Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/adapters/trustpub-gitlab-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import ApplicationAdapter from './application';

export default class TrustpubGitLabConfigAdapter extends ApplicationAdapter {
pathForType() {
return 'trusted_publishing/gitlab_configs';
}
}
1 change: 1 addition & 0 deletions app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
--yellow500: hsl(44, 100%, 60%);
--yellow700: hsl(44, 67%, 50%);
--yellow800: hsl(44, 67%, 20%);
--yellow900: hsl(44, 30%, 23%);

--header-bg-color: light-dark(hsl(115, 31%, 20%), #141413);

Expand Down
33 changes: 25 additions & 8 deletions app/controllers/crate/settings/new-trusted-publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class NewTrustedPublisherController extends Controller {
}

get publishers() {
return ['GitHub'];
return ['GitHub', 'GitLab'];
}

get repository() {
Expand All @@ -37,6 +37,8 @@ export default class NewTrustedPublisherController extends Controller {
get verificationUrl() {
if (this.publisher === 'GitHub' && this.namespace && this.project && this.workflow) {
return `https://raw.githubusercontent.com/${this.namespace}/${this.project}/HEAD/.github/workflows/${this.workflow}`;
} else if (this.publisher === 'GitLab' && this.namespace && this.project && this.workflow) {
return `https://gitlab.com/${this.namespace}/${this.project}/-/raw/HEAD/${this.workflow}`;
}
}

Expand Down Expand Up @@ -65,13 +67,24 @@ export default class NewTrustedPublisherController extends Controller {
saveConfigTask = task(async () => {
if (!this.validate()) return;

let config = this.store.createRecord('trustpub-github-config', {
crate: this.crate,
repository_owner: this.namespace,
repository_name: this.project,
workflow_filename: this.workflow,
environment: this.environment || null,
});
let config;
if (this.publisher === 'GitHub') {
config = this.store.createRecord('trustpub-github-config', {
crate: this.crate,
repository_owner: this.namespace,
repository_name: this.project,
workflow_filename: this.workflow,
environment: this.environment || null,
});
} else if (this.publisher === 'GitLab') {
config = this.store.createRecord('trustpub-gitlab-config', {
crate: this.crate,
namespace: this.namespace,
project: this.project,
workflow_filepath: this.workflow,
environment: this.environment || null,
});
}

try {
// Save the new config on the backend
Expand Down Expand Up @@ -106,6 +119,10 @@ export default class NewTrustedPublisherController extends Controller {
return !this.namespaceInvalid && !this.projectInvalid && !this.workflowInvalid;
}

@action publisherChanged(event) {
this.publisher = event.target.value;
}

@action resetNamespaceValidation() {
this.namespaceInvalid = false;
}
Expand Down
11 changes: 11 additions & 0 deletions app/models/trustpub-gitlab-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Model, { attr, belongsTo } from '@ember-data/model';

export default class TrustpubGitLabConfig extends Model {
@belongsTo('crate', { async: true, inverse: null }) crate;
@attr namespace;
@attr namespace_id;
@attr project;
@attr workflow_filepath;
@attr environment;
@attr('date') created_at;
}
6 changes: 4 additions & 2 deletions app/routes/crate/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ export default class SettingsIndexRoute extends Route {
let crate = this.modelFor('crate');

let githubConfigs = await this.store.query('trustpub-github-config', { crate: crate.name });
let gitlabConfigs = await this.store.query('trustpub-gitlab-config', { crate: crate.name });

return { crate, githubConfigs };
return { crate, githubConfigs, gitlabConfigs };
}

setupController(controller, { crate, githubConfigs }) {
setupController(controller, { crate, githubConfigs, gitlabConfigs }) {
super.setupController(...arguments);

controller.set('crate', crate);
controller.set('githubConfigs', githubConfigs);
controller.set('gitlabConfigs', gitlabConfigs);
}
}
21 changes: 21 additions & 0 deletions app/routes/crate/settings/new-trusted-publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ export default class NewTrustedPublisherRoute extends Route {
} catch {
// ignore malformed URLs
}
} else if (repository && repository.startsWith('https://gitlab.com/')) {
controller.publisher = 'GitLab';
try {
let url = new URL(repository);
let pathParts = url.pathname.slice(1).split('/');

// Find the repository path end (indicated by /-/ for trees/blobs/etc)
let repoEndIndex = pathParts.indexOf('-');
if (repoEndIndex !== -1) {
pathParts = pathParts.slice(0, repoEndIndex);
}

if (pathParts.length >= 2) {
// For GitLab, support nested groups: https://gitlab.com/a/b/c
// namespace = "a/b", project = "c"
controller.namespace = pathParts.slice(0, -1).join('/');
controller.project = pathParts.at(-1).replace(/.git$/, '');
}
} catch {
// ignore malformed URLs
}
}
}
}
11 changes: 11 additions & 0 deletions app/serializers/trustpub-gitlab-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ApplicationSerializer from './application';

export default class TrustpubGitLabConfigSerializer extends ApplicationSerializer {
modelNameFromPayloadKey() {
return 'trustpub-gitlab-config';
}

payloadKeyFromModelName() {
return 'gitlab_config';
}
}
55 changes: 53 additions & 2 deletions app/templates/crate/settings/index.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import perform from 'ember-concurrency/helpers/perform';
import preventDefault from 'ember-event-helpers/helpers/prevent-default';
import pageTitle from 'ember-page-title/helpers/page-title';
import not from 'ember-truth-helpers/helpers/not';
import or from 'ember-truth-helpers/helpers/or';

import CrateHeader from 'crates-io/components/crate-header';
import Tooltip from 'crates-io/components/tooltip';
Expand Down Expand Up @@ -165,11 +166,61 @@ import UserAvatar from 'crates-io/components/user-avatar';
>Remove</button>
</td>
</tr>
{{else}}
{{/each}}
{{#each @controller.gitlabConfigs as |config|}}
<tr data-test-gitlab-config={{config.id}}>
<td>GitLab</td>
<td class='details'>
<strong>Repository:</strong>
<a
href='https://gitlab.com/{{config.namespace}}/{{config.project}}'
target='_blank'
rel='noopener noreferrer'
>{{config.namespace}}/{{config.project}}</a>
<span class='owner-id'>
· Namespace ID:
{{#if config.namespace_id}}
{{config.namespace_id}}
<Tooltip>
This is the namespace ID for
<strong>{{config.namespace}}</strong>
from the first publish using this configuration. If
<strong>{{config.namespace}}</strong>
was recreated on GitLab, this configuration will need to be recreated as well.
</Tooltip>
{{else}}
(not yet set)
<Tooltip>
The namespace ID will be captured from the first publish using this configuration.
</Tooltip>
{{/if}}
</span><br />
<strong>Workflow:</strong>
<a
href='https://gitlab.com/{{config.namespace}}/{{config.project}}/-/blob/HEAD/{{config.workflow_filepath}}'
target='_blank'
rel='noopener noreferrer'
>{{config.workflow_filepath}}</a><br />
{{#if config.environment}}
<strong>Environment:</strong>
{{config.environment}}
{{/if}}
</td>
<td class='actions'>
<button
type='button'
class='button button--small'
data-test-remove-config-button
{{on 'click' (perform @controller.removeConfigTask config)}}
>Remove</button>
</td>
</tr>
{{/each}}
{{#unless (or @controller.githubConfigs.length @controller.gitlabConfigs.length)}}
<tr data-test-no-config>
<td colspan='3'>No trusted publishers configured for this crate.</td>
</tr>
{{/each}}
{{/unless}}
</tbody>
</table>

Expand Down
24 changes: 24 additions & 0 deletions app/templates/crate/settings/new-trusted-publisher.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@
border-radius: 4px;
}

.gitlab-wip-notice {
display: flex;
margin: var(--space-m) 0;
padding: var(--space-xs);
background-color: light-dark(var(--yellow100), var(--yellow900));
border-color: var(--yellow500);
border-left-style: solid;
border-left-width: 4px;
border-radius: var(--space-3xs);
font-size: 0.85em;

:global(svg) {
flex-shrink: 0;
width: 1em;
height: 1em;
color: var(--yellow500);
}

:global(p) {
margin: 0 0 0 var(--space-xs);
text-wrap: pretty;
}
}

.workflow-verification {
margin-top: var(--space-2xs);
font-size: 0.85em;
Expand Down
Loading
Loading