feat: set close reason

Closes #22.
This commit is contained in:
dessant
2023-06-08 12:57:56 +03:00
parent 9433de6dd5
commit 515581124b
3 changed files with 35 additions and 2 deletions

View File

@@ -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
@@ -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
@@ -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:

View File

@@ -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
@@ -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

View File

@@ -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};
}
}
@@ -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(),
@@ -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),