Skip to content

Commit

Permalink
feat: add option for setting lock reason
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Jun 24, 2018
1 parent eb1e76d commit e91b1c8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ that comments on and closes issues labeled as support requests.

## Supporting the Project

The ongoing development of Support Requests is made possible
The continued development of Support Requests is made possible
thanks to the support of awesome backers. If you'd like to join them,
please consider contributing with [Patreon](https://goo.gl/qRhKSW),
[PayPal](https://goo.gl/5FnBaw) or [Bitcoin](https://goo.gl/uJUAaU).
Expand Down Expand Up @@ -42,6 +42,9 @@ close: true
# Lock issues marked as support requests
lock: false

# Assign `off-topic` as the reason for locking. Set to `false` to disable
setLockReason: true

# Repository to extend settings from
# _extends: repo
```
Expand Down
5 changes: 4 additions & 1 deletion assets/app-description.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ close: true
# Lock issues marked as support requests
lock: false

# Assign `off-topic` as the reason for locking. Set to `false` to disable
setLockReason: true

# Repository to extend settings from
# _extends: repo
```

## Supporting the Project

The ongoing development of Support Requests is made possible thanks to the support of awesome backers. If you'd like to join them, please consider contributing with [Patreon](https://goo.gl/qRhKSW), [PayPal](https://goo.gl/5FnBaw) or [Bitcoin](https://goo.gl/uJUAaU).
The continued development of Support Requests is made possible thanks to the support of awesome backers. If you'd like to join them, please consider contributing with [Patreon](https://goo.gl/qRhKSW), [PayPal](https://goo.gl/5FnBaw) or [Bitcoin](https://goo.gl/uJUAaU).
6 changes: 6 additions & 0 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ const schema = Joi.object().keys({
.default(false)
.description('Lock issues marked as support requests'),

setLockReason: Joi.boolean()
.default(true)
.description(
'Assign `off-topic` as the reason for locking. Set to `false` to disable'
),

_extends: Joi.string().description('Repository to extend settings from'),

perform: Joi.boolean().default(!process.env.DRY_RUN)
Expand Down
29 changes: 18 additions & 11 deletions src/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ module.exports = class Support {
}

async ensureUnlock(issue, lock, action) {
const github = this.context.github;
if (lock.active) {
if (!lock.hasOwnProperty('reason')) {
const {data: issueData} = await this.context.github.issues.get({
const {data: issueData} = await github.issues.get({
...issue,
headers: {
Accept: 'application/vnd.github.sailor-v-preview+json'
}
});
lock.reason = issueData.active_lock_reason;
}
await this.context.github.issues.unlock(issue);
await github.issues.unlock(issue);
await action();
if (lock.reason) {
issue = {
Expand All @@ -49,7 +50,7 @@ module.exports = class Support {
}
};
}
await this.context.github.issues.lock(issue);
await github.issues.lock(issue);
} else {
await action();
}
Expand All @@ -62,7 +63,7 @@ module.exports = class Support {

const {payload, github} = this.context;
const issue = this.context.issue();
const {perform, supportComment, close, lock} = this.config;
const {perform, supportComment, close, lock, setLockReason} = this.config;
const meta = {issue, perform};

if (supportComment) {
Expand All @@ -88,13 +89,19 @@ module.exports = class Support {
if (lock && !this.issueLocked) {
this.log.info(meta, 'Locking');
if (perform) {
await github.issues.lock({
...issue,
lock_reason: 'off-topic',
headers: {
Accept: 'application/vnd.github.sailor-v-preview+json'
}
});
let params;
if (setLockReason) {
params = {
...issue,
lock_reason: 'off-topic',
headers: {
Accept: 'application/vnd.github.sailor-v-preview+json'
}
};
} else {
params = issue;
}
await github.issues.lock(params);
}
}
}
Expand Down

0 comments on commit e91b1c8

Please sign in to comment.