From e7ea9892eea11479460d8d132548335d94d0fc97 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Thu, 23 Jun 2022 11:36:45 -0700 Subject: [PATCH 1/8] Add close-as-not-planned option --- __tests__/constants/default-processor-options.ts | 3 ++- src/classes/issue.spec.ts | 3 ++- src/classes/issues-processor.ts | 5 ++++- src/interfaces/issues-processor-options.ts | 1 + src/main.ts | 3 ++- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/__tests__/constants/default-processor-options.ts b/__tests__/constants/default-processor-options.ts index b526d12aa..b721a4cf8 100644 --- a/__tests__/constants/default-processor-options.ts +++ b/__tests__/constants/default-processor-options.ts @@ -50,5 +50,6 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({ ignoreUpdates: false, ignoreIssueUpdates: undefined, ignorePrUpdates: undefined, - exemptDraftPr: false + exemptDraftPr: false, + closeAsNotPlanned: undefined }); diff --git a/src/classes/issue.spec.ts b/src/classes/issue.spec.ts index ccd32d51a..bf269bcb1 100644 --- a/src/classes/issue.spec.ts +++ b/src/classes/issue.spec.ts @@ -61,7 +61,8 @@ describe('Issue', (): void => { ignoreUpdates: false, ignoreIssueUpdates: undefined, ignorePrUpdates: undefined, - exemptDraftPr: false + exemptDraftPr: false, + closeAsNotPlanned: undefined }; issueInterface = { title: 'dummy-title', diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index 89ca2d04e..5359fd7e0 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -865,7 +865,10 @@ export class IssuesProcessor { owner: context.repo.owner, repo: context.repo.repo, issue_number: issue.number, - state: 'closed' + state: 'closed', + state_reason: this.options.closeAsNotPlanned + ? 'not_planned' + : undefined }); } } catch (error) { diff --git a/src/interfaces/issues-processor-options.ts b/src/interfaces/issues-processor-options.ts index 8adbfb4a5..243795a8f 100644 --- a/src/interfaces/issues-processor-options.ts +++ b/src/interfaces/issues-processor-options.ts @@ -51,4 +51,5 @@ export interface IIssuesProcessorOptions { ignoreIssueUpdates: boolean | undefined; ignorePrUpdates: boolean | undefined; exemptDraftPr: boolean; + closeAsNotPlanned: boolean | undefined; } diff --git a/src/main.ts b/src/main.ts index af96654c5..a6014534e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -87,7 +87,8 @@ function _getAndValidateArgs(): IIssuesProcessorOptions { ignoreUpdates: core.getInput('ignore-updates') === 'true', ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'), ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'), - exemptDraftPr: core.getInput('exempt-draft-pr') === 'true' + exemptDraftPr: core.getInput('exempt-draft-pr') === 'true', + closeAsNotPlanned: _toOptionalBoolean('close-as-not-planned') }; for (const numberInput of [ From 70ffa7fcaf72853e7b16cfabbcbfc162f371c6b6 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Thu, 23 Jun 2022 11:40:54 -0700 Subject: [PATCH 2/8] update readme --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 7578edd20..bb2895c11 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ Every argument is optional. | [ignore-updates](#ignore-updates) | Any update (update/comment) can reset the stale idle time on the issues/PRs | `false` | | [ignore-issue-updates](#ignore-issue-updates) | Override [ignore-updates](#ignore-updates) for issues only | | | [ignore-pr-updates](#ignore-pr-updates) | Override [ignore-updates](#ignore-updates) for PRs only | | +| [close-as-not-planned](#close-as-not-planned) | Use the "not planned" close reason for issues | | ### List of output options @@ -509,6 +510,12 @@ Useful to override [ignore-updates](#ignore-updates) but only to ignore the upda Default value: unset +#### close-as-not-planned + +When closing issues, close them as ["not planned"](https://github.blog/changelog/2022-05-19-the-new-github-issues-may-19th-update/). + +Default value: unset + ### Usage See also [action.yml](./action.yml) for a comprehensive list of all the options. From 88af49e34ee1da96f7107921c3051ee60fda332b Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Thu, 23 Jun 2022 11:42:12 -0700 Subject: [PATCH 3/8] add to Option enum --- src/enums/option.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/enums/option.ts b/src/enums/option.ts index f7167c725..8e455cdea 100644 --- a/src/enums/option.ts +++ b/src/enums/option.ts @@ -46,5 +46,6 @@ export enum Option { IgnoreUpdates = 'ignore-updates', IgnoreIssueUpdates = 'ignore-issue-updates', IgnorePrUpdates = 'ignore-pr-updates', - ExemptDraftPr = 'exempt-draft-pr' + ExemptDraftPr = 'exempt-draft-pr', + CloseAsNotPlanned = 'close-as-not-planned' } From 830e3666ab7ab679833f91e634c8bb8738bb84d3 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Thu, 23 Jun 2022 11:43:14 -0700 Subject: [PATCH 4/8] improve wording --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bb2895c11..82a951060 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ Every argument is optional. | [ignore-updates](#ignore-updates) | Any update (update/comment) can reset the stale idle time on the issues/PRs | `false` | | [ignore-issue-updates](#ignore-issue-updates) | Override [ignore-updates](#ignore-updates) for issues only | | | [ignore-pr-updates](#ignore-pr-updates) | Override [ignore-updates](#ignore-updates) for PRs only | | -| [close-as-not-planned](#close-as-not-planned) | Use the "not planned" close reason for issues | | +| [close-as-not-planned](#close-as-not-planned) | Close issues as "not planned" instead of "completed" | | ### List of output options @@ -512,7 +512,7 @@ Default value: unset #### close-as-not-planned -When closing issues, close them as ["not planned"](https://github.blog/changelog/2022-05-19-the-new-github-issues-may-19th-update/). +When closing issues, close them as ["not planned"](https://github.blog/changelog/2022-05-19-the-new-github-issues-may-19th-update/) instead of "completed". Default value: unset From e1eb218ee1421864b6deab659ba0443d5be856b9 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Thu, 23 Jun 2022 11:47:23 -0700 Subject: [PATCH 5/8] npm run pack --- dist/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index f017e13a3..99f399eb0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -885,7 +885,10 @@ class IssuesProcessor { owner: github_1.context.repo.owner, repo: github_1.context.repo.repo, issue_number: issue.number, - state: 'closed' + state: 'closed', + state_reason: this.options.closeAsNotPlanned + ? 'not_planned' + : undefined }); } } @@ -1892,6 +1895,7 @@ var Option; Option["IgnoreIssueUpdates"] = "ignore-issue-updates"; Option["IgnorePrUpdates"] = "ignore-pr-updates"; Option["ExemptDraftPr"] = "exempt-draft-pr"; + Option["CloseAsNotPlanned"] = "close-as-not-planned"; })(Option = exports.Option || (exports.Option = {})); @@ -2202,7 +2206,8 @@ function _getAndValidateArgs() { ignoreUpdates: core.getInput('ignore-updates') === 'true', ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'), ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'), - exemptDraftPr: core.getInput('exempt-draft-pr') === 'true' + exemptDraftPr: core.getInput('exempt-draft-pr') === 'true', + closeAsNotPlanned: _toOptionalBoolean('close-as-not-planned') }; for (const numberInput of [ 'days-before-stale', From 4e102e6cea6693c2eb43f9e119d5ced4bd9ce80e Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Thu, 23 Jun 2022 13:55:39 -0700 Subject: [PATCH 6/8] updates from review --- README.md | 6 +++--- __tests__/constants/default-processor-options.ts | 2 +- dist/index.js | 13 ++++++++----- src/classes/issue.spec.ts | 2 +- src/classes/issues-processor.ts | 4 +--- src/enums/option.ts | 2 +- src/interfaces/issues-processor-options.ts | 2 +- src/main.ts | 10 +++++++++- 8 files changed, 25 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 82a951060..befa27c8b 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Every argument is optional. | [close-pr-message](#close-pr-message) | Comment on the staled PRs while closed | | | [stale-issue-label](#stale-issue-label) | Label to apply on staled issues | `Stale` | | [close-issue-label](#close-issue-label) | Label to apply on closed issues | | +| [close-issue-reason](#close-issue-reason) | Reason to use when closing issues | | | [stale-pr-label](#stale-pr-label) | Label to apply on staled PRs | `Stale` | | [close-pr-label](#close-pr-label) | Label to apply on closed PRs | | | [exempt-issue-labels](#exempt-issue-labels) | Labels on issues exempted from stale | | @@ -80,7 +81,6 @@ Every argument is optional. | [ignore-updates](#ignore-updates) | Any update (update/comment) can reset the stale idle time on the issues/PRs | `false` | | [ignore-issue-updates](#ignore-issue-updates) | Override [ignore-updates](#ignore-updates) for issues only | | | [ignore-pr-updates](#ignore-pr-updates) | Override [ignore-updates](#ignore-updates) for PRs only | | -| [close-as-not-planned](#close-as-not-planned) | Close issues as "not planned" instead of "completed" | | ### List of output options @@ -510,9 +510,9 @@ Useful to override [ignore-updates](#ignore-updates) but only to ignore the upda Default value: unset -#### close-as-not-planned +#### close-issue-reason -When closing issues, close them as ["not planned"](https://github.blog/changelog/2022-05-19-the-new-github-issues-may-19th-update/) instead of "completed". +Specify the [reason](https://github.blog/changelog/2022-05-19-the-new-github-issues-may-19th-update/) used when closing issues. Valid values are `completed` and `not_planned`. Default value: unset diff --git a/__tests__/constants/default-processor-options.ts b/__tests__/constants/default-processor-options.ts index b721a4cf8..a0ac1e5a2 100644 --- a/__tests__/constants/default-processor-options.ts +++ b/__tests__/constants/default-processor-options.ts @@ -51,5 +51,5 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({ ignoreIssueUpdates: undefined, ignorePrUpdates: undefined, exemptDraftPr: false, - closeAsNotPlanned: undefined + closeIssueReason: undefined }); diff --git a/dist/index.js b/dist/index.js index 99f399eb0..1962cbb2e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -886,9 +886,7 @@ class IssuesProcessor { repo: github_1.context.repo.repo, issue_number: issue.number, state: 'closed', - state_reason: this.options.closeAsNotPlanned - ? 'not_planned' - : undefined + state_reason: this.options.closeIssueReason || undefined }); } } @@ -1895,7 +1893,7 @@ var Option; Option["IgnoreIssueUpdates"] = "ignore-issue-updates"; Option["IgnorePrUpdates"] = "ignore-pr-updates"; Option["ExemptDraftPr"] = "exempt-draft-pr"; - Option["CloseAsNotPlanned"] = "close-as-not-planned"; + Option["CloseIssueReason"] = "close-issue-reason"; })(Option = exports.Option || (exports.Option = {})); @@ -2207,7 +2205,7 @@ function _getAndValidateArgs() { ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'), ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'), exemptDraftPr: core.getInput('exempt-draft-pr') === 'true', - closeAsNotPlanned: _toOptionalBoolean('close-as-not-planned') + closeIssueReason: core.getInput('close-issue-reason') }; for (const numberInput of [ 'days-before-stale', @@ -2230,6 +2228,11 @@ function _getAndValidateArgs() { } } } + if (![undefined, 'completed', 'not_planned'].includes(args.closeIssueReason)) { + const errorMessage = `Unrecognized close-issue-reason "${args.closeIssueReason}"`; + core.setFailed(errorMessage); + throw new Error(errorMessage); + } return args; } function processOutput(staledIssues, closedIssues) { diff --git a/src/classes/issue.spec.ts b/src/classes/issue.spec.ts index bf269bcb1..831311646 100644 --- a/src/classes/issue.spec.ts +++ b/src/classes/issue.spec.ts @@ -62,7 +62,7 @@ describe('Issue', (): void => { ignoreIssueUpdates: undefined, ignorePrUpdates: undefined, exemptDraftPr: false, - closeAsNotPlanned: undefined + closeIssueReason: undefined }; issueInterface = { title: 'dummy-title', diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index 5359fd7e0..d603a5f2f 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -866,9 +866,7 @@ export class IssuesProcessor { repo: context.repo.repo, issue_number: issue.number, state: 'closed', - state_reason: this.options.closeAsNotPlanned - ? 'not_planned' - : undefined + state_reason: this.options.closeIssueReason || undefined }); } } catch (error) { diff --git a/src/enums/option.ts b/src/enums/option.ts index 8e455cdea..38cfb193d 100644 --- a/src/enums/option.ts +++ b/src/enums/option.ts @@ -47,5 +47,5 @@ export enum Option { IgnoreIssueUpdates = 'ignore-issue-updates', IgnorePrUpdates = 'ignore-pr-updates', ExemptDraftPr = 'exempt-draft-pr', - CloseAsNotPlanned = 'close-as-not-planned' + CloseIssueReason = 'close-issue-reason' } diff --git a/src/interfaces/issues-processor-options.ts b/src/interfaces/issues-processor-options.ts index 243795a8f..9737ac7de 100644 --- a/src/interfaces/issues-processor-options.ts +++ b/src/interfaces/issues-processor-options.ts @@ -51,5 +51,5 @@ export interface IIssuesProcessorOptions { ignoreIssueUpdates: boolean | undefined; ignorePrUpdates: boolean | undefined; exemptDraftPr: boolean; - closeAsNotPlanned: boolean | undefined; + closeIssueReason: string | undefined; } diff --git a/src/main.ts b/src/main.ts index a6014534e..d0c590057 100644 --- a/src/main.ts +++ b/src/main.ts @@ -88,7 +88,7 @@ function _getAndValidateArgs(): IIssuesProcessorOptions { ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'), ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'), exemptDraftPr: core.getInput('exempt-draft-pr') === 'true', - closeAsNotPlanned: _toOptionalBoolean('close-as-not-planned') + closeIssueReason: core.getInput('close-issue-reason') }; for (const numberInput of [ @@ -114,6 +114,14 @@ function _getAndValidateArgs(): IIssuesProcessorOptions { } } + if ( + ![undefined, 'completed', 'not_planned'].includes(args.closeIssueReason) + ) { + const errorMessage = `Unrecognized close-issue-reason "${args.closeIssueReason}"`; + core.setFailed(errorMessage); + throw new Error(errorMessage); + } + return args; } From f83dd8d9327f5335f955d41904e630d37596ca57 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Thu, 23 Jun 2022 14:20:12 -0700 Subject: [PATCH 7/8] fix tests and improve error message --- __tests__/constants/default-processor-options.ts | 2 +- dist/index.js | 5 +++-- src/classes/issue.spec.ts | 2 +- src/interfaces/issues-processor-options.ts | 2 +- src/main.ts | 9 +++++---- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/__tests__/constants/default-processor-options.ts b/__tests__/constants/default-processor-options.ts index a0ac1e5a2..ee3e7306d 100644 --- a/__tests__/constants/default-processor-options.ts +++ b/__tests__/constants/default-processor-options.ts @@ -51,5 +51,5 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({ ignoreIssueUpdates: undefined, ignorePrUpdates: undefined, exemptDraftPr: false, - closeIssueReason: undefined + closeIssueReason: '' }); diff --git a/dist/index.js b/dist/index.js index 1962cbb2e..bec2b12c3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2228,8 +2228,9 @@ function _getAndValidateArgs() { } } } - if (![undefined, 'completed', 'not_planned'].includes(args.closeIssueReason)) { - const errorMessage = `Unrecognized close-issue-reason "${args.closeIssueReason}"`; + const validCloseReasons = ['', 'completed', 'not_planned']; + if (!validCloseReasons.includes(args.closeIssueReason)) { + const errorMessage = `Unrecognized close-issue-reason "${args.closeIssueReason}", valid values are: ${validCloseReasons.filter(Boolean).join(', ')}`; core.setFailed(errorMessage); throw new Error(errorMessage); } diff --git a/src/classes/issue.spec.ts b/src/classes/issue.spec.ts index 831311646..0a60d1a58 100644 --- a/src/classes/issue.spec.ts +++ b/src/classes/issue.spec.ts @@ -62,7 +62,7 @@ describe('Issue', (): void => { ignoreIssueUpdates: undefined, ignorePrUpdates: undefined, exemptDraftPr: false, - closeIssueReason: undefined + closeIssueReason: '' }; issueInterface = { title: 'dummy-title', diff --git a/src/interfaces/issues-processor-options.ts b/src/interfaces/issues-processor-options.ts index 9737ac7de..496584e87 100644 --- a/src/interfaces/issues-processor-options.ts +++ b/src/interfaces/issues-processor-options.ts @@ -51,5 +51,5 @@ export interface IIssuesProcessorOptions { ignoreIssueUpdates: boolean | undefined; ignorePrUpdates: boolean | undefined; exemptDraftPr: boolean; - closeIssueReason: string | undefined; + closeIssueReason: string; } diff --git a/src/main.ts b/src/main.ts index d0c590057..770aa1163 100644 --- a/src/main.ts +++ b/src/main.ts @@ -114,10 +114,11 @@ function _getAndValidateArgs(): IIssuesProcessorOptions { } } - if ( - ![undefined, 'completed', 'not_planned'].includes(args.closeIssueReason) - ) { - const errorMessage = `Unrecognized close-issue-reason "${args.closeIssueReason}"`; + const validCloseReasons = ['', 'completed', 'not_planned']; + if (!validCloseReasons.includes(args.closeIssueReason)) { + const errorMessage = `Unrecognized close-issue-reason "${ + args.closeIssueReason + }", valid values are: ${validCloseReasons.filter(Boolean).join(', ')}`; core.setFailed(errorMessage); throw new Error(errorMessage); } From 70f12f5d755d672ba6519993b15892f3b4d9ef68 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Thu, 23 Jun 2022 14:21:33 -0700 Subject: [PATCH 8/8] fix readme order --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index befa27c8b..f76e000b3 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,12 @@ It will be automatically removed if the issues are no longer closed nor locked. Default value: unset Required Permission: `issues: write` +#### close-issue-reason + +Specify the [reason](https://github.blog/changelog/2022-05-19-the-new-github-issues-may-19th-update/) used when closing issues. Valid values are `completed` and `not_planned`. + +Default value: unset + #### stale-pr-label The label that will be added to the pull requests when automatically marked as stale. @@ -510,12 +516,6 @@ Useful to override [ignore-updates](#ignore-updates) but only to ignore the upda Default value: unset -#### close-issue-reason - -Specify the [reason](https://github.blog/changelog/2022-05-19-the-new-github-issues-may-19th-update/) used when closing issues. Valid values are `completed` and `not_planned`. - -Default value: unset - ### Usage See also [action.yml](./action.yml) for a comprehensive list of all the options.