From 23100b74dcef16b5b704811b04e3f3c0156d44de Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Sun, 30 Jul 2023 11:22:14 +0200 Subject: [PATCH] Migrate from docs.rs' builds API to status API --- app/models/version.js | 8 ++-- app/routes/crate/version.js | 2 +- mirage/route-handlers/docs-rs.js | 4 +- tests/routes/crate/version/docs-link-test.js | 48 ++++++-------------- 4 files changed, 20 insertions(+), 42 deletions(-) diff --git a/app/models/version.js b/app/models/version.js index 8d6cc222f38..a93562285d8 100644 --- a/app/models/version.js +++ b/app/models/version.js @@ -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() { diff --git a/app/routes/crate/version.js b/app/routes/crate/version.js index 782f8ce68fe..ef51739ece0 100644 --- a/app/routes/crate/version.js +++ b/app/routes/crate/version.js @@ -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); diff --git a/mirage/route-handlers/docs-rs.js b/mirage/route-handlers/docs-rs.js index 43e1e6465ec..1dce1d72fd3 100644 --- a/mirage/route-handlers/docs-rs.js +++ b/mirage/route-handlers/docs-rs.js @@ -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 {}; }); } diff --git a/tests/routes/crate/version/docs-link-test.js b/tests/routes/crate/version/docs-link-test.js index 4e08481be2c..801d1229b93 100644 --- a/tests/routes/crate/version/docs-link-test.js +++ b/tests/routes/crate/version/docs-link-test.js @@ -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(); @@ -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'); @@ -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'); @@ -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'); @@ -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');