Skip to content

Commit

Permalink
Close stale issues even if they were just marked stale (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
hross authored May 11, 2020
1 parent 1e900bc commit e611bf9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
28 changes: 26 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const DefaultProcessorOptions: IssueProcessorOptions = {
staleIssueMessage: 'This issue is stale',
stalePrMessage: 'This PR is stale',
daysBeforeStale: 1,
daysBeforeClose: 1,
daysBeforeClose: 30,
staleIssueLabel: 'Stale',
exemptIssueLabels: '',
stalePrLabel: 'Stale',
Expand All @@ -62,7 +62,7 @@ test('empty issue list results in 1 operation', async () => {
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[] = [
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z')
];
Expand All @@ -77,6 +77,30 @@ test('processing an issue with no label will make it stale', async () => {
// process our fake issue list
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.closedIssues.length).toEqual(0);
});
Expand Down
18 changes: 12 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8510,14 +8510,20 @@ class IssueProcessor {
core.debug(`Skipping ${issueType} because it has an exempt label`);
continue; // don't process exempt issues
}
if (IssueProcessor.isLabeled(issue, staleLabel)) {
core.debug(`Found a stale ${issueType}`);
yield this.processStaleIssue(issue, issueType, staleLabel);
}
else if (!IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale)) {
core.debug(`Marking ${issueType} stale because it was last updated on ${issue.updated_at}`);
// does this issue have a stale label?
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
// determine if this issue needs to be marked stale first
if (!isStale &&
!IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale)) {
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);
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
Expand Down
19 changes: 14 additions & 5 deletions src/IssueProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,29 @@ export class IssueProcessor {
continue; // don't process exempt issues
}

if (IssueProcessor.isLabeled(issue, staleLabel)) {
core.debug(`Found a stale ${issueType}`);
await this.processStaleIssue(issue, issueType, staleLabel);
} else if (
// does this issue have a stale label?
let isStale = IssueProcessor.isLabeled(issue, staleLabel);

// determine if this issue needs to be marked stale first
if (
!isStale &&
!IssueProcessor.updatedSince(
issue.updated_at,
this.options.daysBeforeStale
)
) {
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);
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);
}
}

Expand Down

0 comments on commit e611bf9

Please sign in to comment.