Skip to content

Commit

Permalink
feat: also comment when issue is locked and set lock reason
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Jun 16, 2018
1 parent 898f52d commit 67fad24
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions src/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ module.exports = class Support {
return message;
}

async ensureUnlock(issue, lock, action) {
if (lock.active) {
if (!lock.hasOwnProperty('reason')) {
const {data: issueData} = await this.context.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 action();
if (lock.reason) {
issue = {
...issue,
lock_reason: lock.reason,
headers: {
Accept: 'application/vnd.github.sailor-v-preview+json'
}
};
}
await this.context.github.issues.lock(issue);
} else {
await action();
}
}

async labeled() {
if (!this.supportLabelTouched) {
return;
Expand All @@ -43,7 +71,7 @@ module.exports = class Support {
const {owner, repo} = issue;
const {perform, supportComment, close, lock} = this.config;

if (supportComment && !this.issueLocked) {
if (supportComment) {
this.log.info(
{owner, repo, issue: issue.number},
this.getLogMessage('Commenting')
Expand All @@ -53,10 +81,9 @@ module.exports = class Support {
/{issue-author}/,
payload.issue.user.login
);
await github.issues.createComment({
...issue,
body: commentBody
});
await this.ensureUnlock(issue, {active: this.issueLocked}, () =>
github.issues.createComment({...issue, body: commentBody})
);
}
}

Expand All @@ -66,10 +93,7 @@ module.exports = class Support {
this.getLogMessage('Closing')
);
if (perform) {
await github.issues.edit({
...issue,
state: 'closed'
});
await github.issues.edit({...issue, state: 'closed'});
}
}

Expand All @@ -79,7 +103,13 @@ module.exports = class Support {
this.getLogMessage('Locking')
);
if (perform) {
await github.issues.lock(issue);
await github.issues.lock({
...issue,
lock_reason: 'off-topic',
headers: {
Accept: 'application/vnd.github.sailor-v-preview+json'
}
});
}
}
}
Expand All @@ -100,10 +130,7 @@ module.exports = class Support {
this.getLogMessage('Opening')
);
if (perform) {
await github.issues.edit({
...issue,
state: 'open'
});
await github.issues.edit({...issue, state: 'open'});
}
}

Expand Down Expand Up @@ -134,10 +161,7 @@ module.exports = class Support {
this.getLogMessage('Unlabeling')
);
if (perform) {
await github.issues.removeLabel({
...issue,
name: supportLabel
});
await github.issues.removeLabel({...issue, name: supportLabel});
}
}

Expand Down

0 comments on commit 67fad24

Please sign in to comment.