Skip to content

Commit 7c23757

Browse files
committed
Show "via GitHub" on version list if version was published by GitHub Actions
1 parent 5b26dfe commit 7c23757

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

app/components/version-list/row.hbs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@
4545
{{or @version.published_by.name @version.published_by.login}}
4646
</LinkTo>
4747
</span>
48+
{{else if @version.trustpubPublisher}}
49+
<span local-class="publisher trustpub">
50+
via
51+
{{#if @version.trustpubUrl}}
52+
<a href={{@version.trustpubUrl}} target="_blank" rel="nofollow noopener noreferrer">
53+
{{#if (eq @version.trustpub_data.provider "github")}}
54+
{{svg-jar "github"}}
55+
{{/if}}
56+
{{@version.trustpubPublisher}}
57+
</a>
58+
{{else}}
59+
{{#if (eq @version.trustpub_data.provider "github")}}
60+
{{svg-jar "github"}}
61+
{{/if}}
62+
{{@version.trustpubPublisher}}
63+
{{/if}}
64+
</span>
4865
{{/if}}
4966

5067
<time

app/models/version.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,30 @@ export default class Version extends Model {
4343
/** @type {string[] | null} */
4444
@attr bin_names;
4545

46+
/**
47+
* Information about the trusted publisher that published this version, if any.
48+
* @type {Object | null}
49+
*/
50+
@attr trustpub_data;
51+
52+
/**
53+
* The name of the trusted publisher that published this version, if any.
54+
* @type {string | null}
55+
*/
56+
get trustpubPublisher() {
57+
return this.trustpub_data?.provider === 'github' ? 'GitHub' : null;
58+
}
59+
60+
/**
61+
* The URL to the trusted publisher that published this version, if any.
62+
* @type {string | null}
63+
*/
64+
get trustpubUrl() {
65+
return this.trustpub_data?.provider === 'github'
66+
? `https://github.com/${this.trustpub_data.repository}/actions/runs/${this.trustpub_data.run_id}`
67+
: null;
68+
}
69+
4670
@belongsTo('crate', { async: false, inverse: 'versions' }) crate;
4771

4872
@belongsTo('user', { async: false, inverse: null }) published_by;

e2e/acceptance/versions.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@ import { expect, test } from '@/e2e/helper';
22

33
test.describe('Acceptance | crate versions page', { tag: '@acceptance' }, () => {
44
test('show versions sorted by date', async ({ page, msw, percy }) => {
5+
let trustpubData = {
6+
provider: 'github',
7+
repository: 'octo-org/octo-repo',
8+
run_id: '1234567890',
9+
sha: 'abcdef1234567890',
10+
};
11+
512
let crate = msw.db.crate.create({ name: 'nanomsg' });
613
msw.db.version.create({ crate, num: '0.1.0', created_at: '2017-01-01' });
714
msw.db.version.create({ crate, num: '0.2.0', created_at: '2018-01-01' });
815
msw.db.version.create({ crate, num: '0.3.0', created_at: '2019-01-01', rust_version: '1.69' });
9-
msw.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' });
16+
msw.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01', trustpub_data: trustpubData });
1017

1118
await page.goto('/crates/nanomsg/versions');
1219
await expect(page).toHaveURL('/crates/nanomsg/versions');

tests/acceptance/versions-test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ module('Acceptance | crate versions page', function (hooks) {
99
setupApplicationTest(hooks);
1010

1111
test('show versions sorted by date', async function (assert) {
12+
let trustpubData = {
13+
provider: 'github',
14+
repository: 'octo-org/octo-repo',
15+
run_id: '1234567890',
16+
sha: 'abcdef1234567890',
17+
};
18+
1219
let crate = this.db.crate.create({ name: 'nanomsg' });
1320
this.db.version.create({ crate, num: '0.1.0', created_at: '2017-01-01' });
1421
this.db.version.create({ crate, num: '0.2.0', created_at: '2018-01-01' });
1522
this.db.version.create({ crate, num: '0.3.0', created_at: '2019-01-01', rust_version: '1.69' });
16-
this.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' });
23+
this.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01', trustpub_data: trustpubData });
1724

1825
await visit('/crates/nanomsg/versions');
1926
assert.strictEqual(currentURL(), '/crates/nanomsg/versions');

0 commit comments

Comments
 (0)