Compare commits

...

1 Commits

Author SHA1 Message Date
Ross Brodbeck 58a33fd7e8 Close stale issues even if they were just marked stale 2020-05-11 11:11:41 -04:00
3 changed files with 52 additions and 13 deletions

View File

@ -36,7 +36,7 @@ const DefaultProcessorOptions: IssueProcessorOptions = {
staleIssueMessage: 'This issue is stale', staleIssueMessage: 'This issue is stale',
stalePrMessage: 'This PR is stale', stalePrMessage: 'This PR is stale',
daysBeforeStale: 1, daysBeforeStale: 1,
daysBeforeClose: 1, daysBeforeClose: 30,
staleIssueLabel: 'Stale', staleIssueLabel: 'Stale',
exemptIssueLabels: '', exemptIssueLabels: '',
stalePrLabel: 'Stale', stalePrLabel: 'Stale',
@ -62,7 +62,7 @@ test('empty issue list results in 1 operation', async () => {
expect(operationsLeft).toEqual(99); expect(operationsLeft).toEqual(99);
}); });
test('processing an issue with no label will make it stale', async () => { test('processing an issue with no label will make it stale and close it, if it is old enough', async () => {
const TestIssueList: Issue[] = [ const TestIssueList: Issue[] = [
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z') generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z')
]; ];
@ -77,6 +77,30 @@ test('processing an issue with no label will make it stale', async () => {
// process our fake issue list // process our fake issue list
await processor.processIssues(1); await processor.processIssues(1);
expect(processor.staleIssues.length).toEqual(1);
expect(processor.closedIssues.length).toEqual(1);
});
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
// stale but not close-able, based on default settings
let issueDate = new Date();
issueDate.setDate(issueDate.getDate() - 2);
const TestIssueList: Issue[] = [
generateIssue(1, 'An issue with no label', issueDate.toDateString())
];
const processor = new IssueProcessor(
DefaultProcessorOptions,
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(1); expect(processor.staleIssues.length).toEqual(1);
expect(processor.closedIssues.length).toEqual(0); expect(processor.closedIssues.length).toEqual(0);
}); });

18
dist/index.js vendored
View File

@ -8510,14 +8510,20 @@ class IssueProcessor {
core.debug(`Skipping ${issueType} because it has an exempt label`); core.debug(`Skipping ${issueType} because it has an exempt label`);
continue; // don't process exempt issues continue; // don't process exempt issues
} }
if (IssueProcessor.isLabeled(issue, staleLabel)) { // does this issue have a stale label?
core.debug(`Found a stale ${issueType}`); let isStale = IssueProcessor.isLabeled(issue, staleLabel);
yield this.processStaleIssue(issue, issueType, staleLabel); // determine if this issue needs to be marked stale first
} if (!isStale &&
else if (!IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale)) { !IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale)) {
core.debug(`Marking ${issueType} stale because it was last updated on ${issue.updated_at}`); core.debug(`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`);
yield this.markStale(issue, staleMessage, staleLabel); yield this.markStale(issue, staleMessage, staleLabel);
this.operationsLeft -= 2; this.operationsLeft -= 2;
isStale = true; // this issue is now considered stale
}
// process any issues marked stale (including the issue above, if it was marked)
if (isStale) {
core.debug(`Found a stale ${issueType}`);
yield this.processStaleIssue(issue, issueType, staleLabel);
} }
} }
// do the next batch // do the next batch

View File

@ -150,20 +150,29 @@ export class IssueProcessor {
continue; // don't process exempt issues continue; // don't process exempt issues
} }
if (IssueProcessor.isLabeled(issue, staleLabel)) { // does this issue have a stale label?
core.debug(`Found a stale ${issueType}`); let isStale = IssueProcessor.isLabeled(issue, staleLabel);
await this.processStaleIssue(issue, issueType, staleLabel);
} else if ( // determine if this issue needs to be marked stale first
if (
!isStale &&
!IssueProcessor.updatedSince( !IssueProcessor.updatedSince(
issue.updated_at, issue.updated_at,
this.options.daysBeforeStale this.options.daysBeforeStale
) )
) { ) {
core.debug( core.debug(
`Marking ${issueType} stale because it was last updated on ${issue.updated_at}` `Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`
); );
await this.markStale(issue, staleMessage, staleLabel); await this.markStale(issue, staleMessage, staleLabel);
this.operationsLeft -= 2; this.operationsLeft -= 2;
isStale = true; // this issue is now considered stale
}
// process any issues marked stale (including the issue above, if it was marked)
if (isStale) {
core.debug(`Found a stale ${issueType}`);
await this.processStaleIssue(issue, issueType, staleLabel);
} }
} }