diff --git a/README.md b/README.md index 9497c43..fa17c5d 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/index.js b/src/index.js index b5fb23b..7010077 100644 --- a/src/index.js +++ b/src/index.js @@ -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 diff --git a/src/schema.js b/src/schema.js index d4f2bf5..834d4f6 100644 --- a/src/schema.js +++ b/src/schema.js @@ -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),