From 25e8598339245d6b2666df911963a20c37898af2 Mon Sep 17 00:00:00 2001 From: fabuloso Date: Mon, 23 May 2022 15:51:02 +0200 Subject: [PATCH 01/12] Allow adding user as collaborator to publish:github action Signed-off-by: fabuloso --- .../actions/builtin/publish/github.test.ts | 8 ++-- .../actions/builtin/publish/github.ts | 37 +++++++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts index f1a6c9bfe8..2ab3cfb523 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts @@ -399,11 +399,11 @@ describe('publish:github', () => { collaborators: [ { access: 'pull', - username: 'robot-1', + team: 'robot-1' }, { access: 'push', - username: 'robot-2', + team: 'robot-2', }, ], }, @@ -465,11 +465,11 @@ describe('publish:github', () => { collaborators: [ { access: 'pull', - username: 'robot-1', + team: 'robot-1', }, { access: 'push', - username: 'robot-2', + team: 'robot-2', }, ], }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index 1f9125d962..3deb074a1b 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -58,7 +58,8 @@ export function createPublishGithubAction(options: { requiredStatusCheckContexts?: string[]; repoVisibility?: 'private' | 'internal' | 'public'; collaborators?: Array<{ - username: string; + username?: string; + team?: string; access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; }>; token?: string; @@ -158,7 +159,7 @@ export function createPublishGithubAction(options: { type: 'array', items: { type: 'object', - required: ['username', 'access'], + required: ['access'], properties: { access: { type: 'string', @@ -167,8 +168,12 @@ export function createPublishGithubAction(options: { }, username: { type: 'string', - description: 'The username or group', + description: 'The username', }, + team: { + type: 'string', + description: 'The team name' + } }, }, }, @@ -299,22 +304,24 @@ export function createPublishGithubAction(options: { } if (collaborators) { - for (const { - access: permission, - username: team_slug, - } of collaborators) { + for (const collaborator of collaborators) { try { - await client.rest.teams.addOrUpdateRepoPermissionsInOrg({ - org: owner, - team_slug, - owner, - repo, - permission, - }); + if (collaborator.username) { + await client.rest.repos.addCollaborator({ owner, repo, username: collaborator.username, permissions: collaborator.access }); + } + else { + await client.rest.teams.addOrUpdateRepoPermissionsInOrg({ + org: owner, + team_slug: collaborator.team, + owner, + repo, + permission: collaborator.access, + }); + } } catch (e) { assertError(e); ctx.logger.warn( - `Skipping ${permission} access for ${team_slug}, ${e.message}`, + `Skipping ${collaborator.access} access for ${collaborator.team}, ${e.message}`, ); } } From 456c74403a1430b5118a785bf3ec54fa9ae60096 Mon Sep 17 00:00:00 2001 From: Francesco Saltori Date: Tue, 24 May 2022 15:34:15 +0200 Subject: [PATCH 02/12] Update test for adding collaborators Signed-off-by: Francesco Saltori --- .../actions/builtin/publish/github.test.ts | 32 ++++++++----------- .../actions/builtin/publish/github.ts | 14 +++++--- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts index 2ab3cfb523..0fd6373c7e 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts @@ -399,7 +399,7 @@ describe('publish:github', () => { collaborators: [ { access: 'pull', - team: 'robot-1' + username: 'robot-1', }, { access: 'push', @@ -410,30 +410,24 @@ describe('publish:github', () => { }); const commonProperties = { - org: 'owner', owner: 'owner', repo: 'repo', }; - expect( - mockOctokit.rest.teams.addOrUpdateRepoPermissionsInOrg.mock.calls[1], - ).toEqual([ - { - ...commonProperties, - team_slug: 'robot-1', - permission: 'pull', - }, - ]); + expect(mockOctokit.rest.repos.addCollaborator).toHaveBeenCalledWith({ + ...commonProperties, + username: 'robot-1', + permission: 'pull', + }); expect( - mockOctokit.rest.teams.addOrUpdateRepoPermissionsInOrg.mock.calls[2], - ).toEqual([ - { - ...commonProperties, - team_slug: 'robot-2', - permission: 'push', - }, - ]); + mockOctokit.rest.teams.addOrUpdateRepoPermissionsInOrg, + ).toHaveBeenCalledWith({ + ...commonProperties, + org: 'owner', + team_slug: 'robot-2', + permission: 'push', + }); }); it('should ignore failures when adding multiple collaborators', async () => { diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index 3deb074a1b..1e343c0799 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -172,8 +172,8 @@ export function createPublishGithubAction(options: { }, team: { type: 'string', - description: 'The team name' - } + description: 'The team name', + }, }, }, }, @@ -307,9 +307,13 @@ export function createPublishGithubAction(options: { for (const collaborator of collaborators) { try { if (collaborator.username) { - await client.rest.repos.addCollaborator({ owner, repo, username: collaborator.username, permissions: collaborator.access }); - } - else { + await client.rest.repos.addCollaborator({ + owner, + repo, + username: collaborator.username, + permission: collaborator.access, + }); + } else { await client.rest.teams.addOrUpdateRepoPermissionsInOrg({ org: owner, team_slug: collaborator.team, From d075e2e60fb0483e5bf5e0fa2e65258861db4aec Mon Sep 17 00:00:00 2001 From: Francesco Saltori Date: Tue, 24 May 2022 15:34:15 +0200 Subject: [PATCH 03/12] Fix log message Signed-off-by: Francesco Saltori --- .../src/scaffolder/actions/builtin/publish/github.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index 1e343c0799..7b6abdde10 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -313,7 +313,7 @@ export function createPublishGithubAction(options: { username: collaborator.username, permission: collaborator.access, }); - } else { + } else if (collaborator.team) { await client.rest.teams.addOrUpdateRepoPermissionsInOrg({ org: owner, team_slug: collaborator.team, @@ -325,7 +325,7 @@ export function createPublishGithubAction(options: { } catch (e) { assertError(e); ctx.logger.warn( - `Skipping ${collaborator.access} access for ${collaborator.team}, ${e.message}`, + `Skipping ${collaborator.access} access for ${collaborator.username ?? collaborator.team}, ${e.message}`, ); } } From f7587f11d1a52885339aa1a1eb30de929a3e5b51 Mon Sep 17 00:00:00 2001 From: Francesco Saltori Date: Tue, 24 May 2022 15:34:15 +0200 Subject: [PATCH 04/12] Improve descriptions of collaborators properties Signed-off-by: Francesco Saltori --- .../src/scaffolder/actions/builtin/publish/github.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index 7b6abdde10..b1d6ca45b6 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -168,11 +168,13 @@ export function createPublishGithubAction(options: { }, username: { type: 'string', - description: 'The username', + description: + 'The name of the user that will be added as a collaborator', }, team: { type: 'string', - description: 'The team name', + description: + 'The name of the team that will be added as a collaborator', }, }, }, @@ -325,7 +327,9 @@ export function createPublishGithubAction(options: { } catch (e) { assertError(e); ctx.logger.warn( - `Skipping ${collaborator.access} access for ${collaborator.username ?? collaborator.team}, ${e.message}`, + `Skipping ${collaborator.access} access for ${ + collaborator.username ?? collaborator.team + }, ${e.message}`, ); } } From 45546ba3fba8f2a324a2963f73bdb035d8464ff6 Mon Sep 17 00:00:00 2001 From: Francesco Saltori Date: Mon, 30 May 2022 13:29:30 +0200 Subject: [PATCH 05/12] Refine typings Signed-off-by: Francesco Saltori --- plugins/scaffolder-backend/api-report.md | 14 ++-- .../actions/builtin/publish/github.ts | 72 ++++++++++++------- 2 files changed, 56 insertions(+), 30 deletions(-) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index 84293a8538..b7dedebc02 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -282,10 +282,16 @@ export function createPublishGithubAction(options: { requiredStatusCheckContexts?: string[] | undefined; repoVisibility?: 'internal' | 'private' | 'public' | undefined; collaborators?: - | { - username: string; - access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; - }[] + | ( + | { + username: string; + access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; + } + | { + team: string; + access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; + } + )[] | undefined; token?: string | undefined; topics?: string[] | undefined; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index b1d6ca45b6..7abf30b196 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -57,11 +57,16 @@ export function createPublishGithubAction(options: { requireCodeOwnerReviews?: boolean; requiredStatusCheckContexts?: string[]; repoVisibility?: 'private' | 'internal' | 'public'; - collaborators?: Array<{ - username?: string; - team?: string; - access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; - }>; + collaborators?: Array< + | { + username: string; + access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; + } + | { + team: string; + access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; + } + >; token?: string; topics?: string[]; }>({ @@ -155,28 +160,41 @@ export function createPublishGithubAction(options: { }, collaborators: { title: 'Collaborators', - description: 'Provide additional users with permissions', + description: 'Provide additional users or teams with permissions', type: 'array', items: { type: 'object', required: ['access'], - properties: { - access: { - type: 'string', - description: 'The type of access for the user', - enum: ['push', 'pull', 'admin', 'maintain', 'triage'], + oneOf: [ + { + properties: { + access: { + type: 'string', + description: 'The type of access for the user', + enum: ['push', 'pull', 'admin', 'maintain', 'triage'], + }, + username: { + type: 'string', + description: + 'The name of the user that will be added as a collaborator', + }, + }, }, - username: { - type: 'string', - description: - 'The name of the user that will be added as a collaborator', + { + properties: { + access: { + type: 'string', + description: 'The type of access for the team', + enum: ['push', 'pull', 'admin', 'maintain', 'triage'], + }, + team: { + type: 'string', + description: + 'The name of the team that will be added as a collaborator', + }, + }, }, - team: { - type: 'string', - description: - 'The name of the team that will be added as a collaborator', - }, - }, + ], }, }, token: { @@ -308,14 +326,14 @@ export function createPublishGithubAction(options: { if (collaborators) { for (const collaborator of collaborators) { try { - if (collaborator.username) { + if ('username' in collaborator) { await client.rest.repos.addCollaborator({ owner, repo, username: collaborator.username, permission: collaborator.access, }); - } else if (collaborator.team) { + } else if ('team' in collaborator) { await client.rest.teams.addOrUpdateRepoPermissionsInOrg({ org: owner, team_slug: collaborator.team, @@ -326,10 +344,12 @@ export function createPublishGithubAction(options: { } } catch (e) { assertError(e); + const name = + 'username' in collaborator + ? collaborator.username + : collaborator.team; ctx.logger.warn( - `Skipping ${collaborator.access} access for ${ - collaborator.username ?? collaborator.team - }, ${e.message}`, + `Skipping ${collaborator.access} access for ${name}, ${e.message}`, ); } } From 26a739c43b7b60f34f85acbf41da91c5d9587942 Mon Sep 17 00:00:00 2001 From: Francesco Saltori Date: Mon, 30 May 2022 15:43:38 +0200 Subject: [PATCH 06/12] Fix action schema Signed-off-by: Francesco Saltori --- .../src/scaffolder/actions/builtin/publish/github.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index 7abf30b196..89b6a78e72 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -181,6 +181,7 @@ export function createPublishGithubAction(options: { }, }, { + additionalProperties: false, properties: { access: { type: 'string', From ce0d8d7eb191a0aa54e9281571032b5cedb4a545 Mon Sep 17 00:00:00 2001 From: fabuloso Date: Mon, 30 May 2022 16:42:39 +0200 Subject: [PATCH 07/12] Add changeset Signed-off-by: fabuloso --- .changeset/honest-planets-sin.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .changeset/honest-planets-sin.md diff --git a/.changeset/honest-planets-sin.md b/.changeset/honest-planets-sin.md new file mode 100644 index 0000000000..c3c9d16dd7 --- /dev/null +++ b/.changeset/honest-planets-sin.md @@ -0,0 +1,22 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +**BREAKING** Fixed bug in `publish:github` action that didn't permit to add users as collaborators. +This fix required changing the way parameters are passed to the action. +In order to add a team as collaborator, now you must use the `team` field instead of `username`. +In order to add a user as collaborator, you must use the `username` field. + +```yaml +- id: publish + name: Publish + action: publish:github + input: + allowedHosts: ['github.com'] + repoUrl: ... + collaborators: + - access: ... + team: my_team + - access: ... + username: my_username +``` From 4db51fc5f13a084ff38c86840f67f90ec148775b Mon Sep 17 00:00:00 2001 From: fabuloso Date: Tue, 31 May 2022 10:30:51 +0200 Subject: [PATCH 08/12] Introduce user field Signed-off-by: fabuloso --- .changeset/honest-planets-sin.md | 10 +-- .../actions/builtin/publish/github.test.ts | 2 +- .../actions/builtin/publish/github.ts | 61 ++++++++++++++++--- 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/.changeset/honest-planets-sin.md b/.changeset/honest-planets-sin.md index c3c9d16dd7..5035d8cee4 100644 --- a/.changeset/honest-planets-sin.md +++ b/.changeset/honest-planets-sin.md @@ -2,10 +2,12 @@ '@backstage/plugin-scaffolder-backend': minor --- -**BREAKING** Fixed bug in `publish:github` action that didn't permit to add users as collaborators. +Fixed bug in `publish:github` action that didn't permit to add users as collaborators. This fix required changing the way parameters are passed to the action. -In order to add a team as collaborator, now you must use the `team` field instead of `username`. -In order to add a user as collaborator, you must use the `username` field. +In order to add a team as collaborator, now you must use the `team` field instead of `user`. +In order to add a user as collaborator, you must use the `user` field. + +It's still possible to use the field `username` but is deprecated in favor of `team`. ```yaml - id: publish @@ -18,5 +20,5 @@ In order to add a user as collaborator, you must use the `username` field. - access: ... team: my_team - access: ... - username: my_username + user: my_username ``` diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts index 0fd6373c7e..034c3007c4 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts @@ -399,7 +399,7 @@ describe('publish:github', () => { collaborators: [ { access: 'pull', - username: 'robot-1', + user: 'robot-1', }, { access: 'push', diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index 89b6a78e72..6e6beb6e53 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -59,13 +59,17 @@ export function createPublishGithubAction(options: { repoVisibility?: 'private' | 'internal' | 'public'; collaborators?: Array< | { - username: string; + user: string; access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; } | { team: string; access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; } + | { + username: string; + access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; + } >; token?: string; topics?: string[]; @@ -173,13 +177,26 @@ export function createPublishGithubAction(options: { description: 'The type of access for the user', enum: ['push', 'pull', 'admin', 'maintain', 'triage'], }, - username: { + user: { type: 'string', description: 'The name of the user that will be added as a collaborator', }, }, }, + { + properties: { + access: { + type: 'string', + description: 'The type of access for the user', + enum: ['push', 'pull', 'admin', 'maintain', 'triage'], + }, + username: { + type: 'string', + description: 'Not a valid field anymore', + }, + }, + }, { additionalProperties: false, properties: { @@ -327,11 +344,22 @@ export function createPublishGithubAction(options: { if (collaborators) { for (const collaborator of collaborators) { try { - if ('username' in collaborator) { + if ('user' in collaborator) { await client.rest.repos.addCollaborator({ owner, repo, - username: collaborator.username, + username: collaborator.user, + permission: collaborator.access, + }); + } else if ('username' in collaborator) { + ctx.logger.warn( + 'The field `username` is deprecated in favor of `team`', + ); + await client.rest.teams.addOrUpdateRepoPermissionsInOrg({ + org: owner, + team_slug: collaborator.username, + owner, + repo, permission: collaborator.access, }); } else if ('team' in collaborator) { @@ -345,10 +373,7 @@ export function createPublishGithubAction(options: { } } catch (e) { assertError(e); - const name = - 'username' in collaborator - ? collaborator.username - : collaborator.team; + const name = extractCollaboratorName(collaborator); ctx.logger.warn( `Skipping ${collaborator.access} access for ${name}, ${e.message}`, ); @@ -418,3 +443,23 @@ export function createPublishGithubAction(options: { }, }); } + +function extractCollaboratorName( + collaborator: + | { + user: string; + access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; + } + | { + team: string; + access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; + } + | { + username: string; + access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; + }, +) { + if ('username' in collaborator) return collaborator.username; + if ('user' in collaborator) return collaborator.user; + return collaborator.team; +} From 15a3cacaf2960ac0e4a18678257b5f3705d838b0 Mon Sep 17 00:00:00 2001 From: fabuloso Date: Tue, 31 May 2022 11:57:27 +0200 Subject: [PATCH 09/12] Regenerate api-report and mark old field name as deprecated Signed-off-by: fabuloso --- plugins/scaffolder-backend/api-report.md | 6 +++++- .../src/scaffolder/actions/builtin/publish/github.ts | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index b7dedebc02..256575e747 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -284,13 +284,17 @@ export function createPublishGithubAction(options: { collaborators?: | ( | { - username: string; + user: string; access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; } | { team: string; access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; } + | { + username: string; + access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; + } )[] | undefined; token?: string | undefined; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index 6e6beb6e53..9d3b43dc4f 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -67,6 +67,7 @@ export function createPublishGithubAction(options: { access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; } | { + /** @deprecated This field is deprecated in favor of team */ username: string; access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; } @@ -191,6 +192,7 @@ export function createPublishGithubAction(options: { description: 'The type of access for the user', enum: ['push', 'pull', 'admin', 'maintain', 'triage'], }, + /** @deprecated This field is deprecated in favor of team */ username: { type: 'string', description: 'Not a valid field anymore', @@ -455,6 +457,7 @@ function extractCollaboratorName( access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; } | { + /** @deprecated This field is deprecated in favor of team */ username: string; access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; }, From aea8e28d7c27f3ece4be367e0d9a475865b87175 Mon Sep 17 00:00:00 2001 From: Francesco Saltori Date: Tue, 31 May 2022 15:15:57 +0200 Subject: [PATCH 10/12] Minor adjustments Signed-off-by: Francesco Saltori --- .changeset/honest-planets-sin.md | 2 +- .../actions/builtin/publish/github.ts | 17 ++--------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/.changeset/honest-planets-sin.md b/.changeset/honest-planets-sin.md index 5035d8cee4..03a34f7d86 100644 --- a/.changeset/honest-planets-sin.md +++ b/.changeset/honest-planets-sin.md @@ -4,7 +4,7 @@ Fixed bug in `publish:github` action that didn't permit to add users as collaborators. This fix required changing the way parameters are passed to the action. -In order to add a team as collaborator, now you must use the `team` field instead of `user`. +In order to add a team as collaborator, now you must use the `team` field instead of `username`. In order to add a user as collaborator, you must use the `user` field. It's still possible to use the field `username` but is deprecated in favor of `team`. diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index 9d3b43dc4f..4237ff1abf 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -355,7 +355,7 @@ export function createPublishGithubAction(options: { }); } else if ('username' in collaborator) { ctx.logger.warn( - 'The field `username` is deprecated in favor of `team`', + 'The field `username` is deprecated in favor of `team` and will be removed in the future.', ); await client.rest.teams.addOrUpdateRepoPermissionsInOrg({ org: owner, @@ -447,20 +447,7 @@ export function createPublishGithubAction(options: { } function extractCollaboratorName( - collaborator: - | { - user: string; - access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; - } - | { - team: string; - access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; - } - | { - /** @deprecated This field is deprecated in favor of team */ - username: string; - access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; - }, + collaborator: { user: string } | { team: string } | { username: string }, ) { if ('username' in collaborator) return collaborator.username; if ('user' in collaborator) return collaborator.user; From e7bb7f9cfc8fcf901f5e94505f9cf4b168aea138 Mon Sep 17 00:00:00 2001 From: Francesco Saltori Date: Tue, 31 May 2022 15:12:42 +0200 Subject: [PATCH 11/12] Improve publish:github action schema Signed-off-by: Francesco Saltori --- .../actions/builtin/publish/github.ts | 69 +++++++------------ 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index 4237ff1abf..7e5c76c186 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -169,51 +169,34 @@ export function createPublishGithubAction(options: { type: 'array', items: { type: 'object', + additionalProperties: false, required: ['access'], + properties: { + access: { + type: 'string', + description: 'The type of access for the user', + enum: ['push', 'pull', 'admin', 'maintain', 'triage'], + }, + user: { + type: 'string', + description: + 'The name of the user that will be added as a collaborator', + }, + username: { + type: 'string', + description: + 'Deprecated. Use the `team` or `user` field instead.', + }, + team: { + type: 'string', + description: + 'The name of the team that will be added as a collaborator', + }, + }, oneOf: [ - { - properties: { - access: { - type: 'string', - description: 'The type of access for the user', - enum: ['push', 'pull', 'admin', 'maintain', 'triage'], - }, - user: { - type: 'string', - description: - 'The name of the user that will be added as a collaborator', - }, - }, - }, - { - properties: { - access: { - type: 'string', - description: 'The type of access for the user', - enum: ['push', 'pull', 'admin', 'maintain', 'triage'], - }, - /** @deprecated This field is deprecated in favor of team */ - username: { - type: 'string', - description: 'Not a valid field anymore', - }, - }, - }, - { - additionalProperties: false, - properties: { - access: { - type: 'string', - description: 'The type of access for the team', - enum: ['push', 'pull', 'admin', 'maintain', 'triage'], - }, - team: { - type: 'string', - description: - 'The name of the team that will be added as a collaborator', - }, - }, - }, + { required: ['user'] }, + { required: ['username'] }, + { required: ['team'] }, ], }, }, From 3934f8bb24f96cd44cc3b6696636b935e0652cf8 Mon Sep 17 00:00:00 2001 From: Francesco Saltori Date: Tue, 31 May 2022 15:17:07 +0200 Subject: [PATCH 12/12] Make changeset a bit shorter Signed-off-by: Francesco Saltori --- .changeset/honest-planets-sin.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.changeset/honest-planets-sin.md b/.changeset/honest-planets-sin.md index 03a34f7d86..bb55e881c6 100644 --- a/.changeset/honest-planets-sin.md +++ b/.changeset/honest-planets-sin.md @@ -2,7 +2,7 @@ '@backstage/plugin-scaffolder-backend': minor --- -Fixed bug in `publish:github` action that didn't permit to add users as collaborators. +Fixed a bug in `publish:github` action that didn't permit to add users as collaborators. This fix required changing the way parameters are passed to the action. In order to add a team as collaborator, now you must use the `team` field instead of `username`. In order to add a user as collaborator, you must use the `user` field. @@ -14,7 +14,6 @@ It's still possible to use the field `username` but is deprecated in favor of `t name: Publish action: publish:github input: - allowedHosts: ['github.com'] repoUrl: ... collaborators: - access: ...