Update test for adding collaborators

Signed-off-by: Francesco Saltori <francescosaltori@gmail.com>
This commit is contained in:
Francesco Saltori
2022-05-24 15:34:15 +02:00
parent 25e8598339
commit 456c74403a
2 changed files with 22 additions and 24 deletions
@@ -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 () => {
@@ -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,