@@ -69,7 +69,7 @@ type SyncMembersResponse = Promise<SyncMembersFailed | SyncMembersSucceeded>
6969
7070async function SynchronizeOrgMembers ( installedGitHubClient : InstalledClient , teamName : string , config : AppConfig , sourceTeamMap : Map < string , string > ) : SyncMembersResponse {
7171 const actualTeamName = sourceTeamMap . get ( teamName ) ?? teamName ;
72-
72+
7373 const gitHubIdsResponse = await GetGitHubIds ( actualTeamName , config ) ;
7474
7575 if ( gitHubIdsResponse . Succeeded == false ) {
@@ -90,9 +90,10 @@ async function SynchronizeOrgMembers(installedGitHubClient: InstalledClient, tea
9090
9191 const orgName = installedGitHubClient . GetCurrentOrgName ( ) ;
9292
93+ Log ( "Adding Org Members to " + orgName + " via " + actualTeamName + ": Started" ) ;
9394 const orgMemberPromises = gitHubIds . map ( g => addOrgMember ( g , installedGitHubClient ) ) ;
94-
9595 const responses = await Promise . all ( orgMemberPromises ) ;
96+ Log ( "Adding Org Members to " + orgName + " via " + actualTeamName + ": Completed" ) ;
9697
9798 const orgMembers = responses . filter ( r => r . successful ) . map ( r => r . user ) ;
9899 const problematicGitHubIds = responses . filter ( r => ! r . successful ) ;
@@ -252,7 +253,7 @@ async function SyncSecurityManagers(opts: {
252253 }
253254}
254255
255- async function syncOrg ( installedGitHubClient : InstalledClient , appConfig : AppConfig , invitationsClient : IGitHubInvitations ) : Promise < ReturnTypeOfSyncOrg > {
256+ async function syncOrg ( installedGitHubClient : InstalledClient , appConfig : AppConfig , invitationsClient : IGitHubInvitations , log : ( message : string , operation : string , status : string ) => void ) : Promise < ReturnTypeOfSyncOrg > {
256257 const orgName = installedGitHubClient . GetCurrentOrgName ( ) ;
257258
258259 let response : ReturnTypeOfSyncOrg = {
@@ -282,6 +283,7 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
282283 }
283284 const setOfExistingTeams = new Set ( existingTeamsResponse . data . map ( t => t . Name . toUpperCase ( ) ) ) ;
284285
286+ log ( "" , "GetConfiguration" , "Started" ) ;
285287 const orgConfigResponse = await installedGitHubClient . GetConfigurationForInstallation ( ) ;
286288
287289 const securityManagersFromOrgConfig = orgConfigResponse . successful ? orgConfigResponse . data . AdditionalSecurityManagerGroups : [ ] ;
@@ -291,8 +293,10 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
291293 ...appConfig . SecurityManagerTeams ,
292294 ...securityManagersFromOrgConfig
293295 ] ;
294-
296+ log ( "" , "GetConfiguration" , "Completed" ) ;
297+
295298 if ( securityManagerTeams . length > 0 ) {
299+ log ( "" , "SyncSecurityManagers" , "Started" ) ;
296300 const syncManagersResponse = await SyncSecurityManagers ( {
297301 appConfig,
298302 client : installedGitHubClient ,
@@ -315,7 +319,8 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
315319 ...response ,
316320 syncedSecurityManagerTeams : syncManagersResponse . SyncedSecurityManagerTeams
317321 }
318- }
322+ log ( "" , "SyncSecurityManagers" , "Completed" ) ;
323+ }
319324
320325 if ( ! orgConfigResponse . successful && orgConfigResponse . state == "NoConfig" ) {
321326 return {
@@ -359,10 +364,12 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
359364 const teamsToCreate = teamsThatShouldExist . filter ( t => ! setOfExistingTeams . has ( t . toUpperCase ( ) ) )
360365
361366 if ( teamsToCreate . length > 0 ) {
367+ log ( "" , "CreateTeams" , "Started" ) ;
362368 for ( const t of teamsToCreate ) {
363369 Log ( `Creating team '${ orgName } /${ t } '` )
364370 await installedGitHubClient . CreateTeam ( t , teamDescription ( appConfig . Description . ShortLink , t ) ) ;
365371 }
372+ log ( "" , "CreateTeams" , "Completed" ) ;
366373 }
367374
368375 async function syncOrgMembersByTeam ( teamName : string , sourceTeamMap : Map < string , string > ) {
@@ -375,14 +382,17 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
375382 // TODO: this method is getting very busy, and most likely could benefit from a larger refactor.
376383 // Benefits most likely include performance gains.
377384 Log ( `Syncing Members for ${ installedGitHubClient . GetCurrentOrgName ( ) } by individual teams.` ) ;
385+ log ( "" , "MembershipSync_ByTeam" , "Started" ) ;
378386 const orgMembershipPromises = gitHubTeams . map ( t => syncOrgMembersByTeam ( t , orgConfig . DisplayNameToSourceMap ) ) ;
379387 await Promise . all ( orgMembershipPromises ) ;
388+ log ( "" , "MembershipSync_ByTeam" , "Completed" ) ;
380389 }
381390
382391 let currentMembers : GitHubId [ ] = [ ] ;
383392 // TODO: add log message to explain group being skipped if it is included in TeamsToIgnore
384393 if ( membersGroupName != undefined && membersGroupName != null && ! appConfig . TeamsToIgnore . includes ( membersGroupName ) ) {
385394 Log ( `Syncing Members for ${ installedGitHubClient . GetCurrentOrgName ( ) } : ${ membersGroupName } ` )
395+ log ( "" , "MembershipSync_ByOrgMembersGroup" , "Started" ) ;
386396 const currentMembersResponse = await SynchronizeOrgMembers ( installedGitHubClient , membersGroupName , appConfig , orgConfig . DisplayNameToSourceMap )
387397
388398 if ( currentMembersResponse . Succeeded == false ) {
@@ -405,6 +415,7 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
405415 currentMembers = currentMembersResponse . OrgMembers ;
406416
407417 await SynchronizeGitHubTeam ( installedGitHubClient , membersGroupName , appConfig , currentInvites , orgConfig . DisplayNameToSourceMap ) ;
418+ log ( "" , "MembershipSync_ByOrgMembersGroup" , "Completed" ) ;
408419 }
409420
410421 if ( ! gitHubTeams || gitHubTeams . length < 1 ) {
@@ -419,9 +430,12 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
419430
420431 const teamSyncPromises = gitHubTeams . map ( t => syncTeam ( t , orgConfig ) ) ;
421432
433+ log ( "" , "TeamSync" , "Started" ) ;
422434 await Promise . all ( teamSyncPromises ) ;
435+ log ( "" , "TeamSync" , "Completed" ) ;
423436
424437 if ( ownerGroupName ) {
438+ log ( "" , "OrgOwnerSync" , "Started" ) ;
425439 const teamMembers = await installedGitHubClient . ListCurrentMembersOfGitHubTeam ( ownerGroupName ) ;
426440
427441 if ( ! teamMembers . successful ) {
@@ -444,9 +458,12 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
444458 orgOwnersGroup : ownerGroupName
445459 }
446460 }
461+ log ( "" , "OrgOwnerSync" , "Completed" ) ;
447462 }
448463
464+ log ( "" , "AddCopilotSubscriptions" , "Started" ) ;
449465 const copilotResult = await installedGitHubClient . AddTeamsToCopilotSubscription ( orgConfig . CopilotTeams ) ;
466+ log ( "" , "AddCopilotSubscriptions" , "Completed" ) ;
450467
451468 return {
452469 ...response ,
@@ -479,7 +496,19 @@ export async function SyncOrg(installedGitHubClient: InstalledClient, config: Ap
479496 ) ) ;
480497
481498 try {
482- const response = await syncOrg ( installedGitHubClient , config , invitationsClient ) ;
499+ const log = ( message : string , operation :string , status :string ) => {
500+ Log ( JSON . stringify (
501+ {
502+ data : message ,
503+ orgName : orgName ,
504+ operation : operation ,
505+ status : status ,
506+ trace_id : traceKey
507+ }
508+ ) ) ;
509+ } ;
510+
511+ const response = await syncOrg ( installedGitHubClient , config , invitationsClient , log ) ;
483512
484513 Log ( JSON . stringify (
485514 {
0 commit comments