From 96097e8a65b1a3748fd29c2de58dc82dfde55227 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 24 May 2019 09:37:49 +0200 Subject: [PATCH] Re open issue with config flag --- README.md | 3 +++ lib/schema.js | 4 ++++ lib/stale.js | 23 +++++++++++++++++++++++ test/schema.test.js | 1 + 4 files changed, 31 insertions(+) diff --git a/README.md b/README.md index 3ecd06f..474f965 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,9 @@ markComment: > # closeComment: > # Your comment here. +# Set to true to reopen closed Issue or Pull Request on reply. +# reopenIssue: false (defaults to false) + # Limit the number of actions per hour, from 1-30. Default is 30 limitPerRun: 30 diff --git a/lib/schema.js b/lib/schema.js index d0586a7..592172b 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -38,6 +38,9 @@ const fields = { .error(() => '"closeComment" must be a string or false') .description('Comment to post when closing a stale Issue or Pull Request. Set to `false` to disable'), + reopenIssue: Joi.boolean() + .description('Set to true to reopen a stale Issue or Pull Request on reply'), + limitPerRun: Joi.number().integer().min(1).max(30) .error(() => '"limitPerRun" must be an integer between 1 and 30') .description('Limit the number of actions per hour, from 1-30. Default is 30') @@ -61,6 +64,7 @@ const schema = Joi.object().keys({ ), unmarkComment: fields.unmarkComment.default(false), closeComment: fields.closeComment.default(false), + reopenIssue: fields.reopenIssue.default(false), limitPerRun: fields.limitPerRun.default(30), perform: Joi.boolean().default(!process.env.DRY_RUN), only: Joi.any().valid('issues', 'pulls', null).description('Limit to only `issues` or `pulls`'), diff --git a/lib/stale.js b/lib/stale.js index c64c00c..f33dd2a 100644 --- a/lib/stale.js +++ b/lib/stale.js @@ -157,11 +157,30 @@ module.exports = class Stale { } } + async open (type, issue) { + if (this.remainingActions === 0) { + return + } + this.remainingActions-- + + const { owner, repo } = this.config + const perform = this.getConfigValue(type, 'perform') + const number = issue.number + + if (perform) { + this.logger.info('%s/%s#%d is being reopened', owner, repo, number) + return this.github.issues.edit({ owner, repo, number, state: 'open' }) + } else { + this.logger.info('%s/%s#%d would have been reopened (dry-run)', owner, repo, number) + } + } + async unmarkIssue (type, issue) { const { owner, repo } = this.config const perform = this.getConfigValue(type, 'perform') const staleLabel = this.getConfigValue(type, 'staleLabel') const unmarkComment = this.getConfigValue(type, 'unmarkComment') + const reopenIssue = this.getClosable(type, 'reopenIssue') const number = issue.number if (perform) { @@ -171,6 +190,10 @@ module.exports = class Stale { await this.github.issues.createComment({ owner, repo, number, body: unmarkComment }) } + if (reopenIssue) { + this.open(type, issue) + } + return this.github.issues.removeLabel({ owner, repo, number, name: staleLabel }).catch((err) => { // ignore if it's a 404 because then the label was already removed if (err.code !== 404) { diff --git a/test/schema.test.js b/test/schema.test.js index 10ea3d3..566616a 100644 --- a/test/schema.test.js +++ b/test/schema.test.js @@ -69,6 +69,7 @@ describe('schema', () => { exemptAssignees: false, staleLabel: 'wontfix', perform: true, + reopenIssue: false, markComment: 'Is this still relevant? If so, what is blocking it? ' + 'Is there anything you can do to help move it forward?' + '\n\nThis issue has been automatically marked as stale ' +