11import { escape } from 'querystring' ;
22import test from 'ava' ;
3+ import { repeat } from 'lodash' ;
34import nock from 'nock' ;
45import { stub } from 'sinon' ;
56import ISSUE_ID from '../lib/definitions/sr-issue-id' ;
@@ -49,9 +50,9 @@ test.serial('Add comment to PRs associated with release commits and issues close
4950 const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
5051 const github = authenticate ( )
5152 . get (
52- `/search/issues?q=${ commits . map ( commit => commit . hash ) . join ( '+' ) } + ${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape (
53- 'type:pr'
54- ) } `
53+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } + ${ commits
54+ . map ( commit => commit . hash )
55+ . join ( '+' ) } `
5556 )
5657 . reply ( 200 , { items : prs } )
5758 . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
@@ -78,6 +79,70 @@ test.serial('Add comment to PRs associated with release commits and issues close
7879 t . true ( github . isDone ( ) ) ;
7980} ) ;
8081
82+ test . serial ( 'Make multiple search queries if necessary' , async t => {
83+ const owner = 'test_user' ;
84+ const repo = 'test_repo' ;
85+ process . env . GITHUB_TOKEN = 'github_token' ;
86+ const failTitle = 'The automated release is failing :rotating_light:' ;
87+ const pluginConfig = { failTitle} ;
88+ const prs = [
89+ { number : 1 , pull_request : { } } ,
90+ { number : 2 , pull_request : { } } ,
91+ { number : 3 , pull_request : { } } ,
92+ { number : 4 , pull_request : { } } ,
93+ { number : 5 , pull_request : { } } ,
94+ { number : 6 , pull_request : { } } ,
95+ ] ;
96+ const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
97+ const commits = [
98+ { hash : repeat ( 'a' , 40 ) , message : 'Commit 1 message' } ,
99+ { hash : repeat ( 'b' , 40 ) , message : 'Commit 2 message' } ,
100+ { hash : repeat ( 'c' , 40 ) , message : 'Commit 3 message' } ,
101+ { hash : repeat ( 'd' , 40 ) , message : 'Commit 4 message' } ,
102+ { hash : repeat ( 'e' , 40 ) , message : 'Commit 5 message' } ,
103+ { hash : repeat ( 'f' , 40 ) , message : 'Commit 6 message' } ,
104+ ] ;
105+ const nextRelease = { version : '1.0.0' } ;
106+ const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
107+ const github = authenticate ( )
108+ . get (
109+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ commits [ 0 ] . hash } +${ commits [ 1 ] . hash } +${
110+ commits [ 2 ] . hash
111+ } +${ commits [ 3 ] . hash } +${ commits [ 4 ] . hash } `
112+ )
113+ . reply ( 200 , { items : [ prs [ 0 ] , prs [ 1 ] , prs [ 2 ] , prs [ 3 ] , prs [ 4 ] ] } )
114+ . get ( `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ commits [ 5 ] . hash } ` )
115+ . reply ( 200 , { items : [ prs [ 5 ] ] } )
116+ . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
117+ . reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
118+ . post ( `/repos/${ owner } /${ repo } /issues/2/comments` , { body : / T h i s P R i s i n c l u d e d / } )
119+ . reply ( 200 , { html_url : 'https://github.com/successcomment-2' } )
120+ . post ( `/repos/${ owner } /${ repo } /issues/3/comments` , { body : / T h i s P R i s i n c l u d e d / } )
121+ . reply ( 200 , { html_url : 'https://github.com/successcomment-3' } )
122+ . post ( `/repos/${ owner } /${ repo } /issues/4/comments` , { body : / T h i s P R i s i n c l u d e d / } )
123+ . reply ( 200 , { html_url : 'https://github.com/successcomment-4' } )
124+ . post ( `/repos/${ owner } /${ repo } /issues/5/comments` , { body : / T h i s P R i s i n c l u d e d / } )
125+ . reply ( 200 , { html_url : 'https://github.com/successcomment-5' } )
126+ . post ( `/repos/${ owner } /${ repo } /issues/6/comments` , { body : / T h i s P R i s i n c l u d e d / } )
127+ . reply ( 200 , { html_url : 'https://github.com/successcomment-6' } )
128+ . get (
129+ `/search/issues?q=${ escape ( `title:${ failTitle } ` ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape (
130+ 'type:issue'
131+ ) } +${ escape ( 'state:open' ) } `
132+ )
133+ . reply ( 200 , { items : [ ] } ) ;
134+
135+ await success ( pluginConfig , { options, commits, nextRelease, releases, logger : t . context . logger } ) ;
136+
137+ t . deepEqual ( t . context . log . args [ 0 ] , [ 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ] ) ;
138+ t . deepEqual ( t . context . log . args [ 1 ] , [ 'Added comment to issue #%d: %s' , 2 , 'https://github.com/successcomment-2' ] ) ;
139+ t . deepEqual ( t . context . log . args [ 2 ] , [ 'Added comment to issue #%d: %s' , 3 , 'https://github.com/successcomment-3' ] ) ;
140+ t . deepEqual ( t . context . log . args [ 3 ] , [ 'Added comment to issue #%d: %s' , 4 , 'https://github.com/successcomment-4' ] ) ;
141+ t . deepEqual ( t . context . log . args [ 4 ] , [ 'Added comment to issue #%d: %s' , 5 , 'https://github.com/successcomment-5' ] ) ;
142+ t . deepEqual ( t . context . log . args [ 5 ] , [ 'Added comment to issue #%d: %s' , 6 , 'https://github.com/successcomment-6' ] ) ;
143+ t . true ( github . isDone ( ) ) ;
144+ } ) ;
145+
81146test . serial ( 'Do not add comment if no PR is associated with release commits' , async t => {
82147 const owner = 'test_user' ;
83148 const repo = 'test_repo' ;
@@ -90,9 +155,9 @@ test.serial('Do not add comment if no PR is associated with release commits', as
90155 const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
91156 const github = authenticate ( )
92157 . get (
93- `/search/issues?q=${ commits . map ( commit => commit . hash ) . join ( '+' ) } + ${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape (
94- 'type:pr'
95- ) } `
158+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } + ${ commits
159+ . map ( commit => commit . hash )
160+ . join ( '+' ) } `
96161 )
97162 . reply ( 200 , { items : [ ] } )
98163 . get (
@@ -124,9 +189,9 @@ test.serial('Add custom comment', async t => {
124189 const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
125190 const github = authenticate ( )
126191 . get (
127- `/search/issues?q=${ commits . map ( commit => commit . hash ) . join ( '+' ) } + ${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape (
128- 'type:pr'
129- ) } `
192+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } + ${ commits
193+ . map ( commit => commit . hash )
194+ . join ( '+' ) } `
130195 )
131196 . reply ( 200 , { items : prs } )
132197 . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , {
@@ -163,9 +228,9 @@ test.serial('Ignore errors when adding comments and closing issues', async t =>
163228 const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
164229 const github = authenticate ( )
165230 . get (
166- `/search/issues?q=${ commits . map ( commit => commit . hash ) . join ( '+' ) } + ${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape (
167- 'type:pr'
168- ) } `
231+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } + ${ commits
232+ . map ( commit => commit . hash )
233+ . join ( '+' ) } `
169234 )
170235 . reply ( 200 , { items : prs } )
171236 . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
@@ -213,9 +278,9 @@ test.serial('Close open issues when a release is successful', async t => {
213278 const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
214279 const github = authenticate ( )
215280 . get (
216- `/search/issues?q=${ commits . map ( commit => commit . hash ) . join ( '+' ) } + ${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape (
217- 'type:pr'
218- ) } `
281+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } + ${ commits
282+ . map ( commit => commit . hash )
283+ . join ( '+' ) } `
219284 )
220285 . reply ( 200 , { items : [ ] } )
221286 . get (
0 commit comments