Skip to content

Commit dfa9e82

Browse files
author
dessant
committed
fix: use is:unlocked search qualifier
Closes #5.
1 parent 3755a4f commit dfa9e82

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/lock.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = class Lock {
2121
const lockComment = this.getConfigValue(type, 'lockComment');
2222
const setLockReason = this.getConfigValue(type, 'setLockReason');
2323

24-
const results = await this.getLockableIssues(type);
24+
const results = await this.search(type);
2525
for (const result of results) {
2626
const issue = {...repo, number: result.number};
2727

@@ -58,43 +58,52 @@ module.exports = class Lock {
5858
}
5959
}
6060

61-
search(type) {
61+
async search(type) {
6262
const {owner, repo} = this.context.repo();
6363
const daysUntilLock = this.getConfigValue(type, 'daysUntilLock');
6464
const exemptLabels = this.getConfigValue(type, 'exemptLabels');
65-
const skipCreatedBeforeTimestamp = this.getConfigValue(type, 'skipCreatedBefore');
65+
const skipCreatedBefore = this.getConfigValue(type, 'skipCreatedBefore');
6666

6767
const timestamp = this.getUpdatedTimestamp(daysUntilLock);
6868

69-
let query = `repo:${owner}/${repo} is:closed updated:<${timestamp}`;
69+
let query = `repo:${owner}/${repo} updated:<${timestamp} is:closed is:unlocked`;
70+
7071
if (exemptLabels.length) {
7172
const queryPart = exemptLabels
7273
.map(label => `-label:"${label}"`)
7374
.join(' ');
7475
query += ` ${queryPart}`;
7576
}
77+
78+
if (skipCreatedBefore) {
79+
query += ` created:>${skipCreatedBefore}`;
80+
}
81+
7682
if (type === 'issues') {
7783
query += ' is:issue';
7884
} else {
7985
query += ' is:pr';
8086
}
8187

82-
if (skipCreatedBeforeTimestamp) {
83-
query += ` created:>${skipCreatedBeforeTimestamp}`;
84-
}
85-
8688
this.log.info({repo: {owner, repo}}, `Searching ${type}`);
87-
return this.context.github.search.issues({
89+
const results = (await this.context.github.search.issues({
8890
q: query,
8991
sort: 'updated',
9092
order: 'desc',
9193
per_page: 30
92-
});
93-
}
94+
})).data.items;
9495

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;
98107
}
99108

100109
getUpdatedTimestamp(days) {

0 commit comments

Comments
 (0)