Skip to content

Commit 2a98c9a

Browse files
Add ability to handle users with periods in names (#92)
This also adds the ability to dry run a team specific sync when calling the endpoints directly.
1 parent f77cd5a commit 2a98c9a

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/handlers/syncSpecificTeamHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export async function syncSpecificTeamHandler(
2929
) {
3030
const orgId = c.request.query.orgId! as unknown as number;
3131
const teamName = c.request.query.teamName! as unknown as string;
32+
const dryRun = c.request.query.dryRun as unknown as boolean ?? true;
3233

3334
const client = GetClient();
3435
const orgClient = await client.GetOrgClient(orgId);
@@ -54,7 +55,7 @@ export async function syncSpecificTeamHandler(
5455

5556
const sourceTeamMap = orgConfig.data.DisplayNameToSourceMap;
5657

57-
const response = await SyncTeam(teamName, orgClient, appConfig, invites, sourceTeamMap);
58+
const response = await SyncTeam(teamName, orgClient, appConfig, invites, sourceTeamMap, dryRun);
5859

5960
return res.status(200).json(response);
6061
}

src/openapi.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ paths:
8585
schema:
8686
type: string
8787
required: true
88+
- in: query
89+
name: dryRun
90+
description: Whether to run the sync, or simply return what actions will be taken. Defaults to True (i.e., perform as Dry Run).
91+
schema:
92+
type: boolean
93+
default: true
94+
required: false
8895
responses:
8996
"200":
9097
description: A successful response

src/services/githubSync.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ async function GetGitHubIds(teamName: string, config: AppConfig): Promise<GitHub
5050
return {
5151
Succeeded: true,
5252
Ids: membersFromSourceOfTruth.entries.map(e => {
53-
return replaceAll(e.cn, '_', '-') + config.GitHubIdAppend;
53+
const replace1 = replaceAll(e.cn, '_', '-');
54+
const replace2 = replace1.replaceAll(".", "-");
55+
return replace2 + config.GitHubIdAppend;
5456
})
5557
}
5658
}
@@ -108,7 +110,7 @@ async function SynchronizeOrgMembers(installedGitHubClient: InstalledClient, tea
108110
};
109111
}
110112

111-
async function SynchronizeGitHubTeam(installedGitHubClient: InstalledClient, teamName: string, config: AppConfig, existingInvites: OrgInvite[], sourceTeamMap: Map<string, string>, checkOrgMembers: boolean = true) {
113+
async function SynchronizeGitHubTeam(installedGitHubClient: InstalledClient, teamName: string, config: AppConfig, existingInvites: OrgInvite[], sourceTeamMap: Map<string, string>, checkOrgMembers: boolean = true, dryRun: boolean = false) {
112114
function GetSourceOrReturn(teamName: string) {
113115
return sourceTeamMap.get(teamName) ?? teamName;
114116
}
@@ -170,6 +172,10 @@ async function SynchronizeGitHubTeam(installedGitHubClient: InstalledClient, tea
170172

171173
Log(JSON.stringify(teamSyncNotes));
172174

175+
if(dryRun === true) {
176+
return teamSyncNotes;
177+
}
178+
173179
const deleteResponses = await Promise.all(teamMembersToRemove.map(mtr => installedGitHubClient.RemoveTeamMemberAsync(teamName, mtr)));
174180
const addResponses = await Promise.all(teamMembersToAdd.map(mta => installedGitHubClient.AddTeamMember(teamName, mta)));
175181

@@ -473,8 +479,8 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
473479
}
474480

475481

476-
export async function SyncTeam(teamName: string, client: InstalledClient, config: AppConfig, invites: OrgInvite[], sourceTeamMap: Map<string, string>) {
477-
const response = await SynchronizeGitHubTeam(client, teamName, config, invites, sourceTeamMap, true);
482+
export async function SyncTeam(teamName: string, client: InstalledClient, config: AppConfig, invites: OrgInvite[], sourceTeamMap: Map<string, string>, dryRun: boolean = false) {
483+
const response = await SynchronizeGitHubTeam(client, teamName, config, invites, sourceTeamMap, true, dryRun);
478484

479485
return response;
480486
}

0 commit comments

Comments
 (0)