Skip to content

Commit

Permalink
feat: add support for end date
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mhdawson committed May 16, 2023
1 parent 03af7c3 commit 453d658
Show file tree
Hide file tree
Showing 9 changed files with 3,485 additions and 87 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -406,6 +406,14 @@ If set, the date must be formatted following the `ISO 8601` or `RFC 2822` standa

Default value: unset

#### end-date

The end date is used to ignore the issues and pull requests after the end date.

If set, the date must be formatted following the `ISO 8601` or `RFC 2822` standard.

Default value: unset

#### delete-branch

If set to `true`, the stale workflow will automatically delete the GitHub branches related to the pull requests automatically closed by the stale workflow.
Expand Down
1 change: 1 addition & 0 deletions __tests__/constants/default-processor-options.ts
Expand Up @@ -34,6 +34,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
ascending: false,
deleteBranch: false,
startDate: '',
endDate: '',
exemptMilestones: '',
exemptIssueMilestones: '',
exemptPrMilestones: '',
Expand Down
124 changes: 124 additions & 0 deletions __tests__/main.spec.ts
Expand Up @@ -276,6 +276,130 @@ test('processing an issue with no label and a start date as RFC 2822 being after
expect(processor.closedIssues.length).toStrictEqual(0);
});

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 () => {
expect.assertions(2);
const january2000 = '2000-01-01T00:00:00Z';
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
endDate: january2000.toString()
};
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue with no label',
'2020-01-01T17:00:00Z',
'2000-01-01T17:00:00Z'
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);

// process our fake issue list
await processor.processIssues(1);

expect(processor.staleIssues.length).toStrictEqual(0);
expect(processor.closedIssues.length).toStrictEqual(0);
});

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 () => {
expect.assertions(2);
const january2000 = '2000-01-01T00:00:00Z';
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
endDate: january2000.toString()
};
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue with no label',
'2020-01-01T17:00:00Z',
'1999-12-31T17:00:00Z'
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);

// process our fake issue list
await processor.processIssues(1);

expect(processor.staleIssues.length).toStrictEqual(1);
expect(processor.closedIssues.length).toStrictEqual(1);
});

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 () => {
expect.assertions(2);
const january2000 = 'January 1, 2000 00:00:00';
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
endDate: january2000.toString()
};
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue with no label',
'2020-01-01T17:00:00Z',
'2000-01-01T17:00:00Z'
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);

// process our fake issue list
await processor.processIssues(1);

expect(processor.staleIssues.length).toStrictEqual(0);
expect(processor.closedIssues.length).toStrictEqual(0);
});

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 () => {
expect.assertions(2);
const january2000 = 'January 1, 2000 00:00:00';
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
endDate: january2000.toString()
};
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue with no label',
'2020-01-01T17:00:00Z',
'1999-12-31T17:00:00Z'
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);

// process our fake issue list
await processor.processIssues(1);

expect(processor.staleIssues.length).toStrictEqual(1);
expect(processor.closedIssues.length).toStrictEqual(1);
});

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 () => {
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -144,6 +144,10 @@ inputs:
description: 'The date used to skip the stale action on issue/pull request created before it (ISO 8601 or RFC 2822).'
default: ''
required: false
end-date:
description: 'The date used to skip the stale action on issue/pull request created after it (ISO 8601 or RFC 2822).'
default: ''
required: false
exempt-assignees:
description: 'The assignees which exempt an issue or a pull request from being marked as stale. Separate multiple assignees with commas (eg. "user1,user2").'
default: ''
Expand Down

0 comments on commit 453d658

Please sign in to comment.