@@ -62,40 +62,50 @@ async function main() {
62
62
core . debug ( `User codeowners: ${ ( 0 , util_1 . inspect ) ( userCodeowners ) } ` ) ;
63
63
const githubToken = core . getInput ( "github-token" , { required : true } ) ;
64
64
const octokit = github . getOctokit ( githubToken ) ;
65
- // TEAM-Y OPERATIONS
66
- const allTeamsWithAtLeastWriteAccess = await ( 0 , teams_1 . getAllTeamsWithAtLeastWriteAccess ) ( octokit , github . context . repo . owner , github . context . repo . repo ) ;
67
- core . info ( `Found ${ allTeamsWithAtLeastWriteAccess . length } teams with at least write access.` ) ;
68
- core . debug ( `All teams with at least write access: ${ ( 0 , util_1 . inspect ) ( allTeamsWithAtLeastWriteAccess ) } ` ) ;
69
65
const failedTeams = [ ] ;
70
- teamCodeowners . forEach ( async ( team ) => {
71
- const [ orgName , teamSlug ] = team . replaceAll ( "@" , "" ) . split ( "/" ) ;
72
- core . debug ( `Found org: '${ orgName } ' and team: '${ teamSlug } ' from '${ team } '.` ) ;
73
- if ( allTeamsWithAtLeastWriteAccess . includes ( teamSlug ) ) {
74
- core . notice ( `Team '${ teamSlug } ' already has at least write access; skipping.` ) ;
75
- }
76
- else {
77
- await ( 0 , teams_1 . addTeamToWriteAccess ) ( octokit , orgName , github . context . repo . repo , teamSlug , isDryRun ) . catch ( ( error ) => {
78
- failedTeams . push ( teamSlug ) ;
79
- core . warning ( `Failed to give write access to team '${ teamSlug } ': ${ error } ` ) ;
80
- } ) ;
81
- }
82
- } ) ;
83
- // USER-Y OPERATIONS HERE
84
- const allUsersWithAtLeastWriteAccess = await ( 0 , collaborators_1 . getAllDirectCollaboratorsWithAtLeastWriteAccess ) ( octokit , github . context . repo . owner , github . context . repo . repo ) ;
85
- core . info ( `Found ${ allUsersWithAtLeastWriteAccess . length } users with at least write access.` ) ;
86
- core . debug ( `All users with at least write access: ${ ( 0 , util_1 . inspect ) ( allUsersWithAtLeastWriteAccess ) } ` ) ;
87
66
const failedUsers = [ ] ;
88
- userCodeowners . forEach ( async ( user ) => {
89
- if ( allUsersWithAtLeastWriteAccess . includes ( user ) ) {
90
- core . notice ( `User '${ user } ' already has at least write access; skipping.` ) ;
91
- }
92
- else {
93
- await ( 0 , collaborators_1 . addUserToWriteAccess ) ( octokit , github . context . repo . owner , github . context . repo . repo , user , isDryRun ) . catch ( ( error ) => {
94
- failedUsers . push ( user ) ;
95
- core . warning ( `Failed to give write access to user '${ user } ': ${ error } ` ) ;
96
- } ) ;
97
- }
98
- } ) ;
67
+ // TEAM-Y OPERATIONS
68
+ if ( teamCodeowners . length > 0 ) {
69
+ const allTeamsWithAtLeastWriteAccess = await ( 0 , teams_1 . getAllTeamsWithAtLeastWriteAccess ) ( octokit , github . context . repo . owner , github . context . repo . repo ) ;
70
+ core . info ( `Found ${ allTeamsWithAtLeastWriteAccess . length } teams with at least write access.` ) ;
71
+ core . debug ( `All teams with at least write access: ${ ( 0 , util_1 . inspect ) ( allTeamsWithAtLeastWriteAccess ) } ` ) ;
72
+ teamCodeowners . forEach ( async ( team ) => {
73
+ const [ orgName , teamSlug ] = team . replaceAll ( "@" , "" ) . split ( "/" ) ;
74
+ core . debug ( `Found org: '${ orgName } ' and team: '${ teamSlug } ' from '${ team } '.` ) ;
75
+ if ( allTeamsWithAtLeastWriteAccess . includes ( teamSlug ) ) {
76
+ core . notice ( `Team '${ teamSlug } ' already has at least write access; skipping.` ) ;
77
+ }
78
+ else {
79
+ await ( 0 , teams_1 . addTeamToWriteAccess ) ( octokit , orgName , github . context . repo . repo , teamSlug , isDryRun ) . catch ( ( error ) => {
80
+ failedTeams . push ( teamSlug ) ;
81
+ core . warning ( `Failed to give write access to team '${ teamSlug } ': ${ error } ` ) ;
82
+ } ) ;
83
+ }
84
+ } ) ;
85
+ }
86
+ else {
87
+ core . notice ( "No team codeowners found; skipping team operations." ) ;
88
+ }
89
+ // USER-Y OPERATIONS HERE
90
+ if ( userCodeowners . length > 0 ) {
91
+ const allUsersWithAtLeastWriteAccess = await ( 0 , collaborators_1 . getAllDirectCollaboratorsWithAtLeastWriteAccess ) ( octokit , github . context . repo . owner , github . context . repo . repo ) ;
92
+ core . info ( `Found ${ allUsersWithAtLeastWriteAccess . length } users with at least write access.` ) ;
93
+ core . debug ( `All users with at least write access: ${ ( 0 , util_1 . inspect ) ( allUsersWithAtLeastWriteAccess ) } ` ) ;
94
+ userCodeowners . forEach ( async ( user ) => {
95
+ if ( allUsersWithAtLeastWriteAccess . includes ( user ) ) {
96
+ core . notice ( `User '${ user } ' already has at least write access; skipping.` ) ;
97
+ }
98
+ else {
99
+ await ( 0 , collaborators_1 . addUserToWriteAccess ) ( octokit , github . context . repo . owner , github . context . repo . repo , user , isDryRun ) . catch ( ( error ) => {
100
+ failedUsers . push ( user ) ;
101
+ core . warning ( `Failed to give write access to user '${ user } ': ${ error } ` ) ;
102
+ } ) ;
103
+ }
104
+ } ) ;
105
+ }
106
+ else {
107
+ core . notice ( "No user codeowners found; skipping user operations." ) ;
108
+ }
99
109
if ( failedTeams . length > 0 || failedUsers . length > 0 ) {
100
110
const errorMsg = `Failed to give write access to teams: ${ failedTeams . join ( ", " ) } . ` +
101
111
`Failed to give write access to users: ${ failedUsers . join ( ", " ) } .` ;
0 commit comments