Skip to content

Commit fceff72

Browse files
🐛 fix security manager display name
1 parent fdee8a0 commit fceff72

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
what.json
22
package-lock.json
3+
out.txt
34

45
## https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
56

src/handlers/getInstalledOrgs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ export async function getInstalledOrgsHandler(
1212

1313
const installations = await client.GetInstallations();
1414

15+
console.log(installations);
16+
1517
return res.status(200).json(installations as OrgModel[]);
1618
}

src/services/gitHub.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ async function GetInstallations(client: Octokit): Promise<Org[]> {
136136
}
137137
});
138138
}
139-
catch {
140-
// TODO: log error
139+
catch(e) {
140+
console.log(e);
141141
return [] as Org[]
142142
}
143143
}

src/services/githubSync.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ type SyncSucceeded = {
5454
OrgMembers: string[]
5555
}
5656

57-
async function SynchronizeOrgMembers(installedGitHubClient: InstalledClient, teamName: string, config: AppConfig): Promise<SyncFailed | SyncSucceeded> {
58-
const gitHubIdsResponse = await GetGitHubIds(teamName, config);
57+
async function SynchronizeOrgMembers(installedGitHubClient: InstalledClient, teamName: string, config: AppConfig, sourceTeamMap: Map<string, string>): Promise<SyncFailed | SyncSucceeded> {
58+
const actualTeamName = sourceTeamMap.get(teamName) ?? teamName;
59+
60+
const gitHubIdsResponse = await GetGitHubIds(actualTeamName, config);
5961

6062
if (gitHubIdsResponse.Succeeded == false) {
6163
return {
@@ -183,21 +185,22 @@ async function SyncSecurityManagers(opts: {
183185
shortLink: string
184186
client: InstalledClient
185187
appConfig: AppConfig
186-
currentInvites: OrgInvite[]
188+
currentInvites: OrgInvite[],
189+
displayNameToSourceMap: Map<string,string>
187190
}): Promise<SuccessSync | FailedSecSync> {
188-
const { securityManagerTeams, setOfExistingTeams, shortLink, client: installedGitHubClient, appConfig, currentInvites } = opts;
191+
const { securityManagerTeams, setOfExistingTeams, shortLink, client: installedGitHubClient, appConfig, currentInvites, displayNameToSourceMap } = opts;
189192

190193
const orgName = installedGitHubClient.GetCurrentOrgName();
191194

192-
for (const t of securityManagerTeams) {
195+
for (const t of securityManagerTeams) {
193196
if (!setOfExistingTeams.has(t.toUpperCase())) {
194197
Log(`Creating team '${orgName}/${t}'`)
195198
await installedGitHubClient.CreateTeam(t, teamDescription(shortLink, t));
196199
setOfExistingTeams.add(t);
197200
}
198201

199202
Log(`Syncing Security Managers for ${installedGitHubClient.GetCurrentOrgName()}: ${t}`)
200-
const orgMembers = await SynchronizeOrgMembers(installedGitHubClient, t, appConfig);
203+
const orgMembers = await SynchronizeOrgMembers(installedGitHubClient, t, appConfig, displayNameToSourceMap);
201204

202205
if (orgMembers.Succeeded == false) {
203206
return {
@@ -206,7 +209,8 @@ async function SyncSecurityManagers(opts: {
206209
};
207210
}
208211

209-
await SynchronizeGitHubTeam(installedGitHubClient, t, appConfig, orgMembers.OrgMembers, currentInvites, new Map());
212+
213+
await SynchronizeGitHubTeam(installedGitHubClient, t, appConfig, orgMembers.OrgMembers, currentInvites, displayNameToSourceMap);
210214

211215
Log(`Add Security Manager Team for ${installedGitHubClient.GetCurrentOrgName()}: ${t}`)
212216
const addResult = await installedGitHubClient.AddSecurityManagerTeam(t);
@@ -253,21 +257,22 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
253257

254258
const orgConfigResponse = await installedGitHubClient.GetConfigurationForInstallation();
255259

256-
const orgConfig = orgConfigResponse.successful ? orgConfigResponse.data : undefined;
260+
const orgConfig = orgConfigResponse.successful ? orgConfigResponse.data : undefined;
257261

258262
const securityManagerTeams = [
259263
...appConfig.SecurityManagerTeams,
260264
...orgConfig?.AdditionalSecurityManagerGroups ?? []
261-
];
265+
];
262266

263267
if (securityManagerTeams.length > 0) {
264268
const syncManagersResponse = await SyncSecurityManagers({
265269
appConfig,
266270
client: installedGitHubClient,
267271
currentInvites,
268-
securityManagerTeams,
269-
setOfExistingTeams,
270-
shortLink: appConfig.Description.ShortLink
272+
securityManagerTeams,
273+
setOfExistingTeams,
274+
shortLink: appConfig.Description.ShortLink,
275+
displayNameToSourceMap: orgConfig?.DisplayNameToSourceMap ?? new Map<string,string>()
271276
});
272277

273278
if (!syncManagersResponse.Success) {
@@ -319,7 +324,7 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
319324
async function syncOrgMembersByTeam(teamName: string, sourceTeamMap: Map<string, string>) {
320325
const sourceTeamName = sourceTeamMap.get(teamName) ?? teamName;
321326
Log(`Adding Org Members via ${sourceTeamName} membership in ${installedGitHubClient.GetCurrentOrgName()}`);
322-
await SynchronizeOrgMembers(installedGitHubClient, sourceTeamName, appConfig);
327+
await SynchronizeOrgMembers(installedGitHubClient, sourceTeamName, appConfig, sourceTeamMap);
323328
}
324329

325330
if (orgConfig.AssumeMembershipViaTeams) {
@@ -333,7 +338,7 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
333338
let currentMembers: GitHubId[] = [];
334339
if (membersGroupName != undefined || membersGroupName != null) {
335340
Log(`Syncing Members for ${installedGitHubClient.GetCurrentOrgName()}: ${membersGroupName}`)
336-
const currentMembersResponse = await SynchronizeOrgMembers(installedGitHubClient, membersGroupName, appConfig)
341+
const currentMembersResponse = await SynchronizeOrgMembers(installedGitHubClient, membersGroupName, appConfig, orgConfig.DisplayNameToSourceMap)
337342

338343
if (currentMembersResponse.Succeeded == false) {
339344
Log("Failed to sync members");

0 commit comments

Comments
 (0)