@@ -32,6 +32,9 @@ test.beforeEach(t => {
3232 t . context . stdout = stub ( process . stdout , 'write' ) . callsFake ( val => {
3333 t . context . logs += stripAnsi ( val . toString ( ) ) ;
3434 } ) ;
35+ t . context . sdterr = stub ( process . stderr , 'write' ) . callsFake ( val => {
36+ t . context . error += stripAnsi ( val . toString ( ) ) ;
37+ } ) ;
3538
3639 process . env . TRAVIS = 'true' ;
3740 process . env . CI = 'true' ;
@@ -45,6 +48,7 @@ test.afterEach.always(t => {
4548 // Restore the current working directory
4649 process . chdir ( cwd ) ;
4750 t . context . stdout . restore ( ) ;
51+ t . context . sdterr . restore ( ) ;
4852} ) ;
4953
5054test . after . always ( async ( ) => {
@@ -58,6 +62,7 @@ test.serial('Initial and minor releases', async t => {
5862 const packageName = 'test-release' ;
5963 const owner = 'git' ;
6064 const branch = 'master' ;
65+ const failTitle = 'The automated release is failing 🚨' ;
6166 // Create a remote repo, initialize it, create a local shallow clone and set the cwd to the clone
6267 const { repositoryUrl} = await gitbox . createRepo ( packageName , branch ) ;
6368 process . env . GH_TOKEN = gitbox . gitCredential ;
@@ -70,6 +75,7 @@ test.serial('Initial and minor releases', async t => {
7075 name : packageName ,
7176 version : '0.0.0-dev' ,
7277 repository : { url : repositoryUrl } ,
78+ release : { failTitle} ,
7379 } ) ;
7480
7581 /* Initial release */
@@ -90,6 +96,23 @@ test.serial('Initial and minor releases', async t => {
9096 { body : { tag_name : `v${ version } ` , target_commitish : 'master' , name : `v${ version } ` } } ,
9197 { body : { html_url : `release-url/${ version } ` } }
9298 ) ;
99+ let searchPRsMock = await mockServer . mock (
100+ '/search/issues' ,
101+ { queryStringParameters : { q : `${ escape ( `repo:${ owner } /${ packageName } ` ) } +${ escape ( 'type:pr' ) } ` } } ,
102+ { body : { items : [ ] } , method : 'GET' }
103+ ) ;
104+ let searchIssuesMock = await mockServer . mock (
105+ '/search/issues' ,
106+ {
107+ queryStringParameters : {
108+ q : `${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ packageName } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
109+ 'state:open'
110+ ) } +${ escape ( failTitle ) } `,
111+ } ,
112+ } ,
113+ { body : { items : [ ] } , method : 'GET' }
114+ ) ;
115+
93116 t . log ( 'Commit a feature' ) ;
94117 await execa ( 'git' , [ 'commit' , '-m' , 'feat: new feature' , '--allow-empty' , '--no-gpg-sign' ] ) ;
95118
@@ -100,8 +123,9 @@ test.serial('Initial and minor releases', async t => {
100123 await mockServer . verify ( verifyApmMock ) ;
101124 await mockServer . verify ( getApmVersionMock ) ;
102125 await mockServer . verify ( createReleaseMock ) ;
103- t . regex ( t . context . logs , / R e g i s t e r i n g t e s t - r e l e a s e / ) ;
104- t . regex ( t . context . logs , new RegExp ( `Publishing test-release@v${ version } ` ) ) ;
126+ await mockServer . verify ( searchIssuesMock ) ;
127+ t . regex ( t . context . error , / R e g i s t e r i n g t e s t - r e l e a s e / ) ;
128+ t . regex ( t . context . error , new RegExp ( `Publishing test-release@v${ version } ` ) ) ;
105129 t . regex ( t . context . logs , new RegExp ( `Published release: 1.0.0` ) ) ;
106130 t . is ( ( await readJson ( './package.json' ) ) . version , version ) ;
107131 t . deepEqual ( await gitCommitedFiles ( ) , [ 'CHANGELOG.md' , 'package.json' ] ) ;
@@ -127,6 +151,28 @@ test.serial('Initial and minor releases', async t => {
127151 { body : { tag_name : `v${ version } ` , target_commitish : 'master' , name : `v${ version } ` } } ,
128152 { body : { html_url : `release-url/${ version } ` } }
129153 ) ;
154+ searchPRsMock = await mockServer . mock (
155+ '/search/issues' ,
156+ { queryStringParameters : { q : `${ escape ( `repo:${ owner } /${ packageName } ` ) } +${ escape ( 'type:pr' ) } +${ commit . hash } ` } } ,
157+ { body : { items : [ { number : 1 , pull_request : { } } ] } , method : 'GET' }
158+ ) ;
159+ const addCommentMock = await mockServer . mock (
160+ `/repos/${ owner } /${ packageName } /issues/1/comments` ,
161+ { } ,
162+ { body : { items : [ { number : 1 , pull_request : { } } ] } }
163+ ) ;
164+ searchIssuesMock = await mockServer . mock (
165+ '/search/issues' ,
166+ {
167+ queryStringParameters : {
168+ q : `${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ packageName } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
169+ 'state:open'
170+ ) } +${ escape ( failTitle ) } `,
171+ } ,
172+ } ,
173+ { body : { items : [ ] } , method : 'GET' }
174+ ) ;
175+
130176 t . log ( 'Commit a feature' ) ;
131177 await execa ( 'git' , [ 'commit' , '-m' , 'feat: other feature' , '--allow-empty' , '--no-gpg-sign' ] ) ;
132178
@@ -137,8 +183,12 @@ test.serial('Initial and minor releases', async t => {
137183 await mockServer . verify ( verifyApmMock ) ;
138184 await mockServer . verify ( getApmVersionMock ) ;
139185 await mockServer . verify ( createReleaseMock ) ;
140- t . regex ( t . context . logs , / R e g i s t e r i n g t e s t - r e l e a s e / ) ;
141- t . regex ( t . context . logs , new RegExp ( `Publishing test-release@v${ version } ` ) ) ;
186+ await mockServer . verify ( searchPRsMock ) ;
187+ await mockServer . verify ( addCommentMock ) ;
188+ await mockServer . verify ( searchIssuesMock ) ;
189+
190+ t . regex ( t . context . error , / R e g i s t e r i n g t e s t - r e l e a s e / ) ;
191+ t . regex ( t . context . error , new RegExp ( `Publishing test-release@v${ version } ` ) ) ;
142192 t . regex ( t . context . logs , new RegExp ( `Published release: 1.0.0` ) ) ;
143193 t . is ( ( await readJson ( './package.json' ) ) . version , version ) ;
144194 t . deepEqual ( await gitCommitedFiles ( ) , [ 'CHANGELOG.md' , 'package.json' ] ) ;
@@ -156,6 +206,7 @@ test.serial('Throw error if "ATOM_ACCESS_TOKEN" is not set', async t => {
156206 process . env . ATOM_HOME = tempy . directory ( ) ;
157207 process . env . ATOM_API_URL = mockServer . url ;
158208 process . env . ATOM_RESOURCE_PATH = tempy . directory ( ) ;
209+ process . env . GIT_TERMINAL_PROMPT = 0 ;
159210 delete process . env . ATOM_ACCESS_TOKEN ;
160211 await writeJson ( './package.json' , {
161212 name : packageName ,
@@ -177,6 +228,7 @@ test.serial('Throw error if "apm" is not installed', async t => {
177228 process . env . ATOM_HOME = tempy . directory ( ) ;
178229 process . env . ATOM_API_URL = mockServer . url ;
179230 process . env . ATOM_RESOURCE_PATH = tempy . directory ( ) ;
231+ process . env . GIT_TERMINAL_PROMPT = 0 ;
180232 // Fake PATH with only git available to make sure apm is not in the PATH
181233 const PATH = tempy . directory ( ) ;
182234 await ensureSymlink ( which . sync ( 'git' ) , path . join ( PATH , 'git' ) ) ;
0 commit comments