From 51cc4676ffeb41639c979f74cb995bf6e4ed64b8 Mon Sep 17 00:00:00 2001 From: Ross Brodbeck Date: Mon, 11 May 2020 09:44:50 -0400 Subject: [PATCH] Add debugging, update tests and fix logic. --- __tests__/main.test.ts | 48 ++++++++++++++++++++++++++++++++---------- dist/index.js | 4 ++-- src/IssueProcessor.ts | 6 ++++-- tsconfig.json | 3 ++- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 810f5bb2..7a6ab054 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -64,7 +64,7 @@ test('empty issue list results in 1 operation', async () => { test('processing an issue with no label will make it stale', async () => { const TestIssueList: Issue[] = [ - generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z') + generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z') ]; const processor = new IssueProcessor( @@ -83,7 +83,13 @@ test('processing an issue with no label will make it stale', async () => { test('processing a stale issue will close it', async () => { const TestIssueList: Issue[] = [ - generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Stale']) + generateIssue( + 1, + 'A stale issue that should be closed', + '2020-01-01T17:00:00Z', + false, + ['Stale'] + ) ]; const processor = new IssueProcessor( @@ -102,7 +108,13 @@ test('processing a stale issue will close it', async () => { test('processing a stale PR will close it', async () => { const TestIssueList: Issue[] = [ - generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, ['Stale']) + generateIssue( + 1, + 'A stale PR that should be closed', + '2020-01-01T17:00:00Z', + true, + ['Stale'] + ) ]; const processor = new IssueProcessor( @@ -121,7 +133,14 @@ test('processing a stale PR will close it', async () => { test('closed issues will not be marked stale', async () => { const TestIssueList: Issue[] = [ - generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [], true) + generateIssue( + 1, + 'A closed issue that will not be marked', + '2020-01-01T17:00:00Z', + false, + [], + true + ) ]; const processor = new IssueProcessor( @@ -141,7 +160,7 @@ test('stale closed issues will not be closed', async () => { const TestIssueList: Issue[] = [ generateIssue( 1, - 'My first issue', + 'A stale closed issue', '2020-01-01T17:00:00Z', false, ['Stale'], @@ -165,7 +184,14 @@ test('stale closed issues will not be closed', async () => { test('closed prs will not be marked stale', async () => { const TestIssueList: Issue[] = [ - generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, [], true) + generateIssue( + 1, + 'A closed PR that will not be marked', + '2020-01-01T17:00:00Z', + true, + [], + true + ) ]; const processor = new IssueProcessor( @@ -186,7 +212,7 @@ test('stale closed prs will not be closed', async () => { const TestIssueList: Issue[] = [ generateIssue( 1, - 'My first PR', + 'A stale closed PR that will not be closed again', '2020-01-01T17:00:00Z', true, ['Stale'], @@ -212,7 +238,7 @@ test('locked issues will not be marked stale', async () => { const TestIssueList: Issue[] = [ generateIssue( 1, - 'My first issue', + 'A locked issue that will not be stale', '2020-01-01T17:00:00Z', false, [], @@ -236,7 +262,7 @@ test('stale locked issues will not be closed', async () => { const TestIssueList: Issue[] = [ generateIssue( 1, - 'My first issue', + 'A stale locked issue that will not be closed', '2020-01-01T17:00:00Z', false, ['Stale'], @@ -263,7 +289,7 @@ test('locked prs will not be marked stale', async () => { const TestIssueList: Issue[] = [ generateIssue( 1, - 'My first PR', + 'A locked PR that will not be marked stale', '2020-01-01T17:00:00Z', true, [], @@ -287,7 +313,7 @@ test('stale locked prs will not be closed', async () => { const TestIssueList: Issue[] = [ generateIssue( 1, - 'My first PR', + 'A stale locked PR that will not be closed', '2020-01-01T17:00:00Z', true, ['Stale'], diff --git a/dist/index.js b/dist/index.js index d07f546d..36fc08ed 100644 --- a/dist/index.js +++ b/dist/index.js @@ -8513,7 +8513,7 @@ class IssueProcessor { core.debug(`Found a stale ${issueType}`); yield this.processStaleIssue(issue, issueType, staleLabel); } - else if (IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale)) { + else if (!IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale)) { core.debug(`Marking ${issueType} stale because it was last updated on ${issue.updated_at}`); yield this.markStale(issue, staleMessage, staleLabel); this.operationsLeft -= 2; @@ -8669,7 +8669,7 @@ class IssueProcessor { static updatedSince(timestamp, num_days) { const daysInMillis = 1000 * 60 * 60 * 24 * num_days; const millisSinceLastUpdated = new Date().getTime() - new Date(timestamp).getTime(); - return millisSinceLastUpdated >= daysInMillis; + return millisSinceLastUpdated < daysInMillis; } static parseCommaSeparatedString(s) { // String.prototype.split defaults to [''] when called on an empty string diff --git a/src/IssueProcessor.ts b/src/IssueProcessor.ts index 82613173..20f65005 100644 --- a/src/IssueProcessor.ts +++ b/src/IssueProcessor.ts @@ -153,7 +153,7 @@ export class IssueProcessor { core.debug(`Found a stale ${issueType}`); await this.processStaleIssue(issue, issueType, staleLabel); } else if ( - IssueProcessor.updatedSince( + !IssueProcessor.updatedSince( issue.updated_at, this.options.daysBeforeStale ) @@ -188,6 +188,7 @@ export class IssueProcessor { issue, markedStaleOn ); + const issueHasUpdate: boolean = IssueProcessor.updatedSince( issue.updated_at, this.options.daysBeforeClose @@ -376,7 +377,8 @@ export class IssueProcessor { const daysInMillis = 1000 * 60 * 60 * 24 * num_days; const millisSinceLastUpdated = new Date().getTime() - new Date(timestamp).getTime(); - return millisSinceLastUpdated >= daysInMillis; + + return millisSinceLastUpdated < daysInMillis; } private static parseCommaSeparatedString(s: string): string[] { diff --git a/tsconfig.json b/tsconfig.json index 353d2ea1..a3871fa7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,8 @@ "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ "strict": true, /* Enable all strict type-checking options. */ "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + //"sourceMap": true }, "exclude": ["node_modules", "**/*.test.ts"] } \ No newline at end of file