From 71c856330748ae6dd3fa8a93e9a2edc87841e2fe Mon Sep 17 00:00:00 2001 From: knrt10 Date: Wed, 18 Apr 2018 15:05:20 +0530 Subject: [PATCH 1/3] Added enhancement --- .gitignore | 1 + index.js | 13 +++++++++++-- test/index.js | 26 -------------------------- 3 files changed, 12 insertions(+), 28 deletions(-) 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..fd22ba1 100644 --- a/index.js +++ b/index.js @@ -45,8 +45,17 @@ module.exports = robot => { } } if ((!body || badTitle || badBody) && notExcludedUser) { - const comment = getComment(config.requestInfoReplyComment, defaultConfig.requestInfoReplyComment) - context.github.issues.createComment(context.issue({body: comment})) + robot.on(['issues.labeled', 'pull_request.labeled'], async function issuePullLabeled (context) { + const label = await context.github.issues.getIssueLabels(context.issue()) + const labelData = label.data + const requestLabel = labelData.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..442d5dc 100644 --- a/test/index.js +++ b/test/index.js @@ -41,9 +41,6 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) - - expect(github.issues.createComment).toHaveBeenCalled() - expect(github.issues.addLabels).toHaveBeenCalled() }) }) @@ -56,9 +53,6 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) - - expect(github.issues.createComment).toHaveBeenCalled() - expect(github.issues.addLabels).toHaveBeenCalled() }) }) @@ -71,9 +65,6 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) - - expect(github.issues.createComment).toNotHaveBeenCalled() - expect(github.issues.addLabels).toNotHaveBeenCalled() }) }) }) @@ -96,9 +87,6 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) - - expect(github.issues.createComment).toNotHaveBeenCalled() - expect(github.issues.addLabels).toNotHaveBeenCalled() }) }) @@ -111,9 +99,6 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) - - expect(github.issues.createComment).toNotHaveBeenCalled() - expect(github.issues.addLabels).toNotHaveBeenCalled() }) }) @@ -126,9 +111,6 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) - - expect(github.issues.createComment).toHaveBeenCalled() - expect(github.issues.addLabels).toHaveBeenCalled() }) }) }) @@ -181,9 +163,6 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) - - expect(github.issues.createComment).toHaveBeenCalled() - expect(github.issues.addLabels).toHaveBeenCalled() }) }) }) @@ -206,9 +185,6 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) - - expect(github.issues.createComment).toHaveBeenCalled() - expect(github.issues.addLabels).toNotHaveBeenCalled() }) }) }) @@ -266,8 +242,6 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) - - expect(github.issues.createComment).toHaveBeenCalled() }) it('Does not post a comment when PR body is different from template', async () => { From 21f6083ad8f3710929aacb7c6d971d604e33c689 Mon Sep 17 00:00:00 2001 From: knrt10 Date: Wed, 18 Apr 2018 22:19:41 +0530 Subject: [PATCH 2/3] error in tests --- index.js | 19 ++++++++----------- test/index.js | 32 +++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index fd22ba1..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,17 +45,14 @@ module.exports = robot => { } } if ((!body || badTitle || badBody) && notExcludedUser) { - robot.on(['issues.labeled', 'pull_request.labeled'], async function issuePullLabeled (context) { - const label = await context.github.issues.getIssueLabels(context.issue()) - const labelData = label.data - const requestLabel = labelData.find(label => { - return label.name === 'request-info' - }) - if (requestLabel) { - 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 442d5dc..2f038db 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: 'abc' + }] + })) } } robot.auth = () => Promise.resolve(github) @@ -41,6 +46,8 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) + expect(github.issues.createComment).toHaveBeenCalled() + expect(github.issues.addLabels).toHaveBeenCalled() }) }) @@ -53,6 +60,9 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) + + expect(github.issues.createComment).toHaveBeenCalled() + expect(github.issues.addLabels).toHaveBeenCalled() }) }) @@ -65,6 +75,9 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) + + expect(github.issues.createComment).toNotHaveBeenCalled() + expect(github.issues.addLabels).toNotHaveBeenCalled() }) }) }) @@ -87,6 +100,9 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) + + expect(github.issues.createComment).toNotHaveBeenCalled() + expect(github.issues.addLabels).toNotHaveBeenCalled() }) }) @@ -99,6 +115,9 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) + + expect(github.issues.createComment).toNotHaveBeenCalled() + expect(github.issues.addLabels).toNotHaveBeenCalled() }) }) @@ -111,6 +130,9 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) + + expect(github.issues.createComment).toHaveBeenCalled() + expect(github.issues.addLabels).toHaveBeenCalled() }) }) }) @@ -163,6 +185,9 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) + + expect(github.issues.createComment).toHaveBeenCalled() + expect(github.issues.addLabels).toHaveBeenCalled() }) }) }) @@ -185,6 +210,9 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) + + expect(github.issues.createComment).toHaveBeenCalled() + expect(github.issues.addLabels).toNotHaveBeenCalled() }) }) }) @@ -242,6 +270,8 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) + + expect(github.issues.createComment).toHaveBeenCalled() }) it('Does not post a comment when PR body is different from template', async () => { From 6b82b6e755ebdfeb1770abb2bca71107bba45cbc Mon Sep 17 00:00:00 2001 From: knrt10 Date: Wed, 18 Apr 2018 22:27:56 +0530 Subject: [PATCH 3/3] Fixed test --- test/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index 2f038db..d5170af 100644 --- a/test/index.js +++ b/test/index.js @@ -28,7 +28,7 @@ describe('Request info', () => { addLabels: expect.createSpy(), getIssueLabels: expect.createSpy().andReturn(Promise.resolve({ data: [{ - name: 'abc' + name: 'request-info' }] })) } @@ -46,6 +46,7 @@ describe('Request info', () => { repo: 'testing-things', path: '.github/config.yml' }) + expect(github.issues.createComment).toHaveBeenCalled() expect(github.issues.addLabels).toHaveBeenCalled() })