feat(options): simplify config by removing skip stale message options (#457)

* feat(options): simplify config by removing skip stale message options

Closes #405
Closes #455

BREAKING CHANGES: remove skip-stale-issue-message and skip-stale-pr-message options. If you used this option, replace it by an empty message for the options stale-issue-message and stale-pr-message

* build(dist): update dist

also lint some files

* docs(readme): update the docs by removing the skip options
This commit is contained in:
Geoffrey Testelin 2021-05-25 20:14:22 +02:00 committed by GitHub
parent 16dfaa2c02
commit 6ec637d238
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1868 additions and 1904 deletions

View File

@ -20,8 +20,7 @@ jobs:
runs-on: ...
steps:
- uses: actions/stale@...
with:
...
with: ...
```
## Further context

View File

@ -1,5 +1,7 @@
<!-- List the change(s) you're making with this PR. -->
## Changes
- [x] ...
## Context

View File

@ -39,8 +39,6 @@ Every argument is optional.
| [remove-pr-stale-when-updated](#remove-pr-stale-when-updated) | Remove stale label from PRs on updates/comments | |
| [debug-only](#debug-only) | Dry-run | `false` |
| [ascending](#ascending) | Order to get issues/PRs | `false` |
| [skip-stale-issue-message](#skip-stale-issue-message) | Skip adding stale message on stale issues | `false` |
| [skip-stale-pr-message](#skip-stale-pr-message) | Skip adding stale message on stale PRs | `false` |
| [start-date](#start-date) | Skip stale action for issues/PRs created before it | |
| [delete-branch](#delete-branch) | Delete branch after closing a stale PR | `false` |
| [exempt-milestones](#exempt-milestones) | Milestones on issues/PRs exempted from stale | |
@ -141,7 +139,7 @@ Default value: unset
The message that will be added as a comment to the issues when the stale workflow marks it automatically as stale with a label.
You can omit the comment by setting [skip-stale-issue-message](#skip-stale-issue-message) to `true`.
You can skip the comment sending by omitting the option or by passing an empty string.
Default value: unset
@ -149,7 +147,7 @@ Default value: unset
The message that will be added as a comment to the pull requests when the stale workflow marks it automatically as stale with a label.
You can omit the comment by setting [skip-stale-pr-message](#skip-stale-pr-message) to `true`.
You can skip the comment sending by omitting the option or by passing an empty string.
Default value: unset
@ -316,22 +314,6 @@ Based on the order, you could prefer to focus on the new content or on the old c
Default value: `false`
#### skip-stale-issue-message
If set to `true`, no comment will be added to the issues when they are automatically marked as stale.
If set to `false`, you can define the comment with the [stale-issue-message](#stale-issue-message) option.
Default value: `false`
#### skip-stale-pr-message
If set to `true`, no comment will be added to the pull requests when they are automatically marked as stale.
If set to `false`, you can define the comment with the [stale-pr-message](#stale-pr-message) option.
Default value: `false`
#### start-date
The start date is used to ignore the issues and pull requests created before the start date.

View File

@ -30,8 +30,6 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
removeIssueStaleWhenUpdated: undefined,
removePrStaleWhenUpdated: undefined,
ascending: false,
skipStaleIssueMessage: false,
skipStalePrMessage: false,
deleteBranch: false,
startDate: '',
exemptMilestones: '',

View File

@ -1422,11 +1422,11 @@ test('stale issues should not be closed until after the closed number of days (l
expect(processor.staleIssues).toHaveLength(1);
});
test('skips stale message on issues when skip-stale-issue-message is set', async () => {
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.skipStaleIssueMessage = true;
opts.staleIssueMessage = '';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
const TestIssueList: Issue[] = [
@ -1467,11 +1467,56 @@ test('skips stale message on issues when skip-stale-issue-message is set', async
);
});
test('skips stale message on prs when skip-stale-pr-message is set', 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.skipStalePrMessage = true;
opts.staleIssueMessage = 'dummy issue message';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue that should be marked stale but not closed',
lastUpdate.toString(),
lastUpdate.toString(),
false
)
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);
// for sake of testing, mocking private function
const markSpy = jest.spyOn(processor as any, '_markStale');
await processor.processIssues(1);
// issue should be staled
expect(processor.closedIssues).toHaveLength(0);
expect(processor.removedLabelIssues).toHaveLength(0);
expect(processor.staleIssues).toHaveLength(1);
// comment should not be created
expect(markSpy).toHaveBeenCalledWith(
TestIssueList[0],
opts.staleIssueMessage,
opts.staleIssueLabel,
// this option is skipMessage
false
);
});
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.stalePrMessage = '';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
const TestIssueList: Issue[] = [
@ -1512,46 +1557,11 @@ test('skips stale message on prs when skip-stale-pr-message is set', async () =>
);
});
test('not providing state takes precedence over skipStaleIssueMessage', 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.skipStalePrMessage = true;
opts.staleIssueMessage = '';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue that should be marked stale but not closed',
lastUpdate.toString(),
lastUpdate.toString(),
false
)
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);
await processor.processIssues(1);
// issue should be staled
expect(processor.closedIssues).toHaveLength(0);
expect(processor.removedLabelIssues).toHaveLength(0);
expect(processor.staleIssues).toHaveLength(0);
});
test('not providing stalePrMessage takes precedence over skipStalePrMessage', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 20; // closes after 25 days
opts.skipStalePrMessage = true;
opts.stalePrMessage = '';
opts.stalePrMessage = 'dummy pr message';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
const TestIssueList: Issue[] = [
@ -1572,12 +1582,24 @@ test('not providing stalePrMessage takes precedence over skipStalePrMessage', as
async () => new Date().toDateString()
);
// for sake of testing, mocking private function
const markSpy = jest.spyOn(processor as any, '_markStale');
await processor.processIssues(1);
// issue should be staled
expect(processor.closedIssues).toHaveLength(0);
expect(processor.removedLabelIssues).toHaveLength(0);
expect(processor.staleIssues).toHaveLength(0);
expect(processor.staleIssues).toHaveLength(1);
// comment should not be created
expect(markSpy).toHaveBeenCalledWith(
TestIssueList[0],
opts.stalePrMessage,
opts.stalePrLabel,
// this option is skipMessage
false
);
});
test('git branch is deleted when option is enabled', async () => {

View File

@ -132,14 +132,6 @@ inputs:
description: 'The order to get issues or pull requests. Defaults to false, which is descending.'
default: 'false'
required: false
skip-stale-pr-message:
description: 'Skip adding stale message when marking a pull request as stale.'
default: 'false'
required: false
skip-stale-issue-message:
description: 'Skip adding stale message when marking an issue as stale.'
default: 'false'
required: false
delete-branch:
description: 'Delete the git branch after closing a stale pull request.'
default: 'false'

13
dist/index.js vendored
View File

@ -317,8 +317,8 @@ class IssuesProcessor {
? this.options.closePrLabel
: this.options.closeIssueLabel;
const skipMessage = issue.isPullRequest
? this.options.skipStalePrMessage
: this.options.skipStaleIssueMessage;
? this.options.stalePrMessage.length === 0
: this.options.staleIssueMessage.length === 0;
const daysBeforeStale = issue.isPullRequest
? this._getDaysBeforePrStale()
: this._getDaysBeforeIssueStale();
@ -344,11 +344,6 @@ class IssuesProcessor {
}
issueLogger.info(`Days before $$type stale: ${chalk_1.default.cyan(daysBeforeStale)}`);
const shouldMarkAsStale = should_mark_when_stale_1.shouldMarkWhenStale(daysBeforeStale);
if (!staleMessage && shouldMarkAsStale) {
issueLogger.info(`Skipping this $$type because it should be marked as stale based on the option ${issueLogger.createOptionLink(this._getDaysBeforeStaleUsedOptionName(issue))} (${chalk_1.default.cyan(daysBeforeStale)}) but the option ${issueLogger.createOptionLink(IssuesProcessor._getStaleMessageUsedOptionName(issue))} is not set`);
IssuesProcessor._endIssueProcessing(issue);
continue;
}
if (issue.state === 'closed') {
issueLogger.info(`Skipping this $$type because it is closed`);
IssuesProcessor._endIssueProcessing(issue);
@ -1620,8 +1615,6 @@ var Option;
Option["RemoveStaleWhenUpdated"] = "remove-stale-when-updated";
Option["DebugOnly"] = "debug-only";
Option["Ascending"] = "ascending";
Option["SkipStaleIssueMessage"] = "skip-stale-issue-message";
Option["SkipStalePrMessage"] = "skip-stale-pr-message";
Option["DeleteBranch"] = "delete-branch";
Option["StartDate"] = "start-date";
Option["ExemptMilestones"] = "exempt-milestones";
@ -1902,8 +1895,6 @@ function _getAndValidateArgs() {
removePrStaleWhenUpdated: _toOptionalBoolean(core.getInput('remove-pr-stale-when-updated')),
debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true',
skipStalePrMessage: core.getInput('skip-stale-pr-message') === 'true',
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true',
deleteBranch: core.getInput('delete-branch') === 'true',
startDate: core.getInput('start-date') !== ''
? core.getInput('start-date')

View File

@ -38,8 +38,6 @@ describe('Issue', (): void => {
removeIssueStaleWhenUpdated: undefined,
removePrStaleWhenUpdated: undefined,
repoToken: '',
skipStaleIssueMessage: false,
skipStalePrMessage: false,
staleIssueMessage: '',
stalePrMessage: '',
startDate: undefined,

View File

@ -138,8 +138,8 @@ export class IssuesProcessor {
? this.options.closePrLabel
: this.options.closeIssueLabel;
const skipMessage = issue.isPullRequest
? this.options.skipStalePrMessage
: this.options.skipStaleIssueMessage;
? this.options.stalePrMessage.length === 0
: this.options.staleIssueMessage.length === 0;
const daysBeforeStale: number = issue.isPullRequest
? this._getDaysBeforePrStale()
: this._getDaysBeforeIssueStale();
@ -196,20 +196,6 @@ export class IssuesProcessor {
const shouldMarkAsStale: boolean = shouldMarkWhenStale(daysBeforeStale);
if (!staleMessage && shouldMarkAsStale) {
issueLogger.info(
`Skipping this $$type because it should be marked as stale based on the option ${issueLogger.createOptionLink(
this._getDaysBeforeStaleUsedOptionName(issue)
)} (${chalk.cyan(
daysBeforeStale
)}) but the option ${issueLogger.createOptionLink(
IssuesProcessor._getStaleMessageUsedOptionName(issue)
)} is not set`
);
IssuesProcessor._endIssueProcessing(issue);
continue;
}
if (issue.state === 'closed') {
issueLogger.info(`Skipping this $$type because it is closed`);
IssuesProcessor._endIssueProcessing(issue);

View File

@ -24,8 +24,6 @@ export enum Option {
RemoveStaleWhenUpdated = 'remove-stale-when-updated',
DebugOnly = 'debug-only',
Ascending = 'ascending',
SkipStaleIssueMessage = 'skip-stale-issue-message',
SkipStalePrMessage = 'skip-stale-pr-message',
DeleteBranch = 'delete-branch',
StartDate = 'start-date',
ExemptMilestones = 'exempt-milestones',

View File

@ -30,8 +30,6 @@ export interface IIssuesProcessorOptions {
removePrStaleWhenUpdated: boolean | undefined;
debugOnly: boolean;
ascending: boolean;
skipStaleIssueMessage: boolean;
skipStalePrMessage: boolean;
deleteBranch: boolean;
startDate: IsoOrRfcDateString | undefined; // Should be ISO 8601 or RFC 2822
exemptMilestones: string;

View File

@ -57,8 +57,6 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
),
debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true',
skipStalePrMessage: core.getInput('skip-stale-pr-message') === 'true',
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true',
deleteBranch: core.getInput('delete-branch') === 'true',
startDate:
core.getInput('start-date') !== ''