Introduce user field

Signed-off-by: fabuloso <dalfovo.alessandro@gmail.com>
This commit is contained in:
fabuloso
2022-05-31 10:30:51 +02:00
parent ce0d8d7eb1
commit 4db51fc5f1
3 changed files with 60 additions and 13 deletions
+6 -4
View File
@@ -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
```
@@ -399,7 +399,7 @@ describe('publish:github', () => {
collaborators: [
{
access: 'pull',
username: 'robot-1',
user: 'robot-1',
},
{
access: 'push',
@@ -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;
}