Skip to content

Commit

Permalink
feat: set close reason
Browse files Browse the repository at this point in the history
Closes #22.
  • Loading branch information
dessant committed Jun 8, 2023
1 parent 9433de6 commit 5155811
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ must be configured. The following actions are supported:
- Remove labels
- Close threads
- Reopen threads
- Lock threads with an optional lock reason
- Lock threads
- Unlock threads

## Usage
Expand Down Expand Up @@ -80,6 +80,10 @@ pull requests or discussions by grouping them under the
- Close threads, value must be either `true` or `false`,
ignored for discussions
- Optional, defaults to `false`
- **`close-reason`**
- Reason for closing threads, value must be
either `completed` or `not planned`, ignored for discussions
- Optional, defaults to `completed`
- **`reopen`**
- Reopen threads, value must be either `true` or `false`,
ignored for discussions
Expand Down Expand Up @@ -235,6 +239,8 @@ feature:
:wave: @{issue-author}, please use our idea board to request new features.
# Close the issue
close: true
# Set a close reason
close-reason: 'not planned'

# The `wip` label is added to pull requests
wip:
Expand Down
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,24 @@ class App {
!threadData.merged
) {
core.debug('Reopening');

await this.client.rest.issues.update({...issue, state: 'open'});
}

if (actions.close && threadData.state === 'open') {
core.debug('Closing');
await this.client.rest.issues.update({...issue, state: 'closed'});

await this.client.rest.issues.update({
...issue,
state: 'closed',
state_reason: actions['close-reason']
});
}
}

if (actions.lock && !threadData.locked) {
core.debug('Locking');

if (threadType === 'discussion') {
await this.client.graphql(lockLockableQuery, {
lockableId: discussion.node_id
Expand All @@ -241,6 +248,7 @@ class App {

if (actions.unlock && threadData.locked) {
core.debug('Unlocking');

if (threadType === 'discussion') {
await this.client.graphql(unlockLockableQuery, {
lockableId: discussion.node_id
Expand Down
19 changes: 19 additions & 0 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ const extendedJoi = Joi.extend(joi => {
.filter(Boolean);
}

return {value};
}
}
};
}).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};
}
}
Expand Down Expand Up @@ -50,6 +66,8 @@ const configSchema = Joi.object({
const actions = {
close: Joi.boolean(),

'close-reason': extendedJoi.closeReason().valid('completed', 'not_planned'),

reopen: Joi.boolean(),

lock: Joi.boolean(),
Expand Down Expand Up @@ -95,6 +113,7 @@ const actionSchema = Joi.object()
Joi.string().trim().max(51),
Joi.object().keys({
close: actions.close.default(false),
'close-reason': actions['close-reason'].default('completed'),
reopen: actions.reopen.default(false),
lock: actions.lock.default(false),
unlock: actions.unlock.default(false),
Expand Down

0 comments on commit 5155811

Please sign in to comment.