Allow for issues/PRs to be closed after manually being marked as stale (#103)
Previously this action would stop and skip all issues or pull requests it found if no `stale-issue-message | stale-pr-message` option had been configured. Configuring `days-before-stale: -1` will activate that behaviour.
This commit is contained in:
parent
c2daa6ff62
commit
f111c4f385
|
@ -109,6 +109,31 @@ test('processing an issue with no label will make it stale and not close it if d
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('processing an issue with no label will not make it stale if days-before-stale is set to -1', async () => {
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z')
|
||||||
|
];
|
||||||
|
|
||||||
|
const opts = {
|
||||||
|
...DefaultProcessorOptions,
|
||||||
|
staleIssueMessage: '',
|
||||||
|
daysBeforeStale: -1
|
||||||
|
};
|
||||||
|
|
||||||
|
const processor = new IssueProcessor(
|
||||||
|
opts,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
|
);
|
||||||
|
|
||||||
|
// process our fake issue list
|
||||||
|
await processor.processIssues(1);
|
||||||
|
|
||||||
|
expect(processor.staleIssues.length).toEqual(0);
|
||||||
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
test('processing an issue with no label will make it stale but not close it', async () => {
|
test('processing an issue with no label will make it stale but not close it', async () => {
|
||||||
// issue should be from 2 days ago so it will be
|
// issue should be from 2 days ago so it will be
|
||||||
// stale but not close-able, based on default settings
|
// stale but not close-able, based on default settings
|
||||||
|
@ -183,6 +208,60 @@ test('processing a stale PR will close it', async () => {
|
||||||
expect(processor.closedIssues.length).toEqual(1);
|
expect(processor.closedIssues.length).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('processing a stale issue will close it even if configured not to mark as stale', async () => {
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z', false, [
|
||||||
|
'Stale'
|
||||||
|
])
|
||||||
|
];
|
||||||
|
|
||||||
|
const opts = {
|
||||||
|
...DefaultProcessorOptions,
|
||||||
|
daysBeforeStale: -1,
|
||||||
|
staleIssueMessage: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
const processor = new IssueProcessor(
|
||||||
|
opts,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
|
);
|
||||||
|
|
||||||
|
// process our fake issue list
|
||||||
|
await processor.processIssues(1);
|
||||||
|
|
||||||
|
expect(processor.staleIssues.length).toEqual(0);
|
||||||
|
expect(processor.closedIssues.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('processing a stale PR will close it even if configured not to mark as stale', async () => {
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z', true, [
|
||||||
|
'Stale'
|
||||||
|
])
|
||||||
|
];
|
||||||
|
|
||||||
|
const opts = {
|
||||||
|
...DefaultProcessorOptions,
|
||||||
|
daysBeforeStale: -1,
|
||||||
|
stalePrMessage: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
const processor = new IssueProcessor(
|
||||||
|
opts,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
|
);
|
||||||
|
|
||||||
|
// process our fake issue list
|
||||||
|
await processor.processIssues(1);
|
||||||
|
|
||||||
|
expect(processor.staleIssues.length).toEqual(0);
|
||||||
|
expect(processor.closedIssues.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
test('closed issues will not be marked stale', async () => {
|
test('closed issues will not be marked stale', async () => {
|
||||||
const TestIssueList: Issue[] = [
|
const TestIssueList: Issue[] = [
|
||||||
generateIssue(
|
generateIssue(
|
||||||
|
|
|
@ -14,7 +14,7 @@ inputs:
|
||||||
close-pr-message:
|
close-pr-message:
|
||||||
description: 'The message to post on the pr when closing it. If none provided, will not comment when closing a pull requests.'
|
description: 'The message to post on the pr when closing it. If none provided, will not comment when closing a pull requests.'
|
||||||
days-before-stale:
|
days-before-stale:
|
||||||
description: 'The number of days old an issue can be before marking it stale.'
|
description: 'The number of days old an issue can be before marking it stale. Set to -1 to never mark issues or pull requests as stale automatically.'
|
||||||
default: 60
|
default: 60
|
||||||
days-before-close:
|
days-before-close:
|
||||||
description: 'The number of days to wait to close an issue or pull request after it being marked stale. Set to -1 to never close stale issues.'
|
description: 'The number of days to wait to close an issue or pull request after it being marked stale. Set to -1 to never close stale issues.'
|
||||||
|
|
|
@ -130,8 +130,9 @@ export class IssueProcessor {
|
||||||
isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels
|
isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels
|
||||||
);
|
);
|
||||||
const issueType: string = isPr ? 'pr' : 'issue';
|
const issueType: string = isPr ? 'pr' : 'issue';
|
||||||
|
const shouldMarkWhenStale = this.options.daysBeforeStale > -1;
|
||||||
|
|
||||||
if (!staleMessage) {
|
if (!staleMessage && shouldMarkWhenStale) {
|
||||||
core.info(`Skipping ${issueType} due to empty stale message`);
|
core.info(`Skipping ${issueType} due to empty stale message`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +166,7 @@ export class IssueProcessor {
|
||||||
);
|
);
|
||||||
|
|
||||||
// determine if this issue needs to be marked stale first
|
// determine if this issue needs to be marked stale first
|
||||||
if (!isStale && shouldBeStale) {
|
if (!isStale && shouldBeStale && shouldMarkWhenStale) {
|
||||||
core.info(
|
core.info(
|
||||||
`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`
|
`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue