Skip to content

Commit

Permalink
feat: remove the only-labels option
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
The option only-labels was removed
  • Loading branch information
C0ZEN committed Oct 8, 2021
1 parent a8c5bb1 commit 6299c36
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 138 deletions.
39 changes: 20 additions & 19 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
name: 'Stale issue handler'
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@main
id: stale
with:
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
days-before-stale: 30
days-before-close: 5
exempt-issue-labels: 'blocked,must,should,keep'
- name: Print outputs
run: echo ${{ join(steps.stale.outputs.*, ',') }}
name: 'Stale issue handler'
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@main
id: stale
with:
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
days-before-stale: 30
days-before-issue-close: 5
days-before-pr-close: 5
exempt-issue-labels: 'blocked,must,should,keep'
- name: Print outputs
run: echo ${{ join(steps.stale.outputs.*, ',') }}
37 changes: 17 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ Every argument is optional.
| [days-before-stale](#days-before-stale) | Idle number of days before marking issues/PRs stale | `60` |
| [days-before-issue-stale](#days-before-issue-stale) | Override [days-before-stale](#days-before-stale) for issues only | |
| [days-before-pr-stale](#days-before-pr-stale) | Override [days-before-stale](#days-before-stale) for PRs only | |
| [days-before-close](#days-before-close) | Idle number of days before closing stale issues/PRs | `7` |
| [days-before-issue-close](#days-before-issue-close) | Override [days-before-close](#days-before-close) for issues only | |
| [days-before-pr-close](#days-before-pr-close) | Override [days-before-close](#days-before-close) for PRs only | |
| [days-before-issue-close](#days-before-issue-close) | Idle number of days before closing stale issues | `7` |
| [days-before-pr-close](#days-before-pr-close) | Idle number of days before closing stale PRs | `7` |
| [stale-issue-message](#stale-issue-message) | Comment on the staled issues | |
| [stale-pr-message](#stale-pr-message) | Comment on the staled PRs | |
| [close-issue-message](#close-issue-message) | Comment on the staled issues while closed | |
Expand Down Expand Up @@ -144,32 +143,29 @@ Useful to override [days-before-stale](#days-before-stale) but only for the idle

Default value: unset

#### days-before-close
#### days-before-issue-close

The idle number of days before closing the stale issues or the stale pull requests (due to the stale label).
The issues or the pull requests will be closed if the last update (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) is older than the idle number of days.
The idle number of days before closing the stale issues (due to the stale label).
The issues will be closed if the last update (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) is older than the idle number of days.
Since adding the stale label will alter the last update date, we can calculate the number of days from this date.

If set to a negative number like `-1`, the issues or the pull requests will never be closed automatically.

The label used to stale is defined by these two options:
If set to a negative number like `-1`, the issues will never be closed automatically.

- [stale-issue-label](#stale-issue-label)
- [stale-pr-label](#stale-pr-label)
The label used to stale is defined by this option: [stale-issue-label](#stale-issue-label)

Default value: `7`

#### days-before-issue-close

Override [days-before-close](#days-before-close) but only for the idle number of days before closing the stale issues.
#### days-before-pr-close

Default value: unset
The idle number of days before closing the stale pull requests (due to the stale label).
The pull requests will be closed if the last update (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) is older than the idle number of days.
Since adding the stale label will alter the last update date, we can calculate the number of days from this date.

#### days-before-pr-close
If set to a negative number like `-1`, the pull requests will never be closed automatically.

Override [days-before-close](#days-before-close) but only for the idle number of days before closing the stale pull requests.
The label used to stale is defined by this option: [stale-pr-label](#stale-pr-label)

Default value: unset
Default value: `7`

#### stale-issue-message

Expand Down Expand Up @@ -527,7 +523,8 @@ jobs:
with:
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
days-before-stale: 30
days-before-close: 5
days-before-issue-close: 5
days-before-pr-close: 5
```

Configure different stale timeouts but never close a PR:
Expand All @@ -548,7 +545,7 @@ jobs:
stale-pr-message: 'This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.'
close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.'
days-before-stale: 30
days-before-close: 5
days-before-issue-close: 5
days-before-pr-close: -1
```

Expand Down
5 changes: 2 additions & 3 deletions __tests__/constants/default-processor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
daysBeforeStale: 1,
daysBeforeIssueStale: NaN,
daysBeforePrStale: NaN,
daysBeforeClose: 30,
daysBeforeIssueClose: NaN,
daysBeforePrClose: NaN,
daysBeforeIssueClose: 30,
daysBeforePrClose: 30,
staleIssueLabel: 'Stale',
closeIssueLabel: '',
exemptIssueLabels: '',
Expand Down
73 changes: 24 additions & 49 deletions __tests__/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {generateIssue} from './functions/generate-issue';
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', async () => {
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0
daysBeforeIssueClose: 0
};
const TestIssueList: Issue[] = [
generateIssue(opts, 1, 'An issue with no label', '2020-01-01T17:00:00Z')
Expand All @@ -33,7 +33,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
const january2000 = 946681200000;
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
daysBeforeIssueClose: 0,
startDate: january2000.toString()
};
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -64,7 +64,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
const january2021 = 1609455600000;
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
daysBeforeIssueClose: 0,
startDate: january2021.toString()
};
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -95,7 +95,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
const january2000 = 946681200000000;
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
daysBeforeIssueClose: 0,
startDate: january2000.toString()
};
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -126,7 +126,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
const january2021 = 1609455600000;
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
daysBeforeIssueClose: 0,
startDate: january2021.toString()
};
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -157,7 +157,7 @@ test('processing an issue with no label and a start date as ISO 8601 being befor
const january2000 = '2000-01-01T00:00:00Z';
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
daysBeforeIssueClose: 0,
startDate: january2000.toString()
};
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -188,7 +188,7 @@ test('processing an issue with no label and a start date as ISO 8601 being after
const january2021 = '2021-01-01T00:00:00Z';
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
daysBeforeIssueClose: 0,
startDate: january2021.toString()
};
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -219,7 +219,7 @@ test('processing an issue with no label and a start date as RFC 2822 being befor
const january2000 = 'January 1, 2000 00:00:00';
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
daysBeforeIssueClose: 0,
startDate: january2000.toString()
};
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -250,7 +250,7 @@ test('processing an issue with no label and a start date as RFC 2822 being after
const january2021 = 'January 1, 2021 00:00:00';
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
daysBeforeIssueClose: 0,
startDate: january2021.toString()
};
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -279,7 +279,6 @@ test('processing an issue with no label and a start date as RFC 2822 being after
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,
daysBeforeClose: 1,
daysBeforeIssueClose: 0
};
const TestIssueList: Issue[] = [
Expand All @@ -300,33 +299,10 @@ test('processing an issue with no label will make it stale and close it, if it i
expect(processor.deletedBranchIssues).toHaveLength(0);
});

test('processing an issue with no label will make it stale and not 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,
daysBeforeClose: 1,
daysBeforeIssueClose: 1
};
const TestIssueList: Issue[] = [
generateIssue(opts, 1, 'An issue with no label', '2020-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).toHaveLength(1);
expect(processor.closedIssues).toHaveLength(0);
});

test('processing an issue with no label will make it stale and not close it if days-before-close is set to > 0', async () => {
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 15
daysBeforeIssueClose: 15
};
const TestIssueList: Issue[] = [
generateIssue(opts, 1, 'An issue with no label', '2020-01-01T17:00:00Z')
Expand All @@ -348,7 +324,6 @@ test('processing an issue with no label will make it stale and not close it if d
test('processing an issue with no label will make it stale and not close it if days-before-close is set to -1 and days-before-issue-close is set to > 0', async () => {
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: -1,
daysBeforeIssueClose: 15
};
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -445,7 +420,7 @@ test('processing an issue with no label will make it stale but not close it', as
test('processing a stale issue will close it', async () => {
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 30
daysBeforeIssueClose: 30
};
const TestIssueList: Issue[] = [
generateIssue(
Expand Down Expand Up @@ -535,7 +510,7 @@ test('processing a stale issue containing a slash in the label will close it', a
test('processing a stale issue will close it when days-before-issue-stale override days-before-stale', async () => {
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 30,
daysBeforeIssueClose: 30,
daysBeforeIssueStale: 30
};
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -566,7 +541,7 @@ test('processing a stale issue will close it when days-before-issue-stale overri
test('processing a stale PR will close it', async () => {
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 30
daysBeforePrClose: 30
};
const TestIssueList: Issue[] = [
generateIssue(
Expand Down Expand Up @@ -596,7 +571,6 @@ test('processing a stale PR will close it', async () => {
test('processing a stale PR will close it when days-before-pr-stale override days-before-stale', async () => {
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 30,
daysBeforePrClose: 30
};
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -1134,7 +1108,8 @@ test('exempt issue labels will not be marked stale and will remove the existing

test('stale issues should not be closed if days is set to -1', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeClose = -1;
opts.daysBeforeIssueClose = -1;
opts.daysBeforePrClose = -1;
const TestIssueList: Issue[] = [
generateIssue(
opts,
Expand Down Expand Up @@ -1330,7 +1305,7 @@ test('stale label containing a space should be removed if a comment was added to
test('stale issues should not be closed until after the closed number of days', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 1; // closes after 6 days
opts.daysBeforeIssueClose = 1; // closes after 6 days
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 5);
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -1361,7 +1336,7 @@ test('stale issues should not be closed until after the closed number of days',
test('stale issues should be closed if the closed nubmer of days (additive) is also passed', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 1; // closes after 6 days
opts.daysBeforeIssueClose = 1; // closes after 6 days
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 7);
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -1393,7 +1368,7 @@ test('stale issues should be closed if the closed nubmer of days (additive) is a
test('stale issues should not be closed until after the closed number of days (long)', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 20; // closes after 25 days
opts.daysBeforeIssueClose = 20; // closes after 25 days
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
const TestIssueList: Issue[] = [
Expand Down Expand Up @@ -1424,7 +1399,7 @@ test('stale issues should not be closed until after the closed number of days (l
test('skips stale message on issues when stale-issue-message is empty', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 20; // closes after 25 days
opts.daysBeforeIssueClose = 20; // closes after 25 days
opts.staleIssueMessage = '';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
Expand Down Expand Up @@ -1468,7 +1443,7 @@ test('skips stale message on issues when stale-issue-message is empty', async ()
test('send stale message on issues when stale-issue-message is not empty', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 20; // closes after 25 days
opts.daysBeforeIssueClose = 20; // closes after 25 days
opts.staleIssueMessage = 'dummy issue message';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
Expand Down Expand Up @@ -1512,7 +1487,7 @@ test('send stale message on issues when stale-issue-message is not empty', async
test('skips stale message on prs when stale-pr-message is empty', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 20; // closes after 25 days
opts.daysBeforeIssueClose = 20; // closes after 25 days
opts.stalePrMessage = '';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
Expand Down Expand Up @@ -1556,7 +1531,7 @@ test('skips stale message on prs when stale-pr-message is empty', async () => {
test('send stale message on prs when stale-pr-message is not empty', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 20; // closes after 25 days
opts.daysBeforeIssueClose = 20; // closes after 25 days
opts.stalePrMessage = 'dummy pr message';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
Expand Down Expand Up @@ -2106,7 +2081,7 @@ test('processing an issue stale since less than the daysBeforeStale with a stale
...DefaultProcessorOptions,
staleIssueLabel: 'stale-label',
daysBeforeStale: 30,
daysBeforeClose: 7,
daysBeforeIssueClose: 7,
closeIssueMessage: 'close message',
removeStaleWhenUpdated: false
};
Expand Down Expand Up @@ -2147,7 +2122,7 @@ test('processing an issue stale since less than the daysBeforeStale without a st
...DefaultProcessorOptions,
staleIssueLabel: 'stale-label',
daysBeforeStale: 30,
daysBeforeClose: 7,
daysBeforeIssueClose: 7,
closeIssueMessage: 'close message',
removeStaleWhenUpdated: false
};
Expand Down
Loading

0 comments on commit 6299c36

Please sign in to comment.