Skip to content

Commit

Permalink
Remove former members from each GitHub Team
Browse files Browse the repository at this point in the history
  • Loading branch information
rmacklin committed Apr 1, 2020
1 parent dada76f commit e036a44
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
22 changes: 14 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3641,14 +3641,7 @@ function synchronizeTeamData(client, org, authenticatedUser, teams) {
if (existingTeam) {
core.debug(`Existing team members for team slug ${teamSlug}:`);
core.debug(JSON.stringify(existingMembers));
for (const username of existingMembers) {
if (!desiredMembers.includes(username)) {
core.debug(`Removing ${username} from ${teamSlug}`);
}
else {
core.debug(`Keeping ${username} in ${teamSlug}`);
}
}
yield removeFormerTeamMembers(client, org, teamSlug, existingMembers, desiredMembers);
}
else {
core.debug(`No team was found in ${org} with slug ${teamSlug}. Creating one.`);
Expand All @@ -3658,6 +3651,19 @@ function synchronizeTeamData(client, org, authenticatedUser, teams) {
}
});
}
function removeFormerTeamMembers(client, org, teamSlug, existingMembers, desiredMembers) {
return __awaiter(this, void 0, void 0, function* () {
for (const username of existingMembers) {
if (!desiredMembers.includes(username)) {
core.debug(`Removing ${username} from ${teamSlug}`);
yield client.teams.removeMembershipInOrg({ org, team_slug: teamSlug, username });
}
else {
core.debug(`Keeping ${username} in ${teamSlug}`);
}
}
});
}
function addNewTeamMembers(client, org, teamSlug, existingMembers, desiredMembers) {
return __awaiter(this, void 0, void 0, function* () {
for (const username of desiredMembers) {
Expand Down
25 changes: 18 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ async function synchronizeTeamData(
core.debug(`Existing team members for team slug ${teamSlug}:`)
core.debug(JSON.stringify(existingMembers))

for (const username of existingMembers) {
if (!desiredMembers.includes(username)) {
core.debug(`Removing ${username} from ${teamSlug}`)
} else {
core.debug(`Keeping ${username} in ${teamSlug}`)
}
}
await removeFormerTeamMembers(client, org, teamSlug, existingMembers, desiredMembers)
} else {
core.debug(`No team was found in ${org} with slug ${teamSlug}. Creating one.`)
await createTeamWithNoMembers(client, org, teamName, teamSlug, authenticatedUser)
Expand All @@ -62,6 +56,23 @@ async function synchronizeTeamData(
}
}

async function removeFormerTeamMembers(
client: github.GitHub,
org: string,
teamSlug: string,
existingMembers: string[],
desiredMembers: string[]
): Promise<void> {
for (const username of existingMembers) {
if (!desiredMembers.includes(username)) {
core.debug(`Removing ${username} from ${teamSlug}`)
await client.teams.removeMembershipInOrg({org, team_slug: teamSlug, username})
} else {
core.debug(`Keeping ${username} in ${teamSlug}`)
}
}
}

async function addNewTeamMembers(
client: github.GitHub,
org: string,
Expand Down

0 comments on commit e036a44

Please sign in to comment.