From f71f89033c0562d764b79f3ba733141ef4952e87 Mon Sep 17 00:00:00 2001 From: Ivan Reinoso Date: Fri, 7 Oct 2022 10:18:19 +0200 Subject: [PATCH 1/2] feat: allow daysBeforeStale options to be float --- __tests__/main.spec.ts | 177 +++++++++++++++++++++++++++++++++++++++++ src/main.ts | 20 +++-- 2 files changed, 189 insertions(+), 8 deletions(-) diff --git a/__tests__/main.spec.ts b/__tests__/main.spec.ts index eba2e9dfe..218825471 100644 --- a/__tests__/main.spec.ts +++ b/__tests__/main.spec.ts @@ -1998,6 +1998,84 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss expect(processor.closedIssues).toHaveLength(0); }); +test('processing an issue opened since 1 hour and with the option "daysBeforeIssueStale" at 0.1666666667 (4 hours) will not make it stale', async () => { + expect.assertions(2); + const opts: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 10, + daysBeforeIssueStale: 0.1666666667 + }; + const issueDate = new Date(); + issueDate.setHours(issueDate.getHours() - 1); + const TestIssueList: Issue[] = [ + generateIssue(opts, 1, 'An issue with no label', issueDate.toISOString()) + ]; + const processor = new IssuesProcessorMock( + opts, + async p => (p === 1 ? TestIssueList : []), + async () => [], + async () => new Date().toISOString() + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues).toHaveLength(0); + expect(processor.closedIssues).toHaveLength(0); +}); + +test('processing an issue opened since 4 hours and with the option "daysBeforeIssueStale" at 0.1666666667 (4 hours) will make it stale', async () => { + expect.assertions(2); + const opts: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 10, + daysBeforeIssueStale: 0.1666666667 + }; + const issueDate = new Date(); + issueDate.setHours(issueDate.getHours() - 4); + const TestIssueList: Issue[] = [ + generateIssue(opts, 1, 'An issue with no label', issueDate.toISOString()) + ]; + const processor = new IssuesProcessorMock( + opts, + async p => (p === 1 ? TestIssueList : []), + async () => [], + async () => new Date().toISOString() + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues).toHaveLength(1); + expect(processor.closedIssues).toHaveLength(0); +}); + +test('processing an issue opened since 5 hours and with the option "daysBeforeIssueStale" at 0.1666666667 (4 hours) will make it stale', async () => { + expect.assertions(2); + const opts: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 10, + daysBeforeIssueStale: 0.1666666667 + }; + const issueDate = new Date(); + issueDate.setHours(issueDate.getHours() - 5); + const TestIssueList: Issue[] = [ + generateIssue(opts, 1, 'An issue with no label', issueDate.toISOString()) + ]; + const processor = new IssuesProcessorMock( + opts, + async p => (p === 1 ? TestIssueList : []), + async () => [], + async () => new Date().toISOString() + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues).toHaveLength(1); + expect(processor.closedIssues).toHaveLength(0); +}); + test('processing a pull request opened since 2 days and with the option "daysBeforePrStale" at 3 will not make it stale', async () => { expect.assertions(2); const opts: IIssuesProcessorOptions = { @@ -2097,6 +2175,105 @@ test('processing a pull request opened since 2 days and with the option "daysBef expect(processor.closedIssues).toHaveLength(0); }); +test('processing a pull request opened since 1 hour and with the option "daysBeforePrStale" at 0.1666666667 (4 hours) will not make it stale', async () => { + expect.assertions(2); + const opts: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 10, + daysBeforePrStale: 0.1666666667 + }; + const issueDate = new Date(); + issueDate.setHours(issueDate.getHours() - 1); + const TestIssueList: Issue[] = [ + generateIssue( + opts, + 1, + 'A pull request with no label', + issueDate.toISOString(), + issueDate.toISOString(), + true + ) + ]; + const processor = new IssuesProcessorMock( + opts, + async p => (p === 1 ? TestIssueList : []), + async () => [], + async () => new Date().toISOString() + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues).toHaveLength(0); + expect(processor.closedIssues).toHaveLength(0); +}); + +test('processing a pull request opened since 4 hours and with the option "daysBeforePrStale" at 0.1666666667 (4 hours) will make it stale', async () => { + expect.assertions(2); + const opts: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 10, + daysBeforePrStale: 0.1666666667 + }; + const issueDate = new Date(); + issueDate.setHours(issueDate.getHours() - 4); + const TestIssueList: Issue[] = [ + generateIssue( + opts, + 1, + 'A pull request with no label', + issueDate.toISOString(), + issueDate.toISOString(), + true + ) + ]; + const processor = new IssuesProcessorMock( + opts, + async p => (p === 1 ? TestIssueList : []), + async () => [], + async () => new Date().toISOString() + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues).toHaveLength(1); + expect(processor.closedIssues).toHaveLength(0); +}); + +test('processing a pull request opened since 5 hours and with the option "daysBeforePrStale" at 0.1666666667 (4 hours) will make it stale', async () => { + expect.assertions(2); + const opts: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 10, + daysBeforePrStale: 0.1666666667 + }; + const issueDate = new Date(); + issueDate.setHours(issueDate.getHours() - 5); + const TestIssueList: Issue[] = [ + generateIssue( + opts, + 1, + 'A pull request with no label', + issueDate.toISOString(), + issueDate.toISOString(), + true + ) + ]; + const processor = new IssuesProcessorMock( + opts, + async p => (p === 1 ? TestIssueList : []), + async () => [], + async () => new Date().toISOString() + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues).toHaveLength(1); + expect(processor.closedIssues).toHaveLength(0); +}); + test('processing a previously closed issue with a close label will remove the close label', async () => { expect.assertions(1); const opts: IIssuesProcessorOptions = { diff --git a/src/main.ts b/src/main.ts index 4b7adeab6..1045d6c57 100644 --- a/src/main.ts +++ b/src/main.ts @@ -28,11 +28,11 @@ function _getAndValidateArgs(): IIssuesProcessorOptions { stalePrMessage: core.getInput('stale-pr-message'), closeIssueMessage: core.getInput('close-issue-message'), closePrMessage: core.getInput('close-pr-message'), - daysBeforeStale: parseInt( + daysBeforeStale: parseFloat( core.getInput('days-before-stale', {required: true}) ), - daysBeforeIssueStale: parseInt(core.getInput('days-before-issue-stale')), - daysBeforePrStale: parseInt(core.getInput('days-before-pr-stale')), + daysBeforeIssueStale: parseFloat(core.getInput('days-before-issue-stale')), + daysBeforePrStale: parseFloat(core.getInput('days-before-pr-stale')), daysBeforeClose: parseInt( core.getInput('days-before-close', {required: true}) ), @@ -92,11 +92,15 @@ function _getAndValidateArgs(): IIssuesProcessorOptions { includeOnlyAssigned: core.getInput('include-only-assigned') === 'true' }; - for (const numberInput of [ - 'days-before-stale', - 'days-before-close', - 'operations-per-run' - ]) { + for (const numberInput of ['days-before-stale']) { + if (isNaN(parseFloat(core.getInput(numberInput)))) { + const errorMessage = `Option "${numberInput}" did not parse to a valid float`; + core.setFailed(errorMessage); + throw new Error(errorMessage); + } + } + + for (const numberInput of ['days-before-close', 'operations-per-run']) { if (isNaN(parseInt(core.getInput(numberInput)))) { const errorMessage = `Option "${numberInput}" did not parse to a valid integer`; core.setFailed(errorMessage); From 5c2327a04701d8d9cc1ed7745b989732387ceaa5 Mon Sep 17 00:00:00 2001 From: Ivan Reinoso Date: Fri, 7 Oct 2022 10:20:25 +0200 Subject: [PATCH 2/2] update dist --- dist/index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index b874b3808..f27e127cb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2183,9 +2183,9 @@ function _getAndValidateArgs() { stalePrMessage: core.getInput('stale-pr-message'), closeIssueMessage: core.getInput('close-issue-message'), closePrMessage: core.getInput('close-pr-message'), - daysBeforeStale: parseInt(core.getInput('days-before-stale', { required: true })), - daysBeforeIssueStale: parseInt(core.getInput('days-before-issue-stale')), - daysBeforePrStale: parseInt(core.getInput('days-before-pr-stale')), + daysBeforeStale: parseFloat(core.getInput('days-before-stale', { required: true })), + daysBeforeIssueStale: parseFloat(core.getInput('days-before-issue-stale')), + daysBeforePrStale: parseFloat(core.getInput('days-before-pr-stale')), daysBeforeClose: parseInt(core.getInput('days-before-close', { required: true })), daysBeforeIssueClose: parseInt(core.getInput('days-before-issue-close')), daysBeforePrClose: parseInt(core.getInput('days-before-pr-close')), @@ -2233,11 +2233,14 @@ function _getAndValidateArgs() { closeIssueReason: core.getInput('close-issue-reason'), includeOnlyAssigned: core.getInput('include-only-assigned') === 'true' }; - for (const numberInput of [ - 'days-before-stale', - 'days-before-close', - 'operations-per-run' - ]) { + for (const numberInput of ['days-before-stale']) { + if (isNaN(parseFloat(core.getInput(numberInput)))) { + const errorMessage = `Option "${numberInput}" did not parse to a valid float`; + core.setFailed(errorMessage); + throw new Error(errorMessage); + } + } + for (const numberInput of ['days-before-close', 'operations-per-run']) { if (isNaN(parseInt(core.getInput(numberInput)))) { const errorMessage = `Option "${numberInput}" did not parse to a valid integer`; core.setFailed(errorMessage);