Skip to content

Commit

Permalink
👍 Assign reviewers automatically when creating a pull request(#4)
Browse files Browse the repository at this point in the history
* 👍 Add reviewers automatically when creating a pull request

* 💚 Add tests
  • Loading branch information
re-fort committed Sep 28, 2017
1 parent f132d90 commit 4aca879
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ function removeHeadFeeder() {
headFeeder.destroy()
}


async function after(item, hash, shortHash) {
const { data: pullRequest } = await github.createPullRequest(remote, { title: item.title, body: `Cherry picked from ${item.link}`, branch: shortHash })
Utility.log('S', `Created new pull request: ${pullRequest.html_url}`)
await github.assignReviewers(remote, { number: pullRequest.number, reviewers: ['re-fort', 'kazupon'] })
Utility.log('S', 'Assigned reviewers')

const { messages } = await slack.searchMessages({ query: hash })
if (!messages) return
Expand Down
13 changes: 13 additions & 0 deletions lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ class GitHub {
.catch(err => reject(err))
})
}

assignReviewers(remote, params = {}) {
return new Promise((resolve, reject) => {
this.github.pullRequests.createReviewRequest({
owner: remote.upstream.owner,
repo: remote.upstream.name,
number: params.number,
reviewers: params.reviewers,
})
.then(res => resolve(res))
.catch(err => reject(err))
})
}
}

module.exports = GitHub
34 changes: 23 additions & 11 deletions test/lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,30 @@ describe('Github', function () {
},
}

let params = {
title: 'Pull request Test',
body: 'pull request Test',
branch: 'new-branch',
}
describe('pullRequest', function () {
let pullRequestNumber

describe('createPullRequest()', function () {
it('creates new pull request', async function () {
const { data: newPullRequest } = await github.createPullRequest(remote, { title: 'Test', body: 'Test', branch: 'new-branch' })
pullRequestNumber = newPullRequest.number
assert(newPullRequest.state === 'open')
})
})

describe('assignReviewers()', function () {
it('assigns reviewer(s)', async function () {
const { data: updatedPullRequest } = await github.assignReviewers(remote, { number: pullRequestNumber, reviewers: ['re-fort'] })
assert(updatedPullRequest.requested_reviewers.length === 1)
assert(updatedPullRequest.requested_reviewers[0].login === 're-fort')
})
})

describe('createPullRequest()', function () {
it('creates new pull request', async function () {
const { data: newPullRequest } = await github.createPullRequest(remote, params)
assert(newPullRequest.state === 'open')
const { data: closedPullRequest } = await github.closePullRequest(remote, { number: newPullRequest.number })
assert(closedPullRequest.state === 'closed')
describe('closePullRequest()', async function () {
it('closes opened pull request', async function () {
const { data: closedPullRequest } = await github.closePullRequest(remote, { number: pullRequestNumber })
assert(closedPullRequest.state === 'closed')
})
})
})
})

0 comments on commit 4aca879

Please sign in to comment.