Skip to content

Commit 23100b7

Browse files
committed
Migrate from docs.rs' builds API to status API
1 parent d3f55d2 commit 23100b7

File tree

4 files changed

+20
-42
lines changed

4 files changed

+20
-42
lines changed

app/models/version.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ export default class Version extends Model {
133133
}
134134
});
135135

136-
loadDocsBuildsTask = task(async () => {
137-
return await ajax(`https://docs.rs/crate/${this.crateName}/${this.num}/builds.json`);
136+
loadDocsStatusTask = task(async () => {
137+
return await ajax(`https://docs.rs/crate/${this.crateName}/=${this.num}/status.json`);
138138
});
139139

140140
get hasDocsRsLink() {
141-
let docsBuilds = this.loadDocsBuildsTask.lastSuccessful?.value;
142-
return docsBuilds?.[0]?.build_status === true;
141+
let docsStatus = this.loadDocsStatusTask.lastSuccessful?.value;
142+
return docsStatus?.doc_status === true;
143143
}
144144

145145
get docsRsLink() {

app/routes/crate/version.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default class VersionRoute extends Route {
5454

5555
let { crate, version } = model;
5656
if (!crate.documentation || crate.documentation.startsWith('https://docs.rs/')) {
57-
version.loadDocsBuildsTask.perform().catch(error => {
57+
version.loadDocsStatusTask.perform().catch(error => {
5858
// report unexpected errors to Sentry and ignore `ajax()` errors
5959
if (!didCancel(error) && !(error instanceof AjaxError)) {
6060
this.sentry.captureException(error);

mirage/route-handlers/docs-rs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export function register(server) {
2-
server.get('https://docs.rs/crate/:crate/:version/builds.json', function () {
3-
return [];
2+
server.get('https://docs.rs/crate/:crate/:version/status.json', function () {
3+
return {};
44
});
55
}

tests/routes/crate/version/docs-link-test.js

+13-35
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module('Route | crate.version | docs link', function (hooks) {
1818
let crate = this.server.create('crate', { name: 'foo' });
1919
this.server.create('version', { crate, num: '1.0.0' });
2020

21-
this.server.get('https://docs.rs/crate/:crate/:version/builds.json', []);
21+
this.server.get('https://docs.rs/crate/:crate/:version/status.json', 'not found', 404);
2222

2323
await visit('/crates/foo');
2424
assert.dom('[data-test-docs-link] a').doesNotExist();
@@ -28,16 +28,10 @@ module('Route | crate.version | docs link', function (hooks) {
2828
let crate = this.server.create('crate', { name: 'foo' });
2929
this.server.create('version', { crate, num: '1.0.0' });
3030

31-
this.server.get('https://docs.rs/crate/:crate/:version/builds.json', [
32-
{
33-
id: 42,
34-
rustc_version: 'rustc 1.50.0-nightly (1c389ffef 2020-11-24)',
35-
docsrs_version: 'docsrs 0.6.0 (31c864e 2020-11-22)',
36-
build_status: true,
37-
build_time: '2020-12-06T09:04:36.610302Z',
38-
output: null,
39-
},
40-
]);
31+
this.server.get('https://docs.rs/crate/:crate/:version/status.json', {
32+
doc_status: true,
33+
version: '1.0.0',
34+
});
4135

4236
await visit('/crates/foo');
4337
assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/1.0.0');
@@ -47,7 +41,7 @@ module('Route | crate.version | docs link', function (hooks) {
4741
let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
4842
this.server.create('version', { crate, num: '1.0.0' });
4943

50-
this.server.get('https://docs.rs/crate/:crate/:version/builds.json', []);
44+
this.server.get('https://docs.rs/crate/:crate/:version/status.json', 'not found', 404);
5145

5246
await visit('/crates/foo');
5347
assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/0.6.2');
@@ -57,16 +51,10 @@ module('Route | crate.version | docs link', function (hooks) {
5751
let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
5852
this.server.create('version', { crate, num: '1.0.0' });
5953

60-
this.server.get('https://docs.rs/crate/:crate/:version/builds.json', [
61-
{
62-
id: 42,
63-
rustc_version: 'rustc 1.50.0-nightly (1c389ffef 2020-11-24)',
64-
docsrs_version: 'docsrs 0.6.0 (31c864e 2020-11-22)',
65-
build_status: true,
66-
build_time: '2020-12-06T09:04:36.610302Z',
67-
output: null,
68-
},
69-
]);
54+
this.server.get('https://docs.rs/crate/:crate/:version/status.json', {
55+
doc_status: true,
56+
version: '1.0.0',
57+
});
7058

7159
await visit('/crates/foo');
7260
assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/1.0.0');
@@ -76,27 +64,17 @@ module('Route | crate.version | docs link', function (hooks) {
7664
let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
7765
this.server.create('version', { crate, num: '1.0.0' });
7866

79-
this.server.get('https://docs.rs/crate/:crate/:version/builds.json', {}, 500);
67+
this.server.get('https://docs.rs/crate/:crate/:version/status.json', 'error', 500);
8068

8169
await visit('/crates/foo');
8270
assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/0.6.2');
8371
});
8472

85-
test('null builds in docs.rs responses are ignored', async function (assert) {
73+
test('empty docs.rs responses are ignored', async function (assert) {
8674
let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
8775
this.server.create('version', { crate, num: '0.6.2' });
8876

89-
this.server.get('https://docs.rs/crate/:crate/:version/builds.json', [null]);
90-
91-
await visit('/crates/foo');
92-
assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/0.6.2');
93-
});
94-
95-
test('empty arrays in docs.rs responses are ignored', async function (assert) {
96-
let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
97-
this.server.create('version', { crate, num: '0.6.2' });
98-
99-
this.server.get('https://docs.rs/crate/:crate/:version/builds.json', []);
77+
this.server.get('https://docs.rs/crate/:crate/:version/status.json', {});
10078

10179
await visit('/crates/foo');
10280
assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/0.6.2');

0 commit comments

Comments
 (0)