11// This is a github action script and can be run only from github actions. To run this script locally, you need to mock the github object and context object.
22module . exports = async ( { github, context, core } ) => {
33 const { labelsToAdd } = process . env
4+ const defaultReviewer = 'copilot'
5+
6+ function withDefaultReviewer ( reviewers ) {
7+ return Array . from ( new Set ( [ ...reviewers , defaultReviewer ] ) )
8+ }
49
510 // Check if there are already reviewers assigned to the PR
611 try {
@@ -25,20 +30,20 @@ module.exports = async ({ github, context, core }) => {
2530
2631 // Check if team:external label is being added
2732 if ( labelsToAdd && labelsToAdd . split ( ',' ) . includes ( 'team:external' ) ) {
28- core . setOutput ( 'reviewers' , 'joe-ayoub-segment' )
33+ core . setOutput ( 'reviewers' , withDefaultReviewer ( [ 'joe-ayoub-segment' ] ) . join ( ',' ) )
2934 core . setOutput ( 'team' , 'external' )
3035 core . setOutput ( 'skip' , 'false' )
31- core . info ( 'Assigned joe-ayoub-segment for external contributor PR' )
36+ core . info ( 'Assigned joe-ayoub-segment and copilot for external contributor PR' )
3237 return
3338 }
3439
3540 // Check if team:external label already exists on the PR
3641 const existingLabels = context . payload . pull_request . labels . map ( ( label ) => label . name )
3742 if ( existingLabels . includes ( 'team:external' ) ) {
38- core . setOutput ( 'reviewers' , 'joe-ayoub-segment' )
43+ core . setOutput ( 'reviewers' , withDefaultReviewer ( [ 'joe-ayoub-segment' ] ) . join ( ',' ) )
3944 core . setOutput ( 'team' , 'external' )
4045 core . setOutput ( 'skip' , 'false' )
41- core . info ( 'Assigned joe-ayoub-segment for external contributor PR (existing label)' )
46+ core . info ( 'Assigned joe-ayoub-segment and copilot for external contributor PR (existing label)' )
4247 return
4348 }
4449
@@ -82,10 +87,10 @@ module.exports = async ({ github, context, core }) => {
8287 const teamToAssign = await getTeamFromGitHub ( )
8388
8489 if ( ! teamToAssign ) {
85- core . setOutput ( 'reviewers' , 'joe-ayoub-segment' )
90+ core . setOutput ( 'reviewers' , withDefaultReviewer ( [ 'joe-ayoub-segment' ] ) . join ( ',' ) )
8691 core . setOutput ( 'team' , 'other' )
8792 core . setOutput ( 'skip' , 'false' )
88- core . info ( 'No team assigned, defaulting to joe-ayoub-segment' )
93+ core . info ( 'No team assigned, defaulting to joe-ayoub-segment and copilot ' )
8994 return
9095 }
9196
@@ -107,10 +112,10 @@ module.exports = async ({ github, context, core }) => {
107112
108113 if ( ! isAuthorInTeam ) {
109114 // PR targeting strategic-connections-team from non-team member -> assign to joe-ayoub-segment
110- core . setOutput ( 'reviewers' , 'joe-ayoub-segment' )
115+ core . setOutput ( 'reviewers' , withDefaultReviewer ( [ 'joe-ayoub-segment' ] ) . join ( ',' ) )
111116 core . setOutput ( 'team' , 'other' )
112117 core . setOutput ( 'skip' , 'false' )
113- core . info ( `PR targeting ${ teamToAssign } from non-team member, assigned to joe-ayoub-segment` )
118+ core . info ( `PR targeting ${ teamToAssign } from non-team member, assigned to joe-ayoub-segment and copilot ` )
114119 return
115120 }
116121 // If author is in team, continue to team assignment logic below
@@ -152,12 +157,13 @@ module.exports = async ({ github, context, core }) => {
152157 }
153158
154159 const reviewerLogins = selectedMembers . map ( member => member . login )
155- core . setOutput ( 'reviewers' , reviewerLogins . join ( ',' ) )
160+ const reviewersWithDefault = withDefaultReviewer ( reviewerLogins )
161+ core . setOutput ( 'reviewers' , reviewersWithDefault . join ( ',' ) )
156162 core . setOutput ( 'team' , teamToAssign )
157163 core . setOutput ( 'skip' , 'false' )
158164
159165 const authorInfo = eligibleMembers . length !== team . data . length ? ` (excluded PR author: ${ prAuthor } )` : ''
160- core . info ( `Selected ${ reviewerLogins . join ( ', ' ) } (consecutive from index ${ startIndex } ) from ${ membersToSelectFrom . length } available members in ${ teamToAssign } ${ authorInfo } ` )
166+ core . info ( `Selected ${ reviewersWithDefault . join ( ', ' ) } (consecutive from index ${ startIndex } ) from ${ membersToSelectFrom . length } available members in ${ teamToAssign } ${ authorInfo } ` )
161167
162168 } catch ( error ) {
163169 core . setOutput ( 'skip' , 'true' )
0 commit comments