File tree Expand file tree Collapse file tree 5 files changed +45
-5
lines changed Expand file tree Collapse file tree 5 files changed +45
-5
lines changed Original file line number Diff line number Diff line change @@ -217,6 +217,9 @@ module.exports = {
217
217
get : ( ) => {
218
218
return { data : ( options . deepValidation ) ? options . deepValidation : { } }
219
219
}
220
+ } ,
221
+ search : {
222
+ issuesAndPullRequests : jest . fn ( ) . mockReturnValue ( { data : { items : options . issuesAndPullRequests || [ ] } } )
220
223
}
221
224
} ,
222
225
probotContext : {
Original file line number Diff line number Diff line change @@ -22,6 +22,31 @@ describe('listFiles', () => {
22
22
}
23
23
} )
24
24
25
+ describe ( 'searchIssuesAndPR' , ( ) => {
26
+ test ( 'return correct data if no error' , async ( ) => {
27
+ const issuesAndPR = [
28
+ 'issues 1' ,
29
+ 'PR 2'
30
+ ]
31
+
32
+ const res = await GithubAPI . searchIssuesAndPR ( Helper . mockContext ( { issuesAndPullRequests : issuesAndPR } ) )
33
+ expect ( res ) . toEqual ( issuesAndPR )
34
+ } )
35
+
36
+ test ( 'that error are re-thrown' , async ( ) => {
37
+ const context = Helper . mockContext ( )
38
+ context . octokit . search . issuesAndPullRequests = jest . fn ( ) . mockRejectedValue ( { status : 402 } )
39
+
40
+ try {
41
+ await GithubAPI . searchIssuesAndPR ( context )
42
+ // Fail test if above expression doesn't throw anything.
43
+ expect ( true ) . toBe ( false )
44
+ } catch ( e ) {
45
+ expect ( e . status ) . toBe ( 402 )
46
+ }
47
+ } )
48
+ } )
49
+
25
50
describe ( 'getContent' , ( ) => {
26
51
test ( 'return correct data if no error' , async ( ) => {
27
52
const content = 'This is the content'
Original file line number Diff line number Diff line change @@ -80,13 +80,13 @@ class Merge extends Action {
80
80
let relatedPullRequests = [ ]
81
81
if ( context . eventName === 'status' ) {
82
82
const commitSHA = context . payload . sha
83
- const results = await context . octokit . search . issuesAndPullRequests ( {
83
+ const results = await this . githubAPI . searchIssuesAndPR ( context , {
84
84
q : `repo:${ context . repo ( ) . owner } /${ context . repo ( ) . repo } is:open ${ commitSHA } ` . trim ( ) ,
85
85
sort : 'updated' ,
86
86
order : 'desc' ,
87
87
per_page : 20
88
88
} )
89
- relatedPullRequests = results . data . items . filter ( item => item . pull_request )
89
+ relatedPullRequests = results . filter ( item => item . pull_request )
90
90
} else if ( context . eventName === 'check_suite' ) {
91
91
relatedPullRequests = this . getPayload ( context ) . pull_requests
92
92
} else {
Original file line number Diff line number Diff line change @@ -312,6 +312,20 @@ class GithubAPI {
312
312
return checkCommonError ( err , context , callFn )
313
313
}
314
314
}
315
+
316
+ static async searchIssuesAndPR ( context , callParam ) {
317
+ const callFn = 'search.issuesAndPullRequests'
318
+
319
+ debugLog ( context , callFn )
320
+
321
+ try {
322
+ const res = await context . octokit . search . issuesAndPullRequests ( callParam )
323
+
324
+ return res . data . items
325
+ } catch ( err ) {
326
+ return checkCommonError ( err , context , callFn )
327
+ }
328
+ }
315
329
}
316
330
317
331
module . exports = GithubAPI
Original file line number Diff line number Diff line change @@ -77,15 +77,13 @@ class Stale extends Validator {
77
77
ignoreQuery += 'no:project '
78
78
}
79
79
const labelQuery = labelMatchQuery . concat ( labelIgnoreQuery ) . join ( ' ' )
80
- const results = await context . octokit . search . issuesAndPullRequests ( {
80
+ const items = await this . githubAPI . searchIssuesAndPR ( context , {
81
81
q : `repo:${ context . repo ( ) . owner } /${ context . repo ( ) . repo } is:open updated:<${ timestamp } ${ typeQuery } ${ labelQuery } ${ ignoreQuery } ` . trim ( ) ,
82
82
sort : 'updated' ,
83
83
order : 'desc' ,
84
84
per_page : MAX_ISSUES
85
85
} )
86
86
87
- const items = results . data . items
88
-
89
87
const scheduleResult = {
90
88
issues : items . filter ( item => ! item . pull_request ) ,
91
89
pulls : items . filter ( item => item . pull_request )
You can’t perform that action at this time.
0 commit comments