@@ -27,6 +27,7 @@ async function action() {
2727
2828 let providedLabels = core . getInput ( "labels" , { required : true } ) ;
2929
30+ core . debug ( `gather labels: ${ providedLabels } ` ) ;
3031 if ( labelsAreRegex ) {
3132 // If labels are regex they must be provided as new line delimited
3233 providedLabels = providedLabels . split ( "\n" ) ;
@@ -43,6 +44,18 @@ async function action() {
4344 // Remove any empty labels
4445 providedLabels = providedLabels . filter ( ( r ) => r ) ;
4546
47+ let issue_number = github . context . issue . number ;
48+
49+ if ( github . context . eventName === "merge_group" && ! issue_number ) {
50+ // Parse out of the ref for merge queue
51+ // e.g. refs/heads/gh-readonly-queue/main/pr-17-a3c310584587d4b97c2df0cb46fe050cc46a15d6
52+ const lastPart = github . context . ref . split ( "/" ) . pop ( ) ;
53+ issue_number = lastPart . match ( / p r - ( \d + ) - / ) [ 1 ] ;
54+ core . info (
55+ `merge_group event detected and issue_number parsed as ${ issue_number } ` ,
56+ ) ;
57+ }
58+
4659 const allowedModes = [ "exactly" , "minimum" , "maximum" ] ;
4760 if ( ! allowedModes . includes ( mode ) ) {
4861 await exitWithError (
@@ -52,6 +65,7 @@ async function action() {
5265 `Unknown mode input [${ mode } ]. Must be one of: ${ allowedModes . join (
5366 ", " ,
5467 ) } `,
68+ issue_number ,
5569 ) ;
5670 return ;
5771 }
@@ -65,17 +79,18 @@ async function action() {
6579 `Unknown exit_code input [${ exitType } ]. Must be one of: ${ allowedExitCodes . join (
6680 ", " ,
6781 ) } `,
82+ issue_number ,
6883 ) ;
6984 return ;
7085 }
7186
72- // Fetch the labels using the API
87+ core . debug ( `fetch the labels for ${ issue_number } using the API` ) ;
7388 // We use the API rather than read event.json in case earlier steps
7489 // added a label
7590 const labels = (
7691 await octokit . rest . issues . listLabelsOnIssue ( {
7792 ...github . context . repo ,
78- issue_number : github . context . issue . number ,
93+ issue_number,
7994 } )
8095 ) . data ;
8196
@@ -98,7 +113,7 @@ async function action() {
98113 ) ;
99114 }
100115
101- // Is there an error?
116+ core . debug ( `detect errors...` ) ;
102117 let errorMode ;
103118 if ( mode === "exactly" && intersection . length !== count ) {
104119 errorMode = "exactly" ;
@@ -108,7 +123,7 @@ async function action() {
108123 errorMode = "at most" ;
109124 }
110125
111- // If so, add a comment (if enabled) and fail the run
126+ core . debug ( `if so, add a comment (if enabled) and fail the run...` ) ;
112127 if ( errorMode !== undefined ) {
113128 const comment = core . getInput ( "message" ) ;
114129 const errorMessage = tmpl ( comment , {
@@ -119,15 +134,21 @@ async function action() {
119134 applied : appliedLabels . join ( ", " ) ,
120135 } ) ;
121136
122- await exitWithError ( exitType , octokit , shouldAddComment , errorMessage ) ;
137+ await exitWithError (
138+ exitType ,
139+ octokit ,
140+ shouldAddComment ,
141+ errorMessage ,
142+ issue_number ,
143+ ) ;
123144 return ;
124145 }
125146
126- // Remove the comment if it exists
147+ core . debug ( `remove the comment if it exists...` ) ;
127148 if ( shouldAddComment ) {
128149 const { data : existing } = await octokit . rest . issues . listComments ( {
129150 ...github . context . repo ,
130- issue_number : github . context . issue . number ,
151+ issue_number : issue_number ,
131152 } ) ;
132153
133154 const generatedComment = existing . find ( ( c ) =>
@@ -154,19 +175,25 @@ function tmpl(t, o) {
154175 } ) ;
155176}
156177
157- async function exitWithError ( exitType , octokit , shouldAddComment , message ) {
178+ async function exitWithError (
179+ exitType ,
180+ octokit ,
181+ shouldAddComment ,
182+ message ,
183+ issue_number ,
184+ ) {
158185 if ( shouldAddComment ) {
159186 // Is there an existing comment?
160187 const { data : existing } = await octokit . rest . issues . listComments ( {
161188 ...github . context . repo ,
162- issue_number : github . context . issue . number ,
189+ issue_number : issue_number ,
163190 } ) ;
164191
165192 const generatedComment = existing . find ( ( c ) => c . body . includes ( matchToken ) ) ;
166193
167194 const params = {
168195 ...github . context . repo ,
169- issue_number : github . context . issue . number ,
196+ issue_number : issue_number ,
170197 body : `${ matchToken } ${ message } ` ,
171198 } ;
172199
0 commit comments