Skip to content

Commit

Permalink
Add close-issue-reason option (#764)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jtbandes committed Jun 23, 2022
1 parent 29e800e commit 06d2a39
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -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 | |
Expand Down Expand Up @@ -219,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.
Expand Down
3 changes: 2 additions & 1 deletion __tests__/constants/default-processor-options.ts
Expand Up @@ -50,5 +50,6 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
ignoreUpdates: false,
ignoreIssueUpdates: undefined,
ignorePrUpdates: undefined,
exemptDraftPr: false
exemptDraftPr: false,
closeIssueReason: ''
});
13 changes: 11 additions & 2 deletions dist/index.js
Expand Up @@ -885,7 +885,8 @@ 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.closeIssueReason || undefined
});
}
}
Expand Down Expand Up @@ -1892,6 +1893,7 @@ var Option;
Option["IgnoreIssueUpdates"] = "ignore-issue-updates";
Option["IgnorePrUpdates"] = "ignore-pr-updates";
Option["ExemptDraftPr"] = "exempt-draft-pr";
Option["CloseIssueReason"] = "close-issue-reason";
})(Option = exports.Option || (exports.Option = {}));


Expand Down Expand Up @@ -2202,7 +2204,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',
closeIssueReason: core.getInput('close-issue-reason')
};
for (const numberInput of [
'days-before-stale',
Expand All @@ -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;
}
function processOutput(staledIssues, closedIssues) {
Expand Down
3 changes: 2 additions & 1 deletion src/classes/issue.spec.ts
Expand Up @@ -61,7 +61,8 @@ describe('Issue', (): void => {
ignoreUpdates: false,
ignoreIssueUpdates: undefined,
ignorePrUpdates: undefined,
exemptDraftPr: false
exemptDraftPr: false,
closeIssueReason: ''
};
issueInterface = {
title: 'dummy-title',
Expand Down
3 changes: 2 additions & 1 deletion src/classes/issues-processor.ts
Expand Up @@ -865,7 +865,8 @@ export class IssuesProcessor {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
state: 'closed',
state_reason: this.options.closeIssueReason || undefined
});
}
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion src/enums/option.ts
Expand Up @@ -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',
CloseIssueReason = 'close-issue-reason'
}
1 change: 1 addition & 0 deletions src/interfaces/issues-processor-options.ts
Expand Up @@ -51,4 +51,5 @@ export interface IIssuesProcessorOptions {
ignoreIssueUpdates: boolean | undefined;
ignorePrUpdates: boolean | undefined;
exemptDraftPr: boolean;
closeIssueReason: string;
}
12 changes: 11 additions & 1 deletion src/main.ts
Expand Up @@ -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',
closeIssueReason: core.getInput('close-issue-reason')
};

for (const numberInput of [
Expand All @@ -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;
}

Expand Down

0 comments on commit 06d2a39

Please sign in to comment.