From 379e98cf36b45ff185789965c3ce12ae74a6dcb7 Mon Sep 17 00:00:00 2001 From: Ross Brodbeck Date: Mon, 11 May 2020 10:29:41 -0400 Subject: [PATCH] Add a test for un-staling --- __tests__/main.test.ts | 49 +++++++++++++++++++++++++++++++++--------- dist/index.js | 2 ++ src/IssueProcessor.ts | 3 +++ 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 7a6ab054..1940809f 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -343,11 +343,11 @@ test('exempt issue labels will not be marked stale', async () => { ]) ]; - let opts = DefaultProcessorOptions; + const opts = {...DefaultProcessorOptions}; opts.exemptIssueLabels = 'Exempt'; const processor = new IssueProcessor( - DefaultProcessorOptions, + opts, async p => (p == 1 ? TestIssueList : []), async (num, dt) => [], async (issue, label) => new Date().toDateString() @@ -365,11 +365,11 @@ test('exempt issue labels will not be marked stale (multi issue label with space generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool']) ]; - let opts = DefaultProcessorOptions; + const opts = {...DefaultProcessorOptions}; opts.exemptIssueLabels = 'Exempt, Cool, None'; const processor = new IssueProcessor( - DefaultProcessorOptions, + opts, async p => (p == 1 ? TestIssueList : []), async (num, dt) => [], async (issue, label) => new Date().toDateString() @@ -387,11 +387,11 @@ test('exempt issue labels will not be marked stale (multi issue label)', async ( generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool']) ]; - let opts = DefaultProcessorOptions; + const opts = {...DefaultProcessorOptions}; opts.exemptIssueLabels = 'Exempt,Cool,None'; const processor = new IssueProcessor( - DefaultProcessorOptions, + opts, async p => (p == 1 ? TestIssueList : []), async (num, dt) => [], async (issue, label) => new Date().toDateString() @@ -411,11 +411,11 @@ test('exempt pr labels will not be marked stale', async () => { generateIssue(3, 'Another issue', '2020-01-01T17:00:00Z', false) ]; - let opts = DefaultProcessorOptions; + const opts = {...DefaultProcessorOptions}; opts.exemptIssueLabels = 'Cool'; const processor = new IssueProcessor( - DefaultProcessorOptions, + opts, async p => (p == 1 ? TestIssueList : []), async (num, dt) => [], async (issue, label) => new Date().toDateString() @@ -436,11 +436,11 @@ test('stale issues should not be closed if days is set to -1', async () => { generateIssue(3, 'Another issue', '2020-01-01T17:00:00Z', false, ['Stale']) ]; - let opts = DefaultProcessorOptions; + const opts = {...DefaultProcessorOptions}; opts.daysBeforeClose = -1; const processor = new IssueProcessor( - DefaultProcessorOptions, + opts, async p => (p == 1 ? TestIssueList : []), async (num, dt) => [], async (issue, label) => new Date().toDateString() @@ -451,3 +451,32 @@ test('stale issues should not be closed if days is set to -1', async () => { expect(processor.closedIssues.length).toEqual(0); }); + +test('stale label should be removed if a comment was added to a stale issue', async () => { + const TestIssueList: Issue[] = [ + generateIssue( + 1, + 'An issue that should un-stale', + '2020-01-01T17:00:00Z', + false, + ['Stale'] + ) + ]; + + const opts = DefaultProcessorOptions; + opts.removeStaleWhenUpdated = true; + + const processor = new IssueProcessor( + opts, + async p => (p == 1 ? TestIssueList : []), + async (num, dt) => [{user: {type: 'User'}}], // return a fake comment so indicate there was an update + async (issue, label) => new Date().toDateString() + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.closedIssues.length).toEqual(0); + expect(processor.staleIssues.length).toEqual(0); + expect(processor.removedLabelIssues.length).toEqual(1); +}); diff --git a/dist/index.js b/dist/index.js index 36fc08ed..ce4aaa3e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -8452,6 +8452,7 @@ class IssueProcessor { this.operationsLeft = 0; this.staleIssues = []; this.closedIssues = []; + this.removedLabelIssues = []; this.options = options; this.operationsLeft = options.operationsPerRun; this.client = new github.GitHub(options.repoToken); @@ -8632,6 +8633,7 @@ class IssueProcessor { removeLabel(issue, label) { return __awaiter(this, void 0, void 0, function* () { core.debug(`Removing label ${label} from issue #${issue.number} - ${issue.title}`); + this.removedLabelIssues.push(issue); this.operationsLeft -= 1; if (this.options.debugOnly) { return; diff --git a/src/IssueProcessor.ts b/src/IssueProcessor.ts index 20f65005..a394c029 100644 --- a/src/IssueProcessor.ts +++ b/src/IssueProcessor.ts @@ -58,6 +58,7 @@ export class IssueProcessor { readonly staleIssues: Issue[] = []; readonly closedIssues: Issue[] = []; + readonly removedLabelIssues: Issue[] = []; constructor( options: IssueProcessorOptions, @@ -326,6 +327,8 @@ export class IssueProcessor { `Removing label ${label} from issue #${issue.number} - ${issue.title}` ); + this.removedLabelIssues.push(issue); + this.operationsLeft -= 1; if (this.options.debugOnly) {