From 079c368275a691df185be93ab3890ec9f9b97e20 Mon Sep 17 00:00:00 2001 From: Ross Brodbeck Date: Thu, 4 Feb 2021 12:23:06 -0500 Subject: [PATCH 1/4] Add code owners for tracking --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 000000000..992d27f09 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @actions/actions-runtime From 7164109781d8031584628890c81f344423868a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 5 Feb 2021 12:52:44 +0100 Subject: [PATCH 2/4] Fixed should be stale condition (#304) * Fixed should be stale condition When different stale period is used for issues and pull requests, this code uses wrong one. This was probably missed in https://github.com/actions/stale/pull/224 Fixes #299 * Add tests for #299 Co-authored-by: Geoffrey Testelin --- __tests__/main.test.ts | 198 +++++++++++++++++++++++++++++++++++++++++ src/IssueProcessor.ts | 2 +- 2 files changed, 199 insertions(+), 1 deletion(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index aad95e563..6fea323a2 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -2262,3 +2262,201 @@ test('a PR with an exempted milestone and with an exempted issue milestone will expect(processor.closedIssues.length).toStrictEqual(0); expect(processor.removedLabelIssues.length).toStrictEqual(0); }); + +test('processing an issue opened since 2 days and with the option "daysBeforeIssueStale" at 3 will not make it stale', async () => { + expect.assertions(2); + const opts: IssueProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 10, + daysBeforeIssueStale: 3 + }; + let issueDate = new Date(); + issueDate.setDate(issueDate.getDate() - 2); + const TestIssueList: Issue[] = [ + generateIssue( + opts, + 1, + 'An issue with no label', + issueDate.toDateString(), + ) + ]; + const processor = new IssueProcessor( + opts, + async () => 'abot', + 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(0); + expect(processor.closedIssues.length).toEqual(0); +}); + +test('processing an issue opened since 2 days and with the option "daysBeforeIssueStale" at 2 will make it stale', async () => { + expect.assertions(2); + const opts: IssueProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 10, + daysBeforeIssueStale: 2 + }; + let issueDate = new Date(); + issueDate.setDate(issueDate.getDate() - 2); + const TestIssueList: Issue[] = [ + generateIssue( + opts, + 1, + 'An issue with no label', + issueDate.toDateString(), + ) + ]; + const processor = new IssueProcessor( + opts, + async () => 'abot', + 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); +}); + +test('processing an issue opened since 2 days and with the option "daysBeforeIssueStale" at 1 will make it stale', async () => { + expect.assertions(2); + const opts: IssueProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 10, + daysBeforeIssueStale: 1 + }; + let issueDate = new Date(); + issueDate.setDate(issueDate.getDate() - 2); + const TestIssueList: Issue[] = [ + generateIssue( + opts, + 1, + 'An issue with no label', + issueDate.toDateString(), + ) + ]; + const processor = new IssueProcessor( + opts, + async () => 'abot', + 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); +}); + +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: IssueProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 10, + daysBeforePrStale: 3 + }; + let issueDate = new Date(); + issueDate.setDate(issueDate.getDate() - 2); + const TestIssueList: Issue[] = [ + generateIssue( + opts, + 1, + 'A pull request with no label', + issueDate.toDateString(), + issueDate.toDateString(), + true + ) + ]; + const processor = new IssueProcessor( + opts, + async () => 'abot', + 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(0); + expect(processor.closedIssues.length).toEqual(0); +}); + +test('processing a pull request opened since 2 days and with the option "daysBeforePrStale" at 2 will make it stale', async () => { + expect.assertions(2); + const opts: IssueProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 10, + daysBeforePrStale: 2 + }; + let issueDate = new Date(); + issueDate.setDate(issueDate.getDate() - 2); + const TestIssueList: Issue[] = [ + generateIssue( + opts, + 1, + 'A pull request with no label', + issueDate.toDateString(), + issueDate.toDateString(), + true + ) + ]; + const processor = new IssueProcessor( + opts, + async () => 'abot', + 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); +}); + +test('processing a pull request opened since 2 days and with the option "daysBeforePrStale" at 1 will make it stale', async () => { + expect.assertions(2); + const opts: IssueProcessorOptions = { + ...DefaultProcessorOptions, + daysBeforeStale: 10, + daysBeforePrStale: 1 + }; + let issueDate = new Date(); + issueDate.setDate(issueDate.getDate() - 2); + const TestIssueList: Issue[] = [ + generateIssue( + opts, + 1, + 'A pull request with no label', + issueDate.toDateString(), + issueDate.toDateString(), + true + ) + ]; + const processor = new IssueProcessor( + opts, + async () => 'abot', + 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); +}); diff --git a/src/IssueProcessor.ts b/src/IssueProcessor.ts index f1c2d93db..f74260db7 100644 --- a/src/IssueProcessor.ts +++ b/src/IssueProcessor.ts @@ -273,7 +273,7 @@ export class IssueProcessor { // should this issue be marked stale? const shouldBeStale = !IssueProcessor._updatedSince( issue.updated_at, - this.options.daysBeforeStale + daysBeforeStale ); // determine if this issue needs to be marked stale first From d21d307fd87bde7f0f120c92c6909e8a1fe3981c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 5 Feb 2021 12:53:23 +0100 Subject: [PATCH 3/4] Log why issue is not marked as stale (#301) This might help to understand some situations as described in https://github.com/actions/stale/issues/299. --- src/IssueProcessor.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/IssueProcessor.ts b/src/IssueProcessor.ts index f74260db7..8be9fec43 100644 --- a/src/IssueProcessor.ts +++ b/src/IssueProcessor.ts @@ -283,6 +283,10 @@ export class IssueProcessor { ); await this._markStale(issue, staleMessage, staleLabel, skipMessage); issue.isStale = true; // this issue is now considered stale + } else if (!issue.isStale) { + issueLogger.info( + `Not marking as stale: shouldBeStale=${shouldBeStale}, shouldMarkAsStale=${shouldMarkAsStale}` + ); } // process the issue if it was marked stale From 9d6f46564a515a9ea11e7762ab3957ee58ca50da Mon Sep 17 00:00:00 2001 From: Ross Brodbeck Date: Fri, 5 Feb 2021 06:56:22 -0500 Subject: [PATCH 4/4] Add rebuilt index --- __tests__/main.test.ts | 45 ++++++++++++++---------------------------- dist/index.js | 5 ++++- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 6fea323a2..906be9555 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -2273,12 +2273,7 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss let issueDate = new Date(); issueDate.setDate(issueDate.getDate() - 2); const TestIssueList: Issue[] = [ - generateIssue( - opts, - 1, - 'An issue with no label', - issueDate.toDateString(), - ) + generateIssue(opts, 1, 'An issue with no label', issueDate.toDateString()) ]; const processor = new IssueProcessor( opts, @@ -2287,10 +2282,10 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss async (num, dt) => [], async (issue, label) => new Date().toDateString() ); - + // process our fake issue list await processor.processIssues(1); - + expect(processor.staleIssues.length).toEqual(0); expect(processor.closedIssues.length).toEqual(0); }); @@ -2305,12 +2300,7 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss let issueDate = new Date(); issueDate.setDate(issueDate.getDate() - 2); const TestIssueList: Issue[] = [ - generateIssue( - opts, - 1, - 'An issue with no label', - issueDate.toDateString(), - ) + generateIssue(opts, 1, 'An issue with no label', issueDate.toDateString()) ]; const processor = new IssueProcessor( opts, @@ -2319,10 +2309,10 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss 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); }); @@ -2337,12 +2327,7 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss let issueDate = new Date(); issueDate.setDate(issueDate.getDate() - 2); const TestIssueList: Issue[] = [ - generateIssue( - opts, - 1, - 'An issue with no label', - issueDate.toDateString(), - ) + generateIssue(opts, 1, 'An issue with no label', issueDate.toDateString()) ]; const processor = new IssueProcessor( opts, @@ -2351,10 +2336,10 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss 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); }); @@ -2385,10 +2370,10 @@ test('processing a pull request opened since 2 days and with the option "daysBef async (num, dt) => [], async (issue, label) => new Date().toDateString() ); - + // process our fake issue list await processor.processIssues(1); - + expect(processor.staleIssues.length).toEqual(0); expect(processor.closedIssues.length).toEqual(0); }); @@ -2419,10 +2404,10 @@ test('processing a pull request opened since 2 days and with the option "daysBef 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); }); @@ -2453,10 +2438,10 @@ test('processing a pull request opened since 2 days and with the option "daysBef 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); }); diff --git a/dist/index.js b/dist/index.js index 341822c75..8b113ec96 100644 --- a/dist/index.js +++ b/dist/index.js @@ -157,13 +157,16 @@ 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 = !IssueProcessor._updatedSince(issue.updated_at, 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`); yield this._markStale(issue, staleMessage, staleLabel, skipMessage); issue.isStale = true; // this issue is now considered stale } + else if (!issue.isStale) { + issueLogger.info(`Not marking as stale: shouldBeStale=${shouldBeStale}, shouldMarkAsStale=${shouldMarkAsStale}`); + } // process the issue if it was marked stale if (issue.isStale) { issueLogger.info(`Found a stale ${issueType}`);