Add close-issue-reason option (#764)

* Add close-as-not-planned option

* update readme

* add to Option enum

* improve wording

* npm run pack

* updates from review

* fix tests and improve error message

* fix readme order
This commit is contained in:
Jacob Bandes-Storch 2022-06-23 14:43:36 -07:00 committed by GitHub
parent 29e800e1c8
commit 06d2a3904b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 7 deletions

View File

@ -43,6 +43,7 @@ Every argument is optional.
| [close-pr-message](#close-pr-message) | Comment on the staled PRs while closed | | | [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` | | [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-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` | | [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 | | | [close-pr-label](#close-pr-label) | Label to apply on closed PRs | |
| [exempt-issue-labels](#exempt-issue-labels) | Labels on issues exempted from stale | | | [exempt-issue-labels](#exempt-issue-labels) | Labels on issues exempted from stale | |
@ -219,6 +220,12 @@ It will be automatically removed if the issues are no longer closed nor locked.
Default value: unset Default value: unset
Required Permission: `issues: write` 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 #### stale-pr-label
The label that will be added to the pull requests when automatically marked as stale. The label that will be added to the pull requests when automatically marked as stale.

View File

@ -50,5 +50,6 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
ignoreUpdates: false, ignoreUpdates: false,
ignoreIssueUpdates: undefined, ignoreIssueUpdates: undefined,
ignorePrUpdates: undefined, ignorePrUpdates: undefined,
exemptDraftPr: false exemptDraftPr: false,
closeIssueReason: ''
}); });

13
dist/index.js vendored
View File

@ -885,7 +885,8 @@ class IssuesProcessor {
owner: github_1.context.repo.owner, owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo, repo: github_1.context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
state: 'closed' state: 'closed',
state_reason: this.options.closeIssueReason || undefined
}); });
} }
} }
@ -1892,6 +1893,7 @@ var Option;
Option["IgnoreIssueUpdates"] = "ignore-issue-updates"; Option["IgnoreIssueUpdates"] = "ignore-issue-updates";
Option["IgnorePrUpdates"] = "ignore-pr-updates"; Option["IgnorePrUpdates"] = "ignore-pr-updates";
Option["ExemptDraftPr"] = "exempt-draft-pr"; Option["ExemptDraftPr"] = "exempt-draft-pr";
Option["CloseIssueReason"] = "close-issue-reason";
})(Option = exports.Option || (exports.Option = {})); })(Option = exports.Option || (exports.Option = {}));
@ -2202,7 +2204,8 @@ function _getAndValidateArgs() {
ignoreUpdates: core.getInput('ignore-updates') === 'true', ignoreUpdates: core.getInput('ignore-updates') === 'true',
ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'), ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'),
ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'), ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
exemptDraftPr: core.getInput('exempt-draft-pr') === 'true' exemptDraftPr: core.getInput('exempt-draft-pr') === 'true',
closeIssueReason: core.getInput('close-issue-reason')
}; };
for (const numberInput of [ for (const numberInput of [
'days-before-stale', 'days-before-stale',
@ -2225,6 +2228,12 @@ function _getAndValidateArgs() {
} }
} }
} }
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);
}
return args; return args;
} }
function processOutput(staledIssues, closedIssues) { function processOutput(staledIssues, closedIssues) {

View File

@ -61,7 +61,8 @@ describe('Issue', (): void => {
ignoreUpdates: false, ignoreUpdates: false,
ignoreIssueUpdates: undefined, ignoreIssueUpdates: undefined,
ignorePrUpdates: undefined, ignorePrUpdates: undefined,
exemptDraftPr: false exemptDraftPr: false,
closeIssueReason: ''
}; };
issueInterface = { issueInterface = {
title: 'dummy-title', title: 'dummy-title',

View File

@ -865,7 +865,8 @@ export class IssuesProcessor {
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
state: 'closed' state: 'closed',
state_reason: this.options.closeIssueReason || undefined
}); });
} }
} catch (error) { } catch (error) {

View File

@ -46,5 +46,6 @@ export enum Option {
IgnoreUpdates = 'ignore-updates', IgnoreUpdates = 'ignore-updates',
IgnoreIssueUpdates = 'ignore-issue-updates', IgnoreIssueUpdates = 'ignore-issue-updates',
IgnorePrUpdates = 'ignore-pr-updates', IgnorePrUpdates = 'ignore-pr-updates',
ExemptDraftPr = 'exempt-draft-pr' ExemptDraftPr = 'exempt-draft-pr',
CloseIssueReason = 'close-issue-reason'
} }

View File

@ -51,4 +51,5 @@ export interface IIssuesProcessorOptions {
ignoreIssueUpdates: boolean | undefined; ignoreIssueUpdates: boolean | undefined;
ignorePrUpdates: boolean | undefined; ignorePrUpdates: boolean | undefined;
exemptDraftPr: boolean; exemptDraftPr: boolean;
closeIssueReason: string;
} }

View File

@ -87,7 +87,8 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
ignoreUpdates: core.getInput('ignore-updates') === 'true', ignoreUpdates: core.getInput('ignore-updates') === 'true',
ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'), ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'),
ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'), ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
exemptDraftPr: core.getInput('exempt-draft-pr') === 'true' exemptDraftPr: core.getInput('exempt-draft-pr') === 'true',
closeIssueReason: core.getInput('close-issue-reason')
}; };
for (const numberInput of [ for (const numberInput of [
@ -113,6 +114,15 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
} }
} }
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);
}
return args; return args;
} }