From 41f458f8e50b240d454e7588187d0a671a7b51b3 Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Tue, 9 Oct 2018 20:11:08 -0400 Subject: [PATCH 1/8] Add tests --- test/index.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index d4dc3b3..bdb2f32 100644 --- a/test/index.js +++ b/test/index.js @@ -25,7 +25,8 @@ describe('Request info', () => { }, issues: { createComment: expect.createSpy(), - addLabels: expect.createSpy() + addLabels: expect.createSpy(), + create: expect.createSpy() } } robot.auth = () => Promise.resolve(github) @@ -327,4 +328,30 @@ describe('Request info', () => { }) }) }) + + describe('open issue on installation', () => { + let event + + beforeEach(() => { + event = { + event: 'installation_repositories', + payload: { + action: 'added', + installation: { account: { login: 'BEXO' } }, + repositories_added: [{ name: 'introduction-to-github-apps' }] + } + } + }) + + it('opens a new issue', async () => { + await robot.receive(event) + expect(github.issues.create).toHaveBeenCalled() + }) + + it('does not open a new issue if the repo name is not right', async () => { + event.payload.repositories_added = [] + await robot.receive(event) + expect(github.issues.create).toNotHaveBeenCalled() + }) + }) }) From ec91d4df130fcc4c01149c5d8c110df81b9f5868 Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Tue, 9 Oct 2018 20:11:13 -0400 Subject: [PATCH 2/8] Add handler --- index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.js b/index.js index 2bae04f..d95ce16 100644 --- a/index.js +++ b/index.js @@ -60,4 +60,18 @@ module.exports = robot => { } } } + + // Say hi! + const NAME = 'introduction-to-github-apps' + robot.on('installation_repositories.added', async context => { + const includes = context.payload.repositories_added.some(r => r.name === NAME) + if (!includes) return + + return context.github.issues.create({ + owner: context.payload.installation.account.login, + repo: NAME, + title: 'Great job installing WIP!', + body: 'Some body' + }) + }) } From 462e78575c574dead59ff7a2be403664e3d9a5ab Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Wed, 10 Oct 2018 01:15:47 -0400 Subject: [PATCH 3/8] Comment instead of create an issue --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d95ce16..2f7e491 100644 --- a/index.js +++ b/index.js @@ -67,11 +67,11 @@ module.exports = robot => { const includes = context.payload.repositories_added.some(r => r.name === NAME) if (!includes) return - return context.github.issues.create({ + return context.github.issues.createComment({ owner: context.payload.installation.account.login, repo: NAME, - title: 'Great job installing WIP!', - body: 'Some body' + number: 2. + body: 'Well done! You successfully installed the request info app.\n\n_disclaimer_ If you use this app in future repos, you won\'t get a message like this. This is just for Learning Lab!' }) }) } From af149d9e681c2cdb52013aff1e966fedfcf993fe Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Wed, 10 Oct 2018 01:16:51 -0400 Subject: [PATCH 4/8] Fix tests --- test/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/index.js b/test/index.js index bdb2f32..7752911 100644 --- a/test/index.js +++ b/test/index.js @@ -25,8 +25,7 @@ describe('Request info', () => { }, issues: { createComment: expect.createSpy(), - addLabels: expect.createSpy(), - create: expect.createSpy() + addLabels: expect.createSpy() } } robot.auth = () => Promise.resolve(github) @@ -345,13 +344,13 @@ describe('Request info', () => { it('opens a new issue', async () => { await robot.receive(event) - expect(github.issues.create).toHaveBeenCalled() + expect(github.issues.createComment).toHaveBeenCalled() }) it('does not open a new issue if the repo name is not right', async () => { event.payload.repositories_added = [] await robot.receive(event) - expect(github.issues.create).toNotHaveBeenCalled() + expect(github.issues.createComment).toNotHaveBeenCalled() }) }) }) From e6e120a3b99ce0eb7011374455b591dd93e6ae5b Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Wed, 10 Oct 2018 01:18:36 -0400 Subject: [PATCH 5/8] Whoops typo --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2f7e491..8309114 100644 --- a/index.js +++ b/index.js @@ -70,7 +70,7 @@ module.exports = robot => { return context.github.issues.createComment({ owner: context.payload.installation.account.login, repo: NAME, - number: 2. + number: 2, body: 'Well done! You successfully installed the request info app.\n\n_disclaimer_ If you use this app in future repos, you won\'t get a message like this. This is just for Learning Lab!' }) }) From 8387cdd303c36e3bb46486a043576ae1a20a02ac Mon Sep 17 00:00:00 2001 From: Bex Warner Date: Wed, 10 Oct 2018 01:23:17 -0400 Subject: [PATCH 6/8] follow functions pattern --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8309114..4923d55 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ const PullRequestBodyChecker = require('./lib/PullRequestBodyChecker') const getConfig = require('probot-config') module.exports = robot => { + robot.on('installation_repositories.added', learningLabWelcome) robot.on(['pull_request.opened', 'issues.opened'], receive) async function receive (context) { let title @@ -63,7 +64,7 @@ module.exports = robot => { // Say hi! const NAME = 'introduction-to-github-apps' - robot.on('installation_repositories.added', async context => { + async function learningLabWelcome (context) { const includes = context.payload.repositories_added.some(r => r.name === NAME) if (!includes) return From aece18f3d0ccf5bcf59a8aee3e0065292ee84f38 Mon Sep 17 00:00:00 2001 From: Bex Warner Date: Wed, 10 Oct 2018 01:25:02 -0400 Subject: [PATCH 7/8] lol this is what i get for editting in the browser --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4923d55..9969ee9 100644 --- a/index.js +++ b/index.js @@ -74,5 +74,5 @@ module.exports = robot => { number: 2, body: 'Well done! You successfully installed the request info app.\n\n_disclaimer_ If you use this app in future repos, you won\'t get a message like this. This is just for Learning Lab!' }) - }) + } } From 06f57aec82b58998c8bf0c627e4fc8eb9fb7f588 Mon Sep 17 00:00:00 2001 From: Bex Warner Date: Wed, 10 Oct 2018 01:27:20 -0400 Subject: [PATCH 8/8] make test more clear --- test/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index 7752911..e812579 100644 --- a/test/index.js +++ b/test/index.js @@ -348,7 +348,7 @@ describe('Request info', () => { }) it('does not open a new issue if the repo name is not right', async () => { - event.payload.repositories_added = [] + event.payload.repositories_added = [{ name: 'NOT-introduction-to-github-apps' }] await robot.receive(event) expect(github.issues.createComment).toNotHaveBeenCalled() })