From f058ba4ff9d2290b95ab59beef1dae41b3fa94ee Mon Sep 17 00:00:00 2001 From: HANATANI Takuma Date: Tue, 5 Feb 2019 00:57:27 +0900 Subject: [PATCH] feat: Add 'assigned' label to pull request submitted issue (#24) * feat: Add 'assigned' label to pull request submitted issue * test: Change test label from test to invalid --- index.js | 2 ++ lib/github.js | 13 +++++++++++++ test/lib/github.js | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/index.js b/index.js index 5db23f1..3df3703 100644 --- a/index.js +++ b/index.js @@ -139,6 +139,8 @@ const after = async (item, shortHash, issueNo = null) => { Utility.log('S', `Created new pull request: ${pullRequest.html_url}`) await github.assignReviewers(remote, { number: pullRequest.number, reviewers: ['re-fort', 'kazupon', 'potato4d'] }) Utility.log('S', 'Assigned reviewers') + await github.addLabels(remote, { number: issueNo, labels: ['assigned'] }) + Utility.log('S', 'Added "assigned" label to issue') } process.on('unhandledRejection', err => { Utility.log('E', err) }) diff --git a/lib/github.js b/lib/github.js index a695950..80fa2e7 100644 --- a/lib/github.js +++ b/lib/github.js @@ -40,6 +40,19 @@ class GitHub { }) } + addLabels(remote, params = {}) { + return new Promise((resolve, reject) => { + this.github.issues.addLabels({ + owner: remote.upstream.owner, + repo: remote.upstream.name, + number: params.number, + labels: params.labels, + }) + .then(res => resolve(res)) + .catch(err => reject(err)) + }) + } + searchIssue(remote, params = {}) { return new Promise((resolve, reject) => { this.github.search.issues({ diff --git a/test/lib/github.js b/test/lib/github.js index c4c670e..4cfd6e2 100644 --- a/test/lib/github.js +++ b/test/lib/github.js @@ -42,6 +42,15 @@ describe('Github', function () { assert(closedIssue.state === 'closed') }) }) + + describe('createLabels()', function () { + it('creates new label', async function () { + const { data: newIssue } = await github.createIssue(remote, { title: 'Test', body: `Test\r\nOriginal:${url}`, labels: ['documentation'] }) + + const { data: result } = await github.addLabels(remote, { number: newIssue.number, labels: ['invalid'] }) + assert(result.length === 2) + }) + }) }) describe('pullRequest', function () {