@@ -3,7 +3,7 @@ import sinon from "sinon";
33import test from "ava" ;
44import fetchMock from "fetch-mock" ;
55
6- import { ISSUE_ID } from "../lib/definitions/constants.js" ;
6+ import { ISSUE_ID , RELEASE_FAIL_LABEL } from "../lib/definitions/constants.js" ;
77import { TestOctokit } from "./helpers/test-octokit.js" ;
88
99/* eslint camelcase: ["error", {properties: "never"}] */
@@ -36,6 +36,13 @@ test("Open a new issue with the list of errors", async (t) => {
3636 . getOnce ( "https://api.github.local/repos/test_user/test_repo" , {
3737 full_name : `${ redirectedOwner } /${ redirectedRepo } ` ,
3838 } )
39+ . postOnce ( "https://api.github.local/graphql" , {
40+ data : {
41+ repository : {
42+ issues : { nodes : [ ] } ,
43+ } ,
44+ } ,
45+ } )
3946 . getOnce (
4047 `https://api.github.local/search/issues?q=${ encodeURIComponent (
4148 "in:title" ,
@@ -59,7 +66,7 @@ test("Open a new issue with the list of errors", async (t) => {
5966 data . body ,
6067 / - - - \n \n # # # E r r o r m e s s a g e 1 \n \n E r r o r 1 d e t a i l s \n \n - - - \n \n # # # E r r o r m e s s a g e 2 \n \n E r r o r 2 d e t a i l s \n \n - - - \n \n # # # E r r o r m e s s a g e 3 \n \n E r r o r 3 d e t a i l s \n \n - - - / ,
6168 ) ;
62- t . deepEqual ( data . labels , [ "semantic-release" ] ) ;
69+ t . deepEqual ( data . labels , [ "semantic-release" , RELEASE_FAIL_LABEL ] ) ;
6370 return true ;
6471 } ,
6572 {
@@ -117,6 +124,13 @@ test("Open a new issue with the list of errors and custom title and comment", as
117124 full_name : `${ owner } /${ repo } ` ,
118125 clone_url : `https://api.github.local/${ owner } /${ repo } .git` ,
119126 } )
127+ . postOnce ( "https://api.github.local/graphql" , {
128+ data : {
129+ repository : {
130+ issues : { nodes : [ ] } ,
131+ } ,
132+ } ,
133+ } )
120134 . getOnce (
121135 `https://api.github.local/search/issues?q=${ encodeURIComponent (
122136 "in:title" ,
@@ -132,7 +146,7 @@ test("Open a new issue with the list of errors and custom title and comment", as
132146 body : {
133147 title : failTitle ,
134148 body : `branch master Error message 1 Error message 2 Error message 3\n\n${ ISSUE_ID } ` ,
135- labels : [ "semantic-release" ] ,
149+ labels : [ "semantic-release" , RELEASE_FAIL_LABEL ] ,
136150 } ,
137151 } ,
138152 ) ;
@@ -185,6 +199,13 @@ test("Open a new issue with assignees and the list of errors", async (t) => {
185199 full_name : `${ owner } /${ repo } ` ,
186200 clone_url : `https://api.github.local/${ owner } /${ repo } .git` ,
187201 } )
202+ . postOnce ( "https://api.github.local/graphql" , {
203+ data : {
204+ repository : {
205+ issues : { nodes : [ ] } ,
206+ } ,
207+ } ,
208+ } )
188209 . getOnce (
189210 `https://api.github.local/search/issues?q=${ encodeURIComponent (
190211 "in:title" ,
@@ -203,7 +224,7 @@ test("Open a new issue with assignees and the list of errors", async (t) => {
203224 data . body ,
204225 / - - - \n \n # # # E r r o r m e s s a g e 1 \n \n E r r o r 1 d e t a i l s \n \n - - - \n \n # # # E r r o r m e s s a g e 2 \n \n E r r o r 2 d e t a i l s \n \n - - - / ,
205226 ) ;
206- t . deepEqual ( data . labels , [ "semantic-release" ] ) ;
227+ t . deepEqual ( data . labels , [ "semantic-release" , RELEASE_FAIL_LABEL ] ) ;
207228 t . deepEqual ( data . assignees , [ "user1" , "user2" ] ) ;
208229 return true ;
209230 } ,
@@ -258,6 +279,13 @@ test("Open a new issue without labels and the list of errors", async (t) => {
258279 full_name : `${ owner } /${ repo } ` ,
259280 clone_url : `https://api.github.local/${ owner } /${ repo } .git` ,
260281 } )
282+ . postOnce ( "https://api.github.local/graphql" , {
283+ data : {
284+ repository : {
285+ issues : { nodes : [ ] } ,
286+ } ,
287+ } ,
288+ } )
261289 . getOnce (
262290 `https://api.github.local/search/issues?q=${ encodeURIComponent (
263291 "in:title" ,
@@ -276,7 +304,7 @@ test("Open a new issue without labels and the list of errors", async (t) => {
276304 data . body ,
277305 / - - - \n \n # # # E r r o r m e s s a g e 1 \n \n E r r o r 1 d e t a i l s \n \n - - - \n \n # # # E r r o r m e s s a g e 2 \n \n E r r o r 2 d e t a i l s \n \n - - - / ,
278306 ) ;
279- t . deepEqual ( data . labels , [ ] ) ;
307+ t . deepEqual ( data . labels , [ RELEASE_FAIL_LABEL ] ) ;
280308 return true ;
281309 } ,
282310 { html_url : "https://github.com/issues/1" , number : 1 } ,
@@ -335,14 +363,13 @@ test("Update the first existing issue with the list of errors", async (t) => {
335363 full_name : `${ owner } /${ repo } ` ,
336364 clone_url : `https://api.github.local/${ owner } /${ repo } .git` ,
337365 } )
338- . getOnce (
339- `https://api.github.local/search/issues?q=${ encodeURIComponent (
340- "in:title" ,
341- ) } +${ encodeURIComponent ( `repo:${ owner } /${ repo } ` ) } +${ encodeURIComponent (
342- "type:issue" ,
343- ) } +${ encodeURIComponent ( "state:open" ) } +${ encodeURIComponent ( failTitle ) } `,
344- { items : issues } ,
345- )
366+ . postOnce ( "https://api.github.local/graphql" , {
367+ data : {
368+ repository : {
369+ issues : { nodes : issues } ,
370+ } ,
371+ } ,
372+ } )
346373 . postOnce (
347374 ( url , { body } ) => {
348375 t . is (
@@ -501,13 +528,17 @@ test('Does not post comments on existing issues when "failCommentCondition" is "
501528 . getOnce ( `https://api.github.local/repos/${ owner } /${ repo } ` , {
502529 full_name : `${ owner } /${ repo } ` ,
503530 } )
504- . getOnce (
505- `https://api.github.local/search/issues?q=${ encodeURIComponent (
506- "in:title" ,
507- ) } +${ encodeURIComponent ( `repo:${ owner } /${ repo } ` ) } +${ encodeURIComponent (
508- "type:issue" ,
509- ) } +${ encodeURIComponent ( "state:open" ) } +${ encodeURIComponent ( failTitle ) } `,
510- { items : issues } ,
531+ . postOnce (
532+ ( url , { body } ) =>
533+ url === "https://api.github.local/graphql" &&
534+ JSON . parse ( body ) . query . includes ( "query getSRIssues(" ) ,
535+ {
536+ data : {
537+ repository : {
538+ issues : { nodes : issues } ,
539+ } ,
540+ } ,
541+ } ,
511542 ) ;
512543
513544 await fail (
@@ -551,6 +582,18 @@ test(`Post new issue if none exists yet, but don't comment on existing issues wh
551582 . getOnce ( `https://api.github.local/repos/${ owner } /${ repo } ` , {
552583 full_name : `${ owner } /${ repo } ` ,
553584 } )
585+ . postOnce (
586+ ( url , { body } ) =>
587+ url === "https://api.github.local/graphql" &&
588+ JSON . parse ( body ) . query . includes ( "query getSRIssues(" ) ,
589+ {
590+ data : {
591+ repository : {
592+ issues : { nodes : [ ] } ,
593+ } ,
594+ } ,
595+ } ,
596+ )
554597 . getOnce (
555598 `https://api.github.local/search/issues?q=${ encodeURIComponent (
556599 "in:title" ,
0 commit comments