@@ -86,7 +86,7 @@ async function SynchronizeOrgMembers(installedGitHubClient: InstalledClient, tea
8686 } ;
8787}
8888
89- async function SynchronizeGitHubTeam ( installedGitHubClient : InstalledClient , teamName : string , config : AppConfig , existingMembers : GitHubId [ ] , existingInvites : OrgInvite [ ] , sourceTeamMap : Map < string , string > , checkOrgMembers : boolean = true ) {
89+ async function SynchronizeGitHubTeam ( installedGitHubClient : InstalledClient , teamName : string , config : AppConfig , existingInvites : OrgInvite [ ] , sourceTeamMap : Map < string , string > , checkOrgMembers : boolean = true ) {
9090 function GetSourceOrReturn ( teamName : string ) {
9191 return sourceTeamMap . get ( teamName ) ?? teamName ;
9292 }
@@ -110,10 +110,16 @@ async function SynchronizeGitHubTeam(installedGitHubClient: InstalledClient, tea
110110
111111 const orgName = installedGitHubClient . GetCurrentOrgName ( ) ;
112112
113+ const memberCheckFunc = async ( id :GitHubId ) => {
114+ const response = await installedGitHubClient . IsUserMember ( id ) ;
115+
116+ return response . successful && response . data ;
117+ }
118+
113119 const validMemberCheckResults = await Promise . all ( trueMembersList . map ( tm => checkValidOrgMember ( {
114120 gitHubId : tm ,
115121 checkOrgMembers : checkOrgMembers ,
116- existingMembers : existingMembers ,
122+ isExistingMember : memberCheckFunc ,
117123 idsWithInvites : idsWithInvites ,
118124 installedGitHubClient : installedGitHubClient ,
119125 orgName : orgName
@@ -210,7 +216,7 @@ async function SyncSecurityManagers(opts: {
210216 }
211217
212218
213- await SynchronizeGitHubTeam ( installedGitHubClient , t , appConfig , orgMembers . OrgMembers , currentInvites , displayNameToSourceMap ) ;
219+ await SynchronizeGitHubTeam ( installedGitHubClient , t , appConfig , currentInvites , displayNameToSourceMap ) ;
214220
215221 Log ( `Add Security Manager Team for ${ installedGitHubClient . GetCurrentOrgName ( ) } : ${ t } ` )
216222 const addResult = await installedGitHubClient . AddSecurityManagerTeam ( t ) ;
@@ -352,17 +358,7 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
352358
353359 currentMembers = currentMembersResponse . OrgMembers ;
354360
355- await SynchronizeGitHubTeam ( installedGitHubClient , membersGroupName , appConfig , currentMembers , currentInvites , orgConfig . DisplayNameToSourceMap ) ;
356- }
357-
358- if ( currentMembers . length == 0 ) {
359- const getOrgMembersResponse = await installedGitHubClient . GetOrgMembers ( ) ;
360-
361- if ( ! getOrgMembersResponse . successful ) {
362- throw Error ( "Unable to get current org members" ) ;
363- }
364-
365- currentMembers = getOrgMembersResponse . data ;
361+ await SynchronizeGitHubTeam ( installedGitHubClient , membersGroupName , appConfig , currentInvites , orgConfig . DisplayNameToSourceMap ) ;
366362 }
367363
368364 if ( ! gitHubTeams || gitHubTeams . length < 1 ) {
@@ -372,7 +368,7 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
372368
373369 async function syncTeam ( teamName : string , orgConfig : OrgConfig ) {
374370 Log ( `Syncing Team Members for ${ teamName } in ${ installedGitHubClient . GetCurrentOrgName ( ) } ` )
375- await SynchronizeGitHubTeam ( installedGitHubClient , teamName , appConfig , currentMembers , currentInvites , orgConfig . DisplayNameToSourceMap ) ;
371+ await SynchronizeGitHubTeam ( installedGitHubClient , teamName , appConfig , currentInvites , orgConfig . DisplayNameToSourceMap ) ;
376372 }
377373
378374 const teamSyncPromises = gitHubTeams . map ( t => syncTeam ( t , orgConfig ) ) ;
@@ -414,8 +410,8 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
414410}
415411
416412
417- export async function SyncTeam ( teamName : string , client : InstalledClient , config : AppConfig , existingMembers : GitHubId [ ] , invites : OrgInvite [ ] , sourceTeamMap : Map < string , string > ) {
418- const response = await SynchronizeGitHubTeam ( client , teamName , config , existingMembers , invites , sourceTeamMap , true ) ;
413+ export async function SyncTeam ( teamName : string , client : InstalledClient , config : AppConfig , invites : OrgInvite [ ] , sourceTeamMap : Map < string , string > ) {
414+ const response = await SynchronizeGitHubTeam ( client , teamName , config , invites , sourceTeamMap , true ) ;
419415
420416 return response ;
421417}
@@ -517,9 +513,9 @@ async function checkValidOrgMember(opts: {
517513 checkOrgMembers : boolean ,
518514 orgName : string ,
519515 idsWithInvites : Set < string > ,
520- existingMembers : GitHubId [ ]
516+ isExistingMember : ( id : GitHubId ) => Promise < boolean >
521517} ) {
522- const { installedGitHubClient, gitHubId, checkOrgMembers, orgName, idsWithInvites, existingMembers } = opts ;
518+ const { installedGitHubClient, gitHubId, checkOrgMembers, orgName, idsWithInvites, isExistingMember } = opts ;
523519
524520 const isUserReal = await installedGitHubClient . DoesUserExist ( gitHubId ) ;
525521
@@ -538,9 +534,9 @@ async function checkValidOrgMember(opts: {
538534 message : `User '${ gitHubId } has a Pending Invite to ${ orgName } `
539535 } ;
540536 }
541-
542- if ( checkOrgMembers ) {
543- const isMember = existingMembers . filter ( em => em == gitHubId ) ;
537+
538+ if ( checkOrgMembers ) {
539+ const isMember = await isExistingMember ( gitHubId ) ;
544540
545541 if ( ! isMember ) {
546542 return {
0 commit comments