@@ -24,13 +24,11 @@ beforeEach(() => {
2424 merge : jest . fn ( )
2525 } ,
2626 issues : {
27- update : jest . fn ( )
27+ update : jest . fn ( ) ,
28+ listForRepo : jest . fn ( )
2829 } ,
2930 git : {
3031 updateRef : jest . fn ( )
31- } ,
32- search : {
33- issuesAndPullRequests : jest . fn ( )
3432 }
3533 }
3634
@@ -95,7 +93,7 @@ describe('pull - routineCheck', () => {
9593 const pull = new Pull ( github , { owner : 'wei' , repo : 'fork' , logger : app . log } , configs [ i ] )
9694 await pull . routineCheck ( )
9795 expect ( github . repos . compareCommits ) . not . toHaveBeenCalled ( )
98- expect ( github . search . issuesAndPullRequests ) . not . toHaveBeenCalled ( )
96+ expect ( github . issues . listForRepo ) . not . toHaveBeenCalled ( )
9997 expect ( github . pulls . create ) . not . toHaveBeenCalled ( )
10098 expect ( github . issues . update ) . not . toHaveBeenCalled ( )
10199 }
@@ -115,14 +113,14 @@ describe('pull - routineCheck', () => {
115113 expect ( github . repos . compareCommits ) . nthCalledWith ( 2 , {
116114 owner : 'wei' , repo : 'fork' , base : 'feature/new-1' , head : 'upstream:dev'
117115 } )
118- expect ( github . search . issuesAndPullRequests ) . not . toHaveBeenCalled ( )
116+ expect ( github . issues . listForRepo ) . not . toHaveBeenCalled ( )
119117 expect ( github . pulls . create ) . not . toHaveBeenCalled ( )
120118 expect ( github . issues . update ) . not . toHaveBeenCalled ( )
121119 } )
122120
123121 test ( 'diff too large' , async ( ) => {
124122 github . repos . compareCommits . mockImplementation ( ( ) => { throw Error ( 'Server Error: Sorry, this diff is taking too long to generate.' ) } )
125- github . search . issuesAndPullRequests . mockResolvedValue ( { data : { total_count : 0 } } )
123+ github . issues . listForRepo . mockResolvedValue ( { data : [ ] } )
126124 github . pulls . create . mockResolvedValue ( { data : {
127125 number : 12 ,
128126 base : { ref : 'master' } ,
@@ -136,7 +134,7 @@ describe('pull - routineCheck', () => {
136134 const pull = getPull ( )
137135 await pull . routineCheck ( )
138136 expect ( github . repos . compareCommits . mock . calls . length ) . toBe ( 3 )
139- expect ( github . search . issuesAndPullRequests ) . toHaveBeenCalled ( )
137+ expect ( github . issues . listForRepo ) . toHaveBeenCalled ( )
140138 expect ( github . pulls . create ) . toHaveBeenCalled ( )
141139 expect ( github . issues . update ) . toHaveBeenCalled ( )
142140 } )
@@ -147,7 +145,7 @@ describe('pull - routineCheck', () => {
147145 const pull = getPull ( )
148146 await pull . routineCheck ( )
149147 expect ( github . repos . compareCommits . mock . calls . length ) . toBe ( 3 )
150- expect ( github . search . issuesAndPullRequests ) . not . toHaveBeenCalled ( )
148+ expect ( github . issues . listForRepo ) . not . toHaveBeenCalled ( )
151149 expect ( github . pulls . create ) . not . toHaveBeenCalled ( )
152150 expect ( github . issues . update ) . not . toHaveBeenCalled ( )
153151 } )
@@ -158,7 +156,7 @@ describe('pull - routineCheck', () => {
158156 const pull = getPull ( )
159157 await pull . routineCheck ( )
160158 expect ( github . repos . compareCommits . mock . calls . length ) . toBe ( 3 )
161- expect ( github . search . issuesAndPullRequests ) . not . toHaveBeenCalled ( )
159+ expect ( github . issues . listForRepo ) . not . toHaveBeenCalled ( )
162160 expect ( github . pulls . create ) . not . toHaveBeenCalled ( )
163161 expect ( github . issues . update ) . not . toHaveBeenCalled ( )
164162 } )
@@ -169,66 +167,78 @@ describe('pull - routineCheck', () => {
169167 const pull = getPull ( )
170168 await pull . routineCheck ( )
171169 expect ( github . repos . compareCommits . mock . calls . length ) . toBe ( 3 )
172- expect ( github . search . issuesAndPullRequests ) . not . toHaveBeenCalled ( )
170+ expect ( github . issues . listForRepo ) . not . toHaveBeenCalled ( )
173171 expect ( github . pulls . create ) . not . toHaveBeenCalled ( )
174172 expect ( github . issues . update ) . not . toHaveBeenCalled ( )
175173 } )
176174
177175 test ( 'yes diff, already has PR' , async ( ) => {
178176 github . repos . compareCommits . mockResolvedValue ( { data : { total_commits : 1 } } )
179- github . search . issuesAndPullRequests . mockResolvedValueOnce ( { data : { total_count : 1 , items : [ { number : 12 } ] } } )
180- . mockResolvedValueOnce ( { data : { total_count : 1 , items : [ { number : 13 } ] } } )
181- . mockResolvedValueOnce ( { data : { total_count : 1 , items : [ { number : 14 } ] } } )
182- github . pulls . get . mockResolvedValueOnce ( { data : {
183- number : 12 ,
184- base : { ref : 'master' } ,
185- head : { ref : 'master' , label : 'upstream:master' , sha : 'sha1-placeholder-12' } ,
186- state : 'open' ,
187- user : { login : 'pull[bot]' } ,
188- mergeable : true ,
189- rebaseable : true ,
190- mergeable_state : 'clean'
191- } } ) . mockResolvedValueOnce ( { data : {
192- number : 13 ,
193- base : { ref : 'feature/new-1' } ,
194- head : { ref : 'dev' , label : 'upstream:dev' , sha : 'sha1-placeholder-13' } ,
195- state : 'open' ,
196- user : { login : 'pull[bot]' } ,
197- mergeable : true ,
198- rebaseable : true ,
199- mergeable_state : 'clean'
200- } } ) . mockResolvedValueOnce ( { data : {
201- number : 14 ,
202- base : { ref : 'hotfix/bug-1' } ,
203- head : { ref : 'dev' , label : 'upstream:dev' , sha : 'sha1-placeholder-14' } ,
204- state : 'open' ,
205- user : { login : 'pull[bot]' } ,
206- mergeable : true ,
207- rebaseable : true ,
208- mergeable_state : 'clean'
209- } } )
177+ github . issues . listForRepo . mockResolvedValue ( { data : [ { number : 13 } , { number : 12 } , { number : 14 } ] } )
178+ github . pulls . get . mockImplementation ( ( { number } ) => {
179+ switch ( number ) {
180+ case 12 :
181+ return { data : {
182+ number : 12 ,
183+ base : { ref : 'master' , label : 'wei:master' } ,
184+ head : { ref : 'master' , label : 'upstream:master' , sha : 'sha1-placeholder-12' } ,
185+ state : 'open' ,
186+ user : { login : 'pull[bot]' } ,
187+ mergeable : true ,
188+ rebaseable : true ,
189+ mergeable_state : 'clean'
190+ } }
191+ case 13 :
192+ return { data : {
193+ number : 13 ,
194+ base : { ref : 'feature/new-1' , label : 'wei:feature/new-1' } ,
195+ head : { ref : 'dev' , label : 'upstream:dev' , sha : 'sha1-placeholder-13' } ,
196+ state : 'open' ,
197+ user : { login : 'pull[bot]' } ,
198+ mergeable : true ,
199+ rebaseable : true ,
200+ mergeable_state : 'clean'
201+ } }
202+ case 14 :
203+ return { data : {
204+ number : 14 ,
205+ base : { ref : 'hotfix/bug-1' , label : 'wei:hotfix/bug-1' } ,
206+ head : { ref : 'dev' , label : 'upstream:dev' , sha : 'sha1-placeholder-14' } ,
207+ state : 'open' ,
208+ user : { login : 'pull[bot]' } ,
209+ mergeable : true ,
210+ rebaseable : true ,
211+ mergeable_state : 'clean'
212+ } }
213+ default :
214+ return { data : null }
215+ }
216+ } )
210217
211218 const pull = getPull ( )
212219 await pull . routineCheck ( )
213220 expect ( github . repos . compareCommits ) . nthCalledWith ( 1 , {
214221 owner : 'wei' , repo : 'fork' , base : 'master' , head : 'upstream:master'
215222 } )
216- expect ( github . search . issuesAndPullRequests ) . toHaveBeenCalled ( )
217- expect ( github . pulls . get ) . toHaveBeenCalledWith ( { owner : 'wei' , repo : 'fork' , number : 12 } )
223+ expect ( github . issues . listForRepo ) . toHaveBeenCalled ( )
224+ expect ( github . pulls . get ) . nthCalledWith ( 1 , { owner : 'wei' , repo : 'fork' , number : 13 } )
225+ expect ( github . pulls . get ) . nthCalledWith ( 2 , { owner : 'wei' , repo : 'fork' , number : 12 } )
218226 expect ( github . pulls . merge ) . not . toHaveBeenCalledWith ( )
219227
220228 expect ( github . repos . compareCommits ) . nthCalledWith ( 2 , {
221229 owner : 'wei' , repo : 'fork' , base : 'feature/new-1' , head : 'upstream:dev'
222230 } )
223- expect ( github . search . issuesAndPullRequests ) . toHaveBeenCalled ( )
224- expect ( github . pulls . get ) . toHaveBeenCalledWith ( { owner : 'wei' , repo : 'fork' , number : 13 } )
231+ expect ( github . issues . listForRepo ) . toHaveBeenCalled ( )
232+ expect ( github . pulls . get ) . nthCalledWith ( 3 , { owner : 'wei' , repo : 'fork' , number : 13 } )
225233 expect ( github . pulls . merge ) . toHaveBeenCalledWith ( { owner : 'wei' , repo : 'fork' , number : 13 , merge_method : 'rebase' } )
226234
227235 expect ( github . repos . compareCommits ) . nthCalledWith ( 3 , {
228236 owner : 'wei' , repo : 'fork' , base : 'hotfix/bug-1' , head : 'upstream:dev'
229237 } )
230- expect ( github . search . issuesAndPullRequests ) . toHaveBeenCalled ( )
231- expect ( github . pulls . get ) . toHaveBeenCalledWith ( { owner : 'wei' , repo : 'fork' , number : 14 } )
238+ expect ( github . issues . listForRepo ) . toHaveBeenCalled ( )
239+ expect ( github . pulls . get ) . nthCalledWith ( 4 , { owner : 'wei' , repo : 'fork' , number : 13 } )
240+ expect ( github . pulls . get ) . nthCalledWith ( 5 , { owner : 'wei' , repo : 'fork' , number : 12 } )
241+ expect ( github . pulls . get ) . nthCalledWith ( 6 , { owner : 'wei' , repo : 'fork' , number : 14 } )
232242 expect ( github . git . updateRef ) . toHaveBeenCalledWith (
233243 { owner : 'wei' , repo : 'fork' , ref : `heads/hotfix/bug-1` , sha : 'sha1-placeholder-14' , force : true }
234244 )
@@ -239,13 +249,13 @@ describe('pull - routineCheck', () => {
239249
240250 test ( 'yes diff, no PR, create PR' , async ( ) => {
241251 github . repos . compareCommits . mockResolvedValue ( { data : { total_commits : 1 } } )
242- github . search . issuesAndPullRequests
243- . mockResolvedValueOnce ( { data : { total_count : 1 , items : [ { number : 10 } ] } } )
244- . mockResolvedValueOnce ( { data : { total_count : 0 } } )
245- . mockResolvedValueOnce ( { data : { total_count : 0 } } )
252+ github . issues . listForRepo
253+ . mockResolvedValueOnce ( { data : [ { number : 10 } ] } )
254+ . mockResolvedValueOnce ( { data : [ ] } )
255+ . mockResolvedValueOnce ( { data : [ ] } )
246256 github . pulls . get . mockResolvedValueOnce ( { data : {
247257 number : 10 ,
248- base : { ref : 'master' } ,
258+ base : { ref : 'master' , label : 'wei:master' } ,
249259 head : { ref : 'master' , label : 'upstream:master' , sha : 'sha1-placeholder' } ,
250260 state : 'open' ,
251261 user : { login : 'pull[bot]' } ,
@@ -268,7 +278,7 @@ describe('pull - routineCheck', () => {
268278 expect ( github . repos . compareCommits ) . nthCalledWith ( 3 , {
269279 owner : 'wei' , repo : 'fork' , base : 'hotfix/bug-1' , head : 'upstream:dev'
270280 } )
271- expect ( github . search . issuesAndPullRequests ) . toHaveBeenCalledTimes ( 3 )
281+ expect ( github . issues . listForRepo ) . toHaveBeenCalledTimes ( 3 )
272282 expect ( github . pulls . create ) . toHaveBeenCalledTimes ( 2 )
273283 expect ( github . pulls . create ) . nthCalledWith ( 1 , {
274284 owner : 'wei' , repo : 'fork' , base : 'feature/new-1' , head : 'upstream:dev' , maintainer_can_modify : false , title : helper . getPRTitle ( 'feature/new-1' , 'upstream:dev' ) , body : helper . getPRBody ( 'wei/fork' )
0 commit comments