diff --git a/.gitignore b/.gitignore index 31dcb22..34d7ffc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules *.pem .DS_Store +package-lock.json diff --git a/index.js b/index.js index 9458b88..49267f8 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const defaultConfig = require('./lib/defaultConfig') const PullRequestBodyChecker = require('./lib/PullRequestBodyChecker') module.exports = robot => { - robot.on(['pull_request.opened', 'issues.opened'], receive) + robot.on(['pull_request.opened', 'issues.opened', 'issues.labeled', 'pull_request.labeled'], receive) async function receive (context) { let title let body @@ -45,8 +45,14 @@ module.exports = robot => { } } if ((!body || badTitle || badBody) && notExcludedUser) { - const comment = getComment(config.requestInfoReplyComment, defaultConfig.requestInfoReplyComment) - context.github.issues.createComment(context.issue({body: comment})) + const label = await context.github.issues.getIssueLabels(context.issue()) + const requestLabel = label.data.find(label => { + return label.name === 'request-info' + }) + if (requestLabel) { + const comment = getComment(config.requestInfoReplyComment, defaultConfig.requestInfoReplyComment) + context.github.issues.createComment(context.issue({body: comment})) + } if (config.requestInfoLabelToAdd) { // Add label if there is one listed in the yaml file diff --git a/test/index.js b/test/index.js index d4dc3b3..d5170af 100644 --- a/test/index.js +++ b/test/index.js @@ -25,7 +25,12 @@ describe('Request info', () => { }, issues: { createComment: expect.createSpy(), - addLabels: expect.createSpy() + addLabels: expect.createSpy(), + getIssueLabels: expect.createSpy().andReturn(Promise.resolve({ + data: [{ + name: 'request-info' + }] + })) } } robot.auth = () => Promise.resolve(github)