Skip to content

Commit

Permalink
feat: set close reason
Browse files Browse the repository at this point in the history
Closes #10.
  • Loading branch information
dessant committed Nov 14, 2023
1 parent 2755608 commit cb26bc2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ The action can be configured using [input parameters](https://docs.github.com/en
- Close issues marked as support requests,
value must be either `true` or `false`
- Optional, defaults to `true`
- **`issue-close-reason`**
- Reason for closing issues, value must be
either `completed` or `not planned`
- Optional, defaults to `not planned`
- **`lock-issue`**
- Lock issues marked as support requests,
value must be either `true` or `false`
Expand Down Expand Up @@ -115,6 +119,7 @@ jobs:
to be a support request. Please use our support channels
to get help with the project.
close-issue: true
issue-close-reason: 'not planned'
lock-issue: false
issue-lock-reason: 'off-topic'
```
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ inputs:
close-issue:
description: 'Close issues marked as support requests, value must be either `true` or `false`'
default: true
issue-close-reason:
description: 'Reason for closing issues, value must be either `completed` or `not planned`'
default: 'not planned'
lock-issue:
description: Lock issues marked as support requests, value must be either `true` or `false`'
default: false
Expand Down
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ class App {

if (this.config['close-issue'] && issueData.state === 'open') {
core.debug(`Closing (issue: ${issue.issue_number})`);
await this.client.rest.issues.update({...issue, state: 'closed'});

const params = {...issue, state: 'closed'};

const closeReason = this.config['issue-close-reason'];
if (closeReason) {
params.state_reason = closeReason;
}

await this.client.rest.issues.update(params);
}

if (this.config['lock-issue'] && !issueData.locked) {
Expand Down
23 changes: 23 additions & 0 deletions src/schema.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import Joi from 'joi';

const extendedJoi = Joi.extend(joi => {
return {
type: 'closeReason',
base: joi.string(),
coerce: {
from: 'string',
method(value, helpers) {
value = value.trim();
if (value === 'not planned') {
value = 'not_planned';
}

return {value};
}
}
};
});

const schema = Joi.object({
'github-token': Joi.string().trim().max(100),

Expand All @@ -18,6 +36,11 @@ const schema = Joi.object({

'close-issue': Joi.boolean().default(true),

'issue-close-reason': extendedJoi
.closeReason()
.valid('completed', 'not_planned', '')
.default('not planned'),

'lock-issue': Joi.boolean().default(true),

'issue-lock-reason': Joi.string()
Expand Down

0 comments on commit cb26bc2

Please sign in to comment.