From efacf1122ef66afcd231dc4172fed7ea067ca8ba Mon Sep 17 00:00:00 2001 From: TESTELIN Geoffrey Date: Sat, 23 Jan 2021 12:49:03 +0100 Subject: [PATCH] refactor: move and rename the interfaces/classes closes #272 --- __tests__/main.test.ts | 189 +++++++++--------- dist/index.js | 96 ++++----- src/classes/issue.spec.ts | 9 +- src/classes/issue.ts | 9 +- .../issues-processor.ts} | 109 +++------- src/classes/milestones.spec.ts | 4 +- src/classes/milestones.ts | 6 +- src/functions/is-labeled.ts | 4 +- src/interfaces/comment.ts | 5 + src/interfaces/issue-event.ts | 7 + src/interfaces/issue.ts | 4 +- src/interfaces/issues-processor-options.ts | 33 +++ src/interfaces/label.ts | 3 + src/interfaces/pull-request.ts | 6 + src/interfaces/user.ts | 4 + src/main.ts | 9 +- 16 files changed, 252 insertions(+), 245 deletions(-) rename src/{IssueProcessor.ts => classes/issues-processor.ts} (88%) create mode 100644 src/interfaces/comment.ts create mode 100644 src/interfaces/issue-event.ts create mode 100644 src/interfaces/issues-processor-options.ts create mode 100644 src/interfaces/label.ts create mode 100644 src/interfaces/pull-request.ts create mode 100644 src/interfaces/user.ts diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index aad95e563..3ddfc1962 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -1,11 +1,12 @@ import * as github from '@actions/github'; import {Issue} from '../src/classes/issue'; -import {IssueProcessor, IssueProcessorOptions} from '../src/IssueProcessor'; +import {IssuesProcessor} from '../src/classes/issues-processor'; +import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options'; import {IsoDateString} from '../src/types/iso-date-string'; function generateIssue( - options: IssueProcessorOptions, + options: IIssuesProcessorOptions, id: number, title: string, updatedAt: IsoDateString, @@ -33,7 +34,7 @@ function generateIssue( }); } -const DefaultProcessorOptions: IssueProcessorOptions = Object.freeze({ +const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({ repoToken: 'none', staleIssueMessage: 'This issue is stale', stalePrMessage: 'This PR is stale', @@ -66,7 +67,7 @@ const DefaultProcessorOptions: IssueProcessorOptions = Object.freeze({ }); test('empty issue list results in 1 operation', async () => { - const processor = new IssueProcessor( + const processor = new IssuesProcessor( DefaultProcessorOptions, async () => 'abot', async () => [], @@ -82,14 +83,14 @@ test('empty issue list results in 1 operation', async () => { }); test('processing an issue with no label will make it stale and close it, if it is old enough only if days-before-close is set to 0', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 0 }; const TestIssueList: Issue[] = [ generateIssue(opts, 1, 'An issue with no label', '2020-01-01T17:00:00Z') ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -107,7 +108,7 @@ test('processing an issue with no label will make it stale and close it, if it i test('processing an issue with no label and a start date as ECMAScript epoch in seconds being before the issue creation date will not make it stale nor close it when it is old enough and days-before-close is set to 0', async () => { expect.assertions(2); const january2000 = 946681200000; - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 0, startDate: january2000.toString() @@ -121,7 +122,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in '2020-01-01T17:00:00Z' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -139,7 +140,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in test('processing an issue with no label and a start date as ECMAScript epoch in seconds being after the issue creation date will not make it stale nor close it when it is old enough and days-before-close is set to 0', async () => { expect.assertions(2); const january2021 = 1609455600000; - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 0, startDate: january2021.toString() @@ -153,7 +154,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in '2020-01-01T17:00:00Z' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -171,7 +172,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in test('processing an issue with no label and a start date as ECMAScript epoch in milliseconds being before the issue creation date will not make it stale nor close it when it is old enough and days-before-close is set to 0', async () => { expect.assertions(2); const january2000 = 946681200000000; - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 0, startDate: january2000.toString() @@ -185,7 +186,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in '2020-01-01T17:00:00Z' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -203,7 +204,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in test('processing an issue with no label and a start date as ECMAScript epoch in milliseconds being after the issue creation date will not make it stale nor close it when it is old enough and days-before-close is set to 0', async () => { expect.assertions(2); const january2021 = 1609455600000; - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 0, startDate: january2021.toString() @@ -217,7 +218,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in '2020-01-01T17:00:00Z' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -235,7 +236,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in test('processing an issue with no label and a start date as ISO 8601 being before the issue creation date will make it stale and close it when it is old enough and days-before-close is set to 0', async () => { expect.assertions(2); const january2000 = '2000-01-01T00:00:00Z'; - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 0, startDate: january2000.toString() @@ -249,7 +250,7 @@ test('processing an issue with no label and a start date as ISO 8601 being befor '2020-01-01T17:00:00Z' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -267,7 +268,7 @@ test('processing an issue with no label and a start date as ISO 8601 being befor test('processing an issue with no label and a start date as ISO 8601 being after the issue creation date will not make it stale nor close it when it is old enough and days-before-close is set to 0', async () => { expect.assertions(2); const january2021 = '2021-01-01T00:00:00Z'; - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 0, startDate: january2021.toString() @@ -281,7 +282,7 @@ test('processing an issue with no label and a start date as ISO 8601 being after '2020-01-01T17:00:00Z' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -299,7 +300,7 @@ test('processing an issue with no label and a start date as ISO 8601 being after test('processing an issue with no label and a start date as RFC 2822 being before the issue creation date will make it stale and close it when it is old enough and days-before-close is set to 0', async () => { expect.assertions(2); const january2000 = 'January 1, 2000 00:00:00'; - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 0, startDate: january2000.toString() @@ -313,7 +314,7 @@ test('processing an issue with no label and a start date as RFC 2822 being befor '2020-01-01T17:00:00Z' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -331,7 +332,7 @@ test('processing an issue with no label and a start date as RFC 2822 being befor test('processing an issue with no label and a start date as RFC 2822 being after the issue creation date will not make it stale nor close it when it is old enough and days-before-close is set to 0', async () => { expect.assertions(2); const january2021 = 'January 1, 2021 00:00:00'; - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 0, startDate: january2021.toString() @@ -345,7 +346,7 @@ test('processing an issue with no label and a start date as RFC 2822 being after '2020-01-01T17:00:00Z' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -361,7 +362,7 @@ test('processing an issue with no label and a start date as RFC 2822 being after }); test('processing an issue with no label will make it stale and close it, if it is old enough only if days-before-close is set to > 0 and days-before-issue-close is set to 0', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 1, daysBeforeIssueClose: 0 @@ -369,7 +370,7 @@ test('processing an issue with no label will make it stale and close it, if it i const TestIssueList: Issue[] = [ generateIssue(opts, 1, 'An issue with no label', '2020-01-01T17:00:00Z') ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -386,7 +387,7 @@ test('processing an issue with no label will make it stale and close it, if it i }); test('processing an issue with no label will make it stale and not close it, if it is old enough only if days-before-close is set to > 0 and days-before-issue-close is set to > 0', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 1, daysBeforeIssueClose: 1 @@ -394,7 +395,7 @@ test('processing an issue with no label will make it stale and not close it, if const TestIssueList: Issue[] = [ generateIssue(opts, 1, 'An issue with no label', '2020-01-01T17:00:00Z') ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -410,14 +411,14 @@ test('processing an issue with no label will make it stale and not close it, if }); test('processing an issue with no label will make it stale and not close it if days-before-close is set to > 0', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 15 }; const TestIssueList: Issue[] = [ generateIssue(opts, 1, 'An issue with no label', '2020-01-01T17:00:00Z') ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -433,7 +434,7 @@ test('processing an issue with no label will make it stale and not close it if d }); test('processing an issue with no label will make it stale and not close it if days-before-close is set to -1 and days-before-issue-close is set to > 0', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: -1, daysBeforeIssueClose: 15 @@ -441,7 +442,7 @@ test('processing an issue with no label will make it stale and not close it if d const TestIssueList: Issue[] = [ generateIssue(opts, 1, 'An issue with no label', '2020-01-01T17:00:00Z') ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -457,7 +458,7 @@ test('processing an issue with no label will make it stale and not close it if d }); test('processing an issue with no label will not make it stale if days-before-stale is set to -1', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, staleIssueMessage: '', daysBeforeStale: -1 @@ -465,7 +466,7 @@ test('processing an issue with no label will not make it stale if days-before-st const TestIssueList: Issue[] = [ generateIssue(opts, 1, 'An issue with no label', '2020-01-01T17:00:00Z') ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -481,7 +482,7 @@ test('processing an issue with no label will not make it stale if days-before-st }); test('processing an issue with no label will not make it stale if days-before-stale and days-before-issue-stale are set to -1', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, staleIssueMessage: '', daysBeforeStale: -1, @@ -490,7 +491,7 @@ test('processing an issue with no label will not make it stale if days-before-st const TestIssueList: Issue[] = [ generateIssue(opts, 1, 'An issue with no label', '2020-01-01T17:00:00Z') ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -518,7 +519,7 @@ test('processing an issue with no label will make it stale but not close it', as issueDate.toDateString() ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( DefaultProcessorOptions, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -534,7 +535,7 @@ test('processing an issue with no label will make it stale but not close it', as }); test('processing a stale issue will close it', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 30 }; @@ -549,7 +550,7 @@ test('processing a stale issue will close it', async () => { ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -565,7 +566,7 @@ test('processing a stale issue will close it', async () => { }); test('processing a stale issue containing a space in the label will close it', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, staleIssueLabel: 'state: stale' }; @@ -580,7 +581,7 @@ test('processing a stale issue containing a space in the label will close it', a ['state: stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -596,7 +597,7 @@ test('processing a stale issue containing a space in the label will close it', a }); test('processing a stale issue containing a slash in the label will close it', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, staleIssueLabel: 'lifecycle/stale' }; @@ -611,7 +612,7 @@ test('processing a stale issue containing a slash in the label will close it', a ['lifecycle/stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -627,7 +628,7 @@ test('processing a stale issue containing a slash in the label will close it', a }); test('processing a stale issue will close it when days-before-issue-stale override days-before-stale', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 30, daysBeforeIssueStale: 30 @@ -643,7 +644,7 @@ test('processing a stale issue will close it when days-before-issue-stale overri ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -659,7 +660,7 @@ test('processing a stale issue will close it when days-before-issue-stale overri }); test('processing a stale PR will close it', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 30 }; @@ -674,7 +675,7 @@ test('processing a stale PR will close it', async () => { ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -690,7 +691,7 @@ test('processing a stale PR will close it', async () => { }); test('processing a stale PR will close it when days-before-pr-stale override days-before-stale', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, daysBeforeClose: 30, daysBeforePrClose: 30 @@ -706,7 +707,7 @@ test('processing a stale PR will close it when days-before-pr-stale override day ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -738,7 +739,7 @@ test('processing a stale issue will close it even if configured not to mark as s ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -771,7 +772,7 @@ test('processing a stale issue will close it even if configured not to mark as s ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -803,7 +804,7 @@ test('processing a stale PR will close it even if configured not to mark as stal ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -836,7 +837,7 @@ test('processing a stale PR will close it even if configured not to mark as stal ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -864,7 +865,7 @@ test('closed issues will not be marked stale', async () => { true ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( DefaultProcessorOptions, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -891,7 +892,7 @@ test('stale closed issues will not be closed', async () => { true ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( DefaultProcessorOptions, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -919,7 +920,7 @@ test('closed prs will not be marked stale', async () => { true ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( DefaultProcessorOptions, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -947,7 +948,7 @@ test('stale closed prs will not be closed', async () => { true ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( DefaultProcessorOptions, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -976,7 +977,7 @@ test('locked issues will not be marked stale', async () => { true ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( DefaultProcessorOptions, async () => 'abot', async p => (p == 1 ? TestIssueList : []) @@ -1003,7 +1004,7 @@ test('stale locked issues will not be closed', async () => { true ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( DefaultProcessorOptions, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1032,7 +1033,7 @@ test('locked prs will not be marked stale', async () => { true ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( DefaultProcessorOptions, async () => 'abot', async p => (p == 1 ? TestIssueList : []) @@ -1059,7 +1060,7 @@ test('stale locked prs will not be closed', async () => { true ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( DefaultProcessorOptions, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1089,7 +1090,7 @@ test('exempt issue labels will not be marked stale', async () => { ['Exempt'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1119,7 +1120,7 @@ test('exempt issue labels will not be marked stale (multi issue label with space ['Cool'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1148,7 +1149,7 @@ test('exempt issue labels will not be marked stale (multi issue label)', async ( ['Cool'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1195,7 +1196,7 @@ test('exempt pr labels will not be marked stale', async () => { false ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1224,7 +1225,7 @@ test('exempt issue labels will not be marked stale and will remove the existing ['Exempt', 'Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1279,7 +1280,7 @@ test('stale issues should not be closed if days is set to -1', async () => { ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1308,7 +1309,7 @@ test('stale label should be removed if a comment was added to a stale issue', as ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1346,7 +1347,7 @@ test('stale label should not be removed if a comment was added by the bot (and t ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1370,7 +1371,7 @@ test('stale label should not be removed if a comment was added by the bot (and t }); test('stale label containing a space should be removed if a comment was added to a stale issue', async () => { - const opts: IssueProcessorOptions = { + const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, removeStaleWhenUpdated: true, staleIssueLabel: 'stat: stale' @@ -1386,7 +1387,7 @@ test('stale label containing a space should be removed if a comment was added to ['stat: stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1418,7 +1419,7 @@ test('stale issues should not be closed until after the closed number of days', false ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1451,7 +1452,7 @@ test('stale issues should be closed if the closed nubmer of days (additive) is a ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1483,7 +1484,7 @@ test('stale issues should not be closed until after the closed number of days (l false ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1516,7 +1517,7 @@ test('skips stale message on issues when skip-stale-issue-message is set', async false ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1561,7 +1562,7 @@ test('skips stale message on prs when skip-stale-pr-message is set', async () => true ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1607,7 +1608,7 @@ test('not providing state takes precedence over skipStaleIssueMessage', async () false ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1641,7 +1642,7 @@ test('not providing stalePrMessage takes precedence over skipStalePrMessage', as true ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1671,7 +1672,7 @@ test('git branch is deleted when option is enabled', async () => { ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1701,7 +1702,7 @@ test('git branch is not deleted when issue is not pull request', async () => { ['Stale'] ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1733,7 +1734,7 @@ test('an issue without a milestone will be marked as stale', async () => { '' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( DefaultProcessorOptions, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1767,7 +1768,7 @@ test('an issue without an exempted milestone will be marked as stale', async () 'Milestone' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1801,7 +1802,7 @@ test('an issue with an exempted milestone will not be marked as stale', async () 'Milestone1' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1835,7 +1836,7 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil 'Milestone2' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1869,7 +1870,7 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil 'Milestone2' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1904,7 +1905,7 @@ test('an issue with an exempted milestone but without an exempted issue mileston 'Milestone1' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1939,7 +1940,7 @@ test('an issue with an exempted milestone but with another exempted issue milest 'Milestone1' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -1974,7 +1975,7 @@ test('an issue with an exempted milestone and with an exempted issue milestone w 'Milestone1' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -2006,7 +2007,7 @@ test('a PR without a milestone will be marked as stale', async () => { '' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( DefaultProcessorOptions, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -2040,7 +2041,7 @@ test('a PR without an exempted milestone will be marked as stale', async () => { 'Milestone' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -2074,7 +2075,7 @@ test('a PR with an exempted milestone will not be marked as stale', async () => 'Milestone1' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -2108,7 +2109,7 @@ test('a PR with an exempted milestone will not be marked as stale (multi milesto 'Milestone2' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -2142,7 +2143,7 @@ test('a PR with an exempted milestone will not be marked as stale (multi milesto 'Milestone2' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -2177,7 +2178,7 @@ test('a PR with an exempted milestone but without an exempted issue milestone wi 'Milestone1' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -2212,7 +2213,7 @@ test('a PR with an exempted milestone but with another exempted issue milestone 'Milestone1' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), @@ -2247,7 +2248,7 @@ test('a PR with an exempted milestone and with an exempted issue milestone will 'Milestone1' ) ]; - const processor = new IssueProcessor( + const processor = new IssuesProcessor( opts, async () => 'abot', async p => (p == 1 ? TestIssueList : []), diff --git a/dist/index.js b/dist/index.js index 341822c75..3c13781df 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2,7 +2,43 @@ module.exports = /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ 4407: +/***/ 4783: +/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Issue = void 0; +const is_labeled_1 = __nccwpck_require__(6792); +const is_pull_request_1 = __nccwpck_require__(5400); +class Issue { + constructor(options, issue) { + this._options = options; + this.title = issue.title; + this.number = issue.number; + this.created_at = issue.created_at; + this.updated_at = issue.updated_at; + this.labels = issue.labels; + this.pull_request = issue.pull_request; + this.state = issue.state; + this.locked = issue.locked; + this.milestone = issue.milestone; + this.isPullRequest = is_pull_request_1.isPullRequest(this); + this.staleLabel = this._getStaleLabel(); + this.isStale = is_labeled_1.isLabeled(this, this.staleLabel); + } + _getStaleLabel() { + return this.isPullRequest + ? this._options.stalePrLabel + : this._options.staleIssueLabel; + } +} +exports.Issue = Issue; + + +/***/ }), + +/***/ 3292: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; @@ -17,12 +53,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.IssueProcessor = void 0; +exports.IssuesProcessor = void 0; const github_1 = __nccwpck_require__(5438); -const issue_1 = __nccwpck_require__(4783); -const issue_logger_1 = __nccwpck_require__(2984); -const logger_1 = __nccwpck_require__(6212); -const milestones_1 = __nccwpck_require__(4601); const get_humanized_date_1 = __nccwpck_require__(965); const is_date_more_recent_than_1 = __nccwpck_require__(1473); const is_valid_date_1 = __nccwpck_require__(891); @@ -31,10 +63,14 @@ const is_labeled_1 = __nccwpck_require__(6792); const is_pull_request_1 = __nccwpck_require__(5400); const should_mark_when_stale_1 = __nccwpck_require__(2461); const words_to_list_1 = __nccwpck_require__(1883); +const issue_1 = __nccwpck_require__(4783); +const issue_logger_1 = __nccwpck_require__(2984); +const logger_1 = __nccwpck_require__(6212); +const milestones_1 = __nccwpck_require__(4601); /*** * Handle processing of issues for staleness/closure. */ -class IssueProcessor { +class IssuesProcessor { constructor(options, getActor, getIssues, listIssueComments, getLabelCreationDate) { this._logger = new logger_1.Logger(); this._operationsLeft = 0; @@ -157,7 +193,7 @@ class IssueProcessor { continue; // don't process exempt milestones } // should this issue be marked stale? - const shouldBeStale = !IssueProcessor._updatedSince(issue.updated_at, this.options.daysBeforeStale); + const shouldBeStale = !IssuesProcessor._updatedSince(issue.updated_at, this.options.daysBeforeStale); // determine if this issue needs to be marked stale first if (!issue.isStale && shouldBeStale && shouldMarkAsStale) { issueLogger.info(`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`); @@ -196,7 +232,7 @@ class IssueProcessor { else { issueLogger.info(`Days before issue close: ${daysBeforeClose}`); } - const issueHasUpdate = IssueProcessor._updatedSince(issue.updated_at, daysBeforeClose); + const issueHasUpdate = IssuesProcessor._updatedSince(issue.updated_at, daysBeforeClose); issueLogger.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`); // should we un-stale this issue? if (this.options.removeStaleWhenUpdated && issueHasComments) { @@ -500,43 +536,7 @@ class IssueProcessor { }); } } -exports.IssueProcessor = IssueProcessor; - - -/***/ }), - -/***/ 4783: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { - -"use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Issue = void 0; -const is_labeled_1 = __nccwpck_require__(6792); -const is_pull_request_1 = __nccwpck_require__(5400); -class Issue { - constructor(options, issue) { - this._options = options; - this.title = issue.title; - this.number = issue.number; - this.created_at = issue.created_at; - this.updated_at = issue.updated_at; - this.labels = issue.labels; - this.pull_request = issue.pull_request; - this.state = issue.state; - this.locked = issue.locked; - this.milestone = issue.milestone; - this.isPullRequest = is_pull_request_1.isPullRequest(this); - this.staleLabel = this._getStaleLabel(); - this.isStale = is_labeled_1.isLabeled(this, this.staleLabel); - } - _getStaleLabel() { - return this.isPullRequest - ? this._options.stalePrLabel - : this._options.staleIssueLabel; - } -} -exports.Issue = Issue; +exports.IssuesProcessor = IssuesProcessor; /***/ }), @@ -921,12 +921,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", ({ value: true })); const core = __importStar(__nccwpck_require__(2186)); const is_valid_date_1 = __nccwpck_require__(891); -const IssueProcessor_1 = __nccwpck_require__(4407); +const issues_processor_1 = __nccwpck_require__(3292); function run() { return __awaiter(this, void 0, void 0, function* () { try { const args = getAndValidateArgs(); - const processor = new IssueProcessor_1.IssueProcessor(args); + const processor = new issues_processor_1.IssuesProcessor(args); yield processor.processIssues(); } catch (error) { diff --git a/src/classes/issue.spec.ts b/src/classes/issue.spec.ts index 0b395cf86..949211d57 100644 --- a/src/classes/issue.spec.ts +++ b/src/classes/issue.spec.ts @@ -1,11 +1,12 @@ import {IIssue} from '../interfaces/issue'; +import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; +import {ILabel} from '../interfaces/label'; import {IMilestone} from '../interfaces/milestone'; -import {IssueProcessorOptions, Label} from '../IssueProcessor'; import {Issue} from './issue'; describe('Issue', (): void => { let issue: Issue; - let optionsInterface: IssueProcessorOptions; + let optionsInterface: IIssuesProcessorOptions; let issueInterface: IIssue; beforeEach((): void => { @@ -91,7 +92,7 @@ describe('Issue', (): void => { expect(issue.labels).toStrictEqual([ { name: 'dummy-name' - } as Label + } as ILabel ]); }); @@ -193,7 +194,7 @@ describe('Issue', (): void => { issueInterface.labels = [ { name: 'dummy-stale-issue-label' - } as Label + } as ILabel ]; issue = new Issue(optionsInterface, issueInterface); }); diff --git a/src/classes/issue.ts b/src/classes/issue.ts index 31a40c7c7..af6f825c1 100644 --- a/src/classes/issue.ts +++ b/src/classes/issue.ts @@ -1,17 +1,18 @@ import {isLabeled} from '../functions/is-labeled'; import {isPullRequest} from '../functions/is-pull-request'; import {IIssue} from '../interfaces/issue'; +import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; +import {ILabel} from '../interfaces/label'; import {IMilestone} from '../interfaces/milestone'; -import {IssueProcessorOptions, Label} from '../IssueProcessor'; import {IsoDateString} from '../types/iso-date-string'; export class Issue implements IIssue { - private readonly _options: IssueProcessorOptions; + private readonly _options: IIssuesProcessorOptions; readonly title: string; readonly number: number; created_at: IsoDateString; updated_at: IsoDateString; - readonly labels: Label[]; + readonly labels: ILabel[]; readonly pull_request: Object | null | undefined; readonly state: string; readonly locked: boolean; @@ -21,7 +22,7 @@ export class Issue implements IIssue { isStale: boolean; constructor( - options: Readonly, + options: Readonly, issue: Readonly ) { this._options = options; diff --git a/src/IssueProcessor.ts b/src/classes/issues-processor.ts similarity index 88% rename from src/IssueProcessor.ts rename to src/classes/issues-processor.ts index f1c2d93db..b17315838 100644 --- a/src/IssueProcessor.ts +++ b/src/classes/issues-processor.ts @@ -1,84 +1,29 @@ import {context, getOctokit} from '@actions/github'; import {GitHub} from '@actions/github/lib/utils'; import {GetResponseTypeFromEndpointMethod} from '@octokit/types'; -import {Issue} from './classes/issue'; -import {IssueLogger} from './classes/loggers/issue-logger'; -import {Logger} from './classes/loggers/logger'; -import {Milestones} from './classes/milestones'; -import {IssueType} from './enums/issue-type'; -import {getHumanizedDate} from './functions/dates/get-humanized-date'; -import {isDateMoreRecentThan} from './functions/dates/is-date-more-recent-than'; -import {isValidDate} from './functions/dates/is-valid-date'; -import {getIssueType} from './functions/get-issue-type'; -import {isLabeled} from './functions/is-labeled'; -import {isPullRequest} from './functions/is-pull-request'; -import {shouldMarkWhenStale} from './functions/should-mark-when-stale'; -import {IsoOrRfcDateString} from './types/iso-or-rfc-date-string'; -import {wordsToList} from './functions/words-to-list'; -import {IIssue} from './interfaces/issue'; - -export interface PullRequest { - number: number; - head: { - ref: string; - }; -} - -export interface User { - type: string; - login: string; -} - -export interface Comment { - user: User; -} - -export interface IssueEvent { - created_at: string; - event: string; - label: Label; -} - -export interface Label { - name: string; -} - -export interface IssueProcessorOptions { - repoToken: string; - staleIssueMessage: string; - stalePrMessage: string; - closeIssueMessage: string; - closePrMessage: string; - daysBeforeStale: number; - daysBeforeIssueStale: number; // Could be NaN - daysBeforePrStale: number; // Could be NaN - daysBeforeClose: number; - daysBeforeIssueClose: number; // Could be NaN - daysBeforePrClose: number; // Could be NaN - staleIssueLabel: string; - closeIssueLabel: string; - exemptIssueLabels: string; - stalePrLabel: string; - closePrLabel: string; - exemptPrLabels: string; - onlyLabels: string; - operationsPerRun: number; - removeStaleWhenUpdated: boolean; - debugOnly: boolean; - ascending: boolean; - skipStaleIssueMessage: boolean; - skipStalePrMessage: boolean; - deleteBranch: boolean; - startDate: IsoOrRfcDateString | undefined; // Should be ISO 8601 or RFC 2822 - exemptMilestones: string; - exemptIssueMilestones: string; - exemptPrMilestones: string; -} +import {IssueType} from '../enums/issue-type'; +import {getHumanizedDate} from '../functions/dates/get-humanized-date'; +import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than'; +import {isValidDate} from '../functions/dates/is-valid-date'; +import {getIssueType} from '../functions/get-issue-type'; +import {isLabeled} from '../functions/is-labeled'; +import {isPullRequest} from '../functions/is-pull-request'; +import {shouldMarkWhenStale} from '../functions/should-mark-when-stale'; +import {wordsToList} from '../functions/words-to-list'; +import {IComment} from '../interfaces/comment'; +import {IIssue} from '../interfaces/issue'; +import {IIssueEvent} from '../interfaces/issue-event'; +import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; +import {IPullRequest} from '../interfaces/pull-request'; +import {Issue} from './issue'; +import {IssueLogger} from './loggers/issue-logger'; +import {Logger} from './loggers/logger'; +import {Milestones} from './milestones'; /*** * Handle processing of issues for staleness/closure. */ -export class IssueProcessor { +export class IssuesProcessor { private static _updatedSince(timestamp: string, num_days: number): boolean { const daysInMillis = 1000 * 60 * 60 * 24 * num_days; const millisSinceLastUpdated = @@ -90,20 +35,20 @@ export class IssueProcessor { private readonly _logger: Logger = new Logger(); private _operationsLeft = 0; readonly client: InstanceType; - readonly options: IssueProcessorOptions; + readonly options: IIssuesProcessorOptions; readonly staleIssues: Issue[] = []; readonly closedIssues: Issue[] = []; readonly deletedBranchIssues: Issue[] = []; readonly removedLabelIssues: Issue[] = []; constructor( - options: IssueProcessorOptions, + options: IIssuesProcessorOptions, getActor?: () => Promise, getIssues?: (page: number) => Promise, listIssueComments?: ( issueNumber: number, sinceDate: string - ) => Promise, + ) => Promise, getLabelCreationDate?: ( issue: Issue, label: string @@ -271,7 +216,7 @@ export class IssueProcessor { } // should this issue be marked stale? - const shouldBeStale = !IssueProcessor._updatedSince( + const shouldBeStale = !IssuesProcessor._updatedSince( issue.updated_at, this.options.daysBeforeStale ); @@ -346,7 +291,7 @@ export class IssueProcessor { issueLogger.info(`Days before issue close: ${daysBeforeClose}`); } - const issueHasUpdate: boolean = IssueProcessor._updatedSince( + const issueHasUpdate: boolean = IssuesProcessor._updatedSince( issue.updated_at, daysBeforeClose ); @@ -419,7 +364,7 @@ export class IssueProcessor { private async _listIssueComments( issueNumber: number, sinceDate: string - ): Promise { + ): Promise { // find any comments since date on the given issue try { const comments = await this.client.issues.listComments({ @@ -582,7 +527,7 @@ export class IssueProcessor { private async _getPullRequest( issue: Issue - ): Promise { + ): Promise { const issueLogger: IssueLogger = new IssueLogger(issue); this._operationsLeft -= 1; @@ -688,7 +633,7 @@ export class IssueProcessor { issue_number: issue.number }); - const events: IssueEvent[] = await this.client.paginate(options); + const events: IIssueEvent[] = await this.client.paginate(options); const reversedEvents = events.reverse(); const staleLabeledEvent = reversedEvents.find( diff --git a/src/classes/milestones.spec.ts b/src/classes/milestones.spec.ts index 032c1610e..4703a7f70 100644 --- a/src/classes/milestones.spec.ts +++ b/src/classes/milestones.spec.ts @@ -1,11 +1,11 @@ import {IIssue} from '../interfaces/issue'; -import {IssueProcessorOptions} from '../IssueProcessor'; +import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; import {Issue} from './issue'; import {Milestones} from './milestones'; describe('Milestones', (): void => { let milestones: Milestones; - let optionsInterface: IssueProcessorOptions; + let optionsInterface: IIssuesProcessorOptions; let issue: Issue; let issueInterface: IIssue; diff --git a/src/classes/milestones.ts b/src/classes/milestones.ts index 99b2cce65..b208c85f5 100644 --- a/src/classes/milestones.ts +++ b/src/classes/milestones.ts @@ -1,6 +1,6 @@ import deburr from 'lodash.deburr'; import {wordsToList} from '../functions/words-to-list'; -import {IssueProcessorOptions} from '../IssueProcessor'; +import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; import {Issue} from './issue'; type CleanMilestone = string; @@ -10,10 +10,10 @@ export class Milestones { return deburr(label.toLowerCase()); } - private readonly _options: IssueProcessorOptions; + private readonly _options: IIssuesProcessorOptions; private readonly _issue: Issue; - constructor(options: Readonly, issue: Issue) { + constructor(options: Readonly, issue: Issue) { this._options = options; this._issue = issue; } diff --git a/src/functions/is-labeled.ts b/src/functions/is-labeled.ts index 791cd0a82..890de3ade 100644 --- a/src/functions/is-labeled.ts +++ b/src/functions/is-labeled.ts @@ -1,6 +1,6 @@ import deburr from 'lodash.deburr'; import {Issue} from '../classes/issue'; -import {Label} from '../IssueProcessor'; +import {ILabel} from '../interfaces/label'; import {CleanLabel} from '../types/clean-label'; /** @@ -16,7 +16,7 @@ export function isLabeled( issue: Readonly, label: Readonly ): boolean { - return !!issue.labels.find((issueLabel: Readonly