Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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`'),
Expand Down
23 changes: 23 additions & 0 deletions lib/stale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down