Skip to content

Commit

Permalink
Migrate from docs.rs' builds API to status API
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Jul 30, 2023
1 parent d3f55d2 commit 23100b7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 42 deletions.
8 changes: 4 additions & 4 deletions app/models/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ export default class Version extends Model {
}
});

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

get hasDocsRsLink() {
let docsBuilds = this.loadDocsBuildsTask.lastSuccessful?.value;
return docsBuilds?.[0]?.build_status === true;
let docsStatus = this.loadDocsStatusTask.lastSuccessful?.value;
return docsStatus?.doc_status === true;
}

get docsRsLink() {
Expand Down
2 changes: 1 addition & 1 deletion app/routes/crate/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class VersionRoute extends Route {

let { crate, version } = model;
if (!crate.documentation || crate.documentation.startsWith('https://docs.rs/')) {
version.loadDocsBuildsTask.perform().catch(error => {
version.loadDocsStatusTask.perform().catch(error => {
// report unexpected errors to Sentry and ignore `ajax()` errors
if (!didCancel(error) && !(error instanceof AjaxError)) {
this.sentry.captureException(error);
Expand Down
4 changes: 2 additions & 2 deletions mirage/route-handlers/docs-rs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function register(server) {
server.get('https://docs.rs/crate/:crate/:version/builds.json', function () {
return [];
server.get('https://docs.rs/crate/:crate/:version/status.json', function () {
return {};
});
}
48 changes: 13 additions & 35 deletions tests/routes/crate/version/docs-link-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module('Route | crate.version | docs link', function (hooks) {
let crate = this.server.create('crate', { name: 'foo' });
this.server.create('version', { crate, num: '1.0.0' });

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

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

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

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

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

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

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

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

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

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

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

this.server.get('https://docs.rs/crate/:crate/:version/builds.json', [null]);

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

test('empty arrays in docs.rs responses are ignored', async function (assert) {
let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
this.server.create('version', { crate, num: '0.6.2' });

this.server.get('https://docs.rs/crate/:crate/:version/builds.json', []);
this.server.get('https://docs.rs/crate/:crate/:version/status.json', {});

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

0 comments on commit 23100b7

Please sign in to comment.