@@ -21,7 +21,7 @@ module.exports = class Lock {
21
21
const lockComment = this . getConfigValue ( type , 'lockComment' ) ;
22
22
const setLockReason = this . getConfigValue ( type , 'setLockReason' ) ;
23
23
24
- const results = await this . getLockableIssues ( type ) ;
24
+ const results = await this . search ( type ) ;
25
25
for ( const result of results ) {
26
26
const issue = { ...repo , number : result . number } ;
27
27
@@ -58,43 +58,52 @@ module.exports = class Lock {
58
58
}
59
59
}
60
60
61
- search ( type ) {
61
+ async search ( type ) {
62
62
const { owner, repo} = this . context . repo ( ) ;
63
63
const daysUntilLock = this . getConfigValue ( type , 'daysUntilLock' ) ;
64
64
const exemptLabels = this . getConfigValue ( type , 'exemptLabels' ) ;
65
- const skipCreatedBeforeTimestamp = this . getConfigValue ( type , 'skipCreatedBefore' ) ;
65
+ const skipCreatedBefore = this . getConfigValue ( type , 'skipCreatedBefore' ) ;
66
66
67
67
const timestamp = this . getUpdatedTimestamp ( daysUntilLock ) ;
68
68
69
- let query = `repo:${ owner } /${ repo } is:closed updated:<${ timestamp } ` ;
69
+ let query = `repo:${ owner } /${ repo } updated:<${ timestamp } is:closed is:unlocked` ;
70
+
70
71
if ( exemptLabels . length ) {
71
72
const queryPart = exemptLabels
72
73
. map ( label => `-label:"${ label } "` )
73
74
. join ( ' ' ) ;
74
75
query += ` ${ queryPart } ` ;
75
76
}
77
+
78
+ if ( skipCreatedBefore ) {
79
+ query += ` created:>${ skipCreatedBefore } ` ;
80
+ }
81
+
76
82
if ( type === 'issues' ) {
77
83
query += ' is:issue' ;
78
84
} else {
79
85
query += ' is:pr' ;
80
86
}
81
87
82
- if ( skipCreatedBeforeTimestamp ) {
83
- query += ` created:>${ skipCreatedBeforeTimestamp } ` ;
84
- }
85
-
86
88
this . log . info ( { repo : { owner, repo} } , `Searching ${ type } ` ) ;
87
- return this . context . github . search . issues ( {
89
+ const results = ( await this . context . github . search . issues ( {
88
90
q : query ,
89
91
sort : 'updated' ,
90
92
order : 'desc' ,
91
93
per_page : 30
92
- } ) ;
93
- }
94
+ } ) ) . data . items ;
94
95
95
- async getLockableIssues ( type ) {
96
- const results = await this . search ( type ) ;
97
- return results . data . items . filter ( issue => ! issue . locked ) ;
96
+ // `is:unlocked` search qualifier is undocumented, warn on wrong results
97
+ const wrongResults = results . filter (
98
+ issue => issue . state === 'open' || issue . locked
99
+ ) ;
100
+ if ( wrongResults . length ) {
101
+ const issues = wrongResults . map ( issue => issue . number ) ;
102
+ this . log . warn ( { query, issues} , 'Wrong search results' ) ;
103
+ return [ ] ;
104
+ }
105
+
106
+ return results ;
98
107
}
99
108
100
109
getUpdatedTimestamp ( days ) {
0 commit comments