Skip to content

Commit 1efddcb

Browse files
authored
feat(options): add new options to avoid stale base on comments (#494)
* feat(options): add new options to avoid stale based on comments Helping to close #441, #470, #435? Closes #390 due to no activity BREAKING CHANGES: the options related to remove-stale-when-updated will only check the updates, not the comment. It is only impactint the configurations using the value at false * style(readme): fix table syntax due to rebase * docs(readme): add permissions only for the new options
1 parent f1017f3 commit 1efddcb

File tree

12 files changed

+827
-79
lines changed

12 files changed

+827
-79
lines changed

README.md

Lines changed: 75 additions & 51 deletions
Large diffs are not rendered by default.

__tests__/constants/default-processor-options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
2929
removeStaleWhenUpdated: false,
3030
removeIssueStaleWhenUpdated: undefined,
3131
removePrStaleWhenUpdated: undefined,
32+
removeStaleWhenCommented: false,
33+
removeIssueStaleWhenCommented: undefined,
34+
removePrStaleWhenCommented: undefined,
3235
ascending: false,
3336
deleteBranch: false,
3437
startDate: '',

__tests__/main.spec.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ test('stale issues should not be closed if days is set to -1', async () => {
12201220
});
12211221

12221222
test('stale label should be removed if a comment was added to a stale issue', async () => {
1223-
const opts = {...DefaultProcessorOptions, removeStaleWhenUpdated: true};
1223+
const opts = {...DefaultProcessorOptions, removeStaleWhenCommented: true};
12241224
const TestIssueList: Issue[] = [
12251225
generateIssue(
12261226
opts,
@@ -1259,7 +1259,7 @@ test('when the option "labelsToAddWhenUnstale" is set, the labels should be adde
12591259
expect.assertions(4);
12601260
const opts = {
12611261
...DefaultProcessorOptions,
1262-
removeStaleWhenUpdated: true,
1262+
removeStaleWhenCommented: true,
12631263
labelsToAddWhenUnstale: 'test'
12641264
};
12651265
const TestIssueList: Issue[] = [
@@ -1299,8 +1299,37 @@ test('when the option "labelsToAddWhenUnstale" is set, the labels should be adde
12991299
expect(processor.addedLabelIssues).toHaveLength(1);
13001300
});
13011301

1302-
test('stale label should not be removed if a comment was added by the bot (and the issue should be closed)', async () => {
1302+
test('stale label should be removed if a stale issue was updated', async () => {
13031303
const opts = {...DefaultProcessorOptions, removeStaleWhenUpdated: true};
1304+
const TestIssueList: Issue[] = [
1305+
generateIssue(
1306+
opts,
1307+
1,
1308+
'An issue that should un-stale',
1309+
new Date().toDateString(),
1310+
'2020-01-01T17:00:00Z',
1311+
false,
1312+
['Stale']
1313+
)
1314+
];
1315+
const processor = new IssuesProcessorMock(
1316+
opts,
1317+
async () => 'abot',
1318+
async p => (p === 1 ? TestIssueList : []),
1319+
async () => [],
1320+
async () => '2020-01-02T17:00:00Z'
1321+
);
1322+
1323+
// process our fake issue list
1324+
await processor.processIssues(1);
1325+
1326+
expect(processor.closedIssues).toHaveLength(0);
1327+
expect(processor.staleIssues).toHaveLength(0);
1328+
expect(processor.removedLabelIssues).toHaveLength(1);
1329+
});
1330+
1331+
test('stale label should not be removed if a comment was added by the bot (and the issue should be closed)', async () => {
1332+
const opts = {...DefaultProcessorOptions, removeStaleWhenCommented: true};
13041333
github.context.actor = 'abot';
13051334
const TestIssueList: Issue[] = [
13061335
generateIssue(
@@ -1339,7 +1368,7 @@ test('stale label should not be removed if a comment was added by the bot (and t
13391368
test('stale label containing a space should be removed if a comment was added to a stale issue', async () => {
13401369
const opts: IIssuesProcessorOptions = {
13411370
...DefaultProcessorOptions,
1342-
removeStaleWhenUpdated: true,
1371+
removeStaleWhenCommented: true,
13431372
staleIssueLabel: 'stat: stale'
13441373
};
13451374
const TestIssueList: Issue[] = [
@@ -2278,7 +2307,7 @@ test('processing an issue stale since less than the daysBeforeStale with a stale
22782307
daysBeforeStale: 30,
22792308
daysBeforeClose: 7,
22802309
closeIssueMessage: 'close message',
2281-
removeStaleWhenUpdated: false
2310+
removeStaleWhenCommented: false
22822311
};
22832312
const now: Date = new Date();
22842313
const updatedAt: Date = new Date(now.setDate(now.getDate() - 9));
@@ -2320,7 +2349,7 @@ test('processing an issue stale since less than the daysBeforeStale without a st
23202349
daysBeforeStale: 30,
23212350
daysBeforeClose: 7,
23222351
closeIssueMessage: 'close message',
2323-
removeStaleWhenUpdated: false
2352+
removeStaleWhenCommented: false
23242353
};
23252354
const now: Date = new Date();
23262355
const updatedAt: Date = new Date(now.setDate(now.getDate() - 9));

0 commit comments

Comments
 (0)