From ae2c5c5308670b5b2cd25345ea6290186b8ee062 Mon Sep 17 00:00:00 2001 From: "James M. Greene" Date: Mon, 27 Apr 2020 06:53:58 -0500 Subject: [PATCH] Prevent processing of locked/closed issues/PRs (#52) Fixes #50 Fixes #51 --- __tests__/main.test.ts | 136 ++++++++++++++++++++++++++++++++++++++++- src/IssueProcessor.ts | 12 ++++ 2 files changed, 146 insertions(+), 2 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 56ec6f21..7efd4f92 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -14,7 +14,9 @@ function generateIssue( title: string, updatedAt: string, isPullRequest: boolean = false, - labels: string[] = [] + labels: string[] = [], + isClosed: boolean = false, + isLocked: boolean = false ): Issue { return { number: id, @@ -23,7 +25,9 @@ function generateIssue( }), title: title, updated_at: updatedAt, - pull_request: isPullRequest ? {} : null + pull_request: isPullRequest ? {} : null, + state: isClosed ? 'closed' : 'open', + locked: isLocked }; } @@ -100,6 +104,134 @@ test('processing a stale PR will close it', async () => { expect(processor.closedIssues.length).toEqual(1); }); +test('closed issues will not be marked stale', async () => { + const TestIssueList: Issue[] = [ + generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [], true) + ]; + + const processor = new IssueProcessor(DefaultProcessorOptions, async p => + p == 1 ? TestIssueList : [] + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues.length).toEqual(0); + expect(processor.closedIssues.length).toEqual(0); +}); + +test('stale closed issues will not be closed', async () => { + const TestIssueList: Issue[] = [ + generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Stale'], true) + ]; + + const processor = new IssueProcessor(DefaultProcessorOptions, async p => + p == 1 ? TestIssueList : [] + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues.length).toEqual(0); + expect(processor.closedIssues.length).toEqual(0); +}); + +test('closed prs will not be marked stale', async () => { + const TestIssueList: Issue[] = [ + generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, [], true) + ]; + + const processor = new IssueProcessor(DefaultProcessorOptions, async p => + p == 1 ? TestIssueList : [] + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues.length).toEqual(0); + expect(processor.closedIssues.length).toEqual(0); +}); + +test('stale closed prs will not be closed', async () => { + const TestIssueList: Issue[] = [ + generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, ['Stale'], true) + ]; + + const processor = new IssueProcessor(DefaultProcessorOptions, async p => + p == 1 ? TestIssueList : [] + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues.length).toEqual(0); + expect(processor.closedIssues.length).toEqual(0); +}); + +test('locked issues will not be marked stale', async () => { + const TestIssueList: Issue[] = [ + generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [], false, true) + ]; + + const processor = new IssueProcessor(DefaultProcessorOptions, async p => + p == 1 ? TestIssueList : [] + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues.length).toEqual(0); + expect(processor.closedIssues.length).toEqual(0); +}); + +test('stale locked issues will not be closed', async () => { + const TestIssueList: Issue[] = [ + generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Stale'], false, true) + ]; + + const processor = new IssueProcessor(DefaultProcessorOptions, async p => + p == 1 ? TestIssueList : [] + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues.length).toEqual(0); + expect(processor.closedIssues.length).toEqual(0); +}); + +test('locked prs will not be marked stale', async () => { + const TestIssueList: Issue[] = [ + generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, [], false, true) + ]; + + const processor = new IssueProcessor(DefaultProcessorOptions, async p => + p == 1 ? TestIssueList : [] + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues.length).toEqual(0); + expect(processor.closedIssues.length).toEqual(0); +}); + +test('stale locked prs will not be closed', async () => { + const TestIssueList: Issue[] = [ + generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, ['Stale'], false, true) + ]; + + const processor = new IssueProcessor(DefaultProcessorOptions, async p => + p == 1 ? TestIssueList : [] + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues.length).toEqual(0); + expect(processor.closedIssues.length).toEqual(0); +}); + test('exempt issue labels will not be marked stale', async () => { const TestIssueList: Issue[] = [ generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [ diff --git a/src/IssueProcessor.ts b/src/IssueProcessor.ts index e6406ee4..b911e098 100644 --- a/src/IssueProcessor.ts +++ b/src/IssueProcessor.ts @@ -10,6 +10,8 @@ export interface Issue { updated_at: string; labels: Label[]; pull_request: any; + state: string; + locked: boolean; } export interface Label { @@ -100,6 +102,16 @@ export class IssueProcessor { continue; } + if (issue.state === 'closed') { + core.debug(`Skipping ${issueType} because it is closed`); + continue; // don't process closed issues + } + + if (issue.locked) { + core.debug(`Skipping ${issueType} because it is locked`); + continue; // don't process locked issues + } + if ( exemptLabels.some((exemptLabel: string) => IssueProcessor.isLabeled(issue, exemptLabel)