Skip to content

Commit 453d658

Browse files
committed
feat: add support for end date
Add support for the end-date option. This option is similar to the start-date option except is allows skipping items which were created after the end date. In the Node.js project we want to mark PRs which are older than 1 year old and have not been updated in 6 months as stale and then close them. The end-date option is needed to be able to only operate on PRs which are older than one year. Signed-off-by: Michael Dawson <[email protected]>
1 parent 03af7c3 commit 453d658

File tree

9 files changed

+3485
-87
lines changed

9 files changed

+3485
-87
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,14 @@ If set, the date must be formatted following the `ISO 8601` or `RFC 2822` standa
406406

407407
Default value: unset
408408

409+
#### end-date
410+
411+
The end date is used to ignore the issues and pull requests after the end date.
412+
413+
If set, the date must be formatted following the `ISO 8601` or `RFC 2822` standard.
414+
415+
Default value: unset
416+
409417
#### delete-branch
410418

411419
If set to `true`, the stale workflow will automatically delete the GitHub branches related to the pull requests automatically closed by the stale workflow.

__tests__/constants/default-processor-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
3434
ascending: false,
3535
deleteBranch: false,
3636
startDate: '',
37+
endDate: '',
3738
exemptMilestones: '',
3839
exemptIssueMilestones: '',
3940
exemptPrMilestones: '',

__tests__/main.spec.ts

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,130 @@ test('processing an issue with no label and a start date as RFC 2822 being after
276276
expect(processor.closedIssues.length).toStrictEqual(0);
277277
});
278278

279+
test('processing an issue with no label and an end date as ISO 8601 being before the issue creation date will not make it stale nor close it when it is old enough and days-before-close is set to 0', async () => {
280+
expect.assertions(2);
281+
const january2000 = '2000-01-01T00:00:00Z';
282+
const opts: IIssuesProcessorOptions = {
283+
...DefaultProcessorOptions,
284+
daysBeforeClose: 0,
285+
endDate: january2000.toString()
286+
};
287+
const TestIssueList: Issue[] = [
288+
generateIssue(
289+
opts,
290+
1,
291+
'An issue with no label',
292+
'2020-01-01T17:00:00Z',
293+
'2000-01-01T17:00:00Z'
294+
)
295+
];
296+
const processor = new IssuesProcessorMock(
297+
opts,
298+
async p => (p === 1 ? TestIssueList : []),
299+
async () => [],
300+
async () => new Date().toDateString()
301+
);
302+
303+
// process our fake issue list
304+
await processor.processIssues(1);
305+
306+
expect(processor.staleIssues.length).toStrictEqual(0);
307+
expect(processor.closedIssues.length).toStrictEqual(0);
308+
});
309+
310+
test('processing an issue with no label and an end date as ISO 8601 being after the issue creation date will make it stale and close it when it is old enough and days-before-close is set to 0', async () => {
311+
expect.assertions(2);
312+
const january2000 = '2000-01-01T00:00:00Z';
313+
const opts: IIssuesProcessorOptions = {
314+
...DefaultProcessorOptions,
315+
daysBeforeClose: 0,
316+
endDate: january2000.toString()
317+
};
318+
const TestIssueList: Issue[] = [
319+
generateIssue(
320+
opts,
321+
1,
322+
'An issue with no label',
323+
'2020-01-01T17:00:00Z',
324+
'1999-12-31T17:00:00Z'
325+
)
326+
];
327+
const processor = new IssuesProcessorMock(
328+
opts,
329+
async p => (p === 1 ? TestIssueList : []),
330+
async () => [],
331+
async () => new Date().toDateString()
332+
);
333+
334+
// process our fake issue list
335+
await processor.processIssues(1);
336+
337+
expect(processor.staleIssues.length).toStrictEqual(1);
338+
expect(processor.closedIssues.length).toStrictEqual(1);
339+
});
340+
341+
test('processing an issue with no label and an end date as RFC 2822 being before the issue creation date will not make it stale nor close it when it is old enough and days-before-close is set to 0', async () => {
342+
expect.assertions(2);
343+
const january2000 = 'January 1, 2000 00:00:00';
344+
const opts: IIssuesProcessorOptions = {
345+
...DefaultProcessorOptions,
346+
daysBeforeClose: 0,
347+
endDate: january2000.toString()
348+
};
349+
const TestIssueList: Issue[] = [
350+
generateIssue(
351+
opts,
352+
1,
353+
'An issue with no label',
354+
'2020-01-01T17:00:00Z',
355+
'2000-01-01T17:00:00Z'
356+
)
357+
];
358+
const processor = new IssuesProcessorMock(
359+
opts,
360+
async p => (p === 1 ? TestIssueList : []),
361+
async () => [],
362+
async () => new Date().toDateString()
363+
);
364+
365+
// process our fake issue list
366+
await processor.processIssues(1);
367+
368+
expect(processor.staleIssues.length).toStrictEqual(0);
369+
expect(processor.closedIssues.length).toStrictEqual(0);
370+
});
371+
372+
test('processing an issue with no label and an end date as RFC 2822 being after the issue creation date will make it stale and close it when it is old enough and days-before-close is set to 0', async () => {
373+
expect.assertions(2);
374+
const january2000 = 'January 1, 2000 00:00:00';
375+
const opts: IIssuesProcessorOptions = {
376+
...DefaultProcessorOptions,
377+
daysBeforeClose: 0,
378+
endDate: january2000.toString()
379+
};
380+
const TestIssueList: Issue[] = [
381+
generateIssue(
382+
opts,
383+
1,
384+
'An issue with no label',
385+
'2020-01-01T17:00:00Z',
386+
'1999-12-31T17:00:00Z'
387+
)
388+
];
389+
const processor = new IssuesProcessorMock(
390+
opts,
391+
async p => (p === 1 ? TestIssueList : []),
392+
async () => [],
393+
async () => new Date().toDateString()
394+
);
395+
396+
// process our fake issue list
397+
await processor.processIssues(1);
398+
399+
expect(processor.staleIssues.length).toStrictEqual(1);
400+
expect(processor.closedIssues.length).toStrictEqual(1);
401+
});
402+
279403
test('processing an issue with no label will make it stale and close it, if it is old enough only if days-before-close is set to > 0 and days-before-issue-close is set to 0', async () => {
280404
const opts: IIssuesProcessorOptions = {
281405
...DefaultProcessorOptions,

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ inputs:
144144
description: 'The date used to skip the stale action on issue/pull request created before it (ISO 8601 or RFC 2822).'
145145
default: ''
146146
required: false
147+
end-date:
148+
description: 'The date used to skip the stale action on issue/pull request created after it (ISO 8601 or RFC 2822).'
149+
default: ''
150+
required: false
147151
exempt-assignees:
148152
description: 'The assignees which exempt an issue or a pull request from being marked as stale. Separate multiple assignees with commas (eg. "user1,user2").'
149153
default: ''

0 commit comments

Comments
 (0)