Skip to content

Commit

Permalink
add github client support for filtering out commit authors
Browse files Browse the repository at this point in the history
resolve #7
  • Loading branch information
imsky committed Sep 13, 2017
1 parent f398527 commit 054a4f7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .pull-review
Expand Up @@ -28,6 +28,8 @@ reviewers:
slack: bsmith
charlie:
slack: cwilliams
dee:
slack: dwhite

# list of users who will never be notified
review_blacklist:
Expand All @@ -38,4 +40,4 @@ review_path_fallbacks:
app/web:
- alice
app/api:
- bob
- bob
13 changes: 13 additions & 0 deletions src/github/index.js
Expand Up @@ -143,9 +143,22 @@ function getPullRequest(options) {
return github.pullRequests.get(options);
}

function getPullRequestCommits(resource) {
return github.pullRequests.getCommits({
'owner': resource.owner,
'repo': resource.repo,
'number': resource.number,
'per_page': 100
})
.then(function (res) {
return res.data;
});
}

module.exports = {
'getPullRequest': getPullRequest,
'getPullRequestFiles': getPullRequestFiles,
'getPullRequestCommits': getPullRequestCommits,
'getBlameForCommitFile': getBlameForCommitFile,
'getRepoFile': getRepoFile,
'assignUsersToPullRequest': assignUsersToPullRequest,
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Expand Up @@ -40,8 +40,8 @@ module.exports = function PullReview(options) {

var transaction = [];

actions = actions.map(Action)
.forEach(function (action) {
actions = actions.map(Action);
actions.forEach(function (action) {
switch (action.type) {
case 'ASSIGN_USERS_TO_PULL_REQUEST':
transaction.push(github.assignUsersToPullRequest(action.payload.pullRequest, action.payload.assignees));
Expand Down
2 changes: 1 addition & 1 deletion test/get-reviewers-test.js
Expand Up @@ -102,7 +102,7 @@ describe('#getReviewers', function () {
});
});

it.only('filters out all commit authors', function () {
it('filters out all commit authors', function () {
return getReviewers({
'config': {
'version': 2,
Expand Down
20 changes: 20 additions & 0 deletions test/integration-test.js
Expand Up @@ -33,6 +33,26 @@ describe('pull-review', function () {
});
});

it('filters out committers', function () {
githubMock({
'config': config,
'commits': [
{
'author': {
'login': 'bob'
}
}
]
});
return pullReview({
'pullRequestURL': 'https://github.com/OWNER/REPO/pull/1'
})
.then(function (actions) {
actions.should.have.lengthOf(2);
actions[0].payload.assignees.should.not.include('bob');
});
})

it('fails with invalid arguments', function () {
(function () { pullReview(); }).should.throw('Invalid input: either a review request or a Hubot reference must be provided');
});
Expand Down
12 changes: 6 additions & 6 deletions test/mocks/github.js
Expand Up @@ -66,13 +66,11 @@ module.exports = function (options) {
function mockPullRequestCommits(options) {
var number = options.number || 1;

api.get('/repos/OWNER/REPO/pulls/' + number + '/commits')
api.get('/repos/OWNER/REPO/pulls/' + number + '/commits?per_page=100')
.reply(200, options.commits || [
{
'commit': {
'author': {
'login': 'alice'
}
'author': {
'login': 'alice'
}
}
]);
Expand All @@ -89,6 +87,7 @@ module.exports = function (options) {

api.post('/repos/OWNER/REPO/issues/1/comments', "{\"body\":\"@bob: please review this pull request.\\n\\n> Powered by [pull-review](https://github.com/imsky/pull-review)\"}\n").reply(200);
api.post('/repos/OWNER/REPO/issues/2/comments', "{\"body\":\"@bob: please review this pull request.\\n\\n> Powered by [pull-review](https://github.com/imsky/pull-review)\"}\n").reply(200);
api.post('/repos/OWNER/REPO/issues/1/comments', "{\"body\":\"@dee: please review this pull request.\\n\\n> Powered by [pull-review](https://github.com/imsky/pull-review)\"}\n").reply(200);

mockPullRequest({
'number': 1,
Expand All @@ -110,7 +109,8 @@ module.exports = function (options) {
});

mockPullRequestCommits({
'number': 1
'number': 1,
'commits': options.commits
});

mockPullRequestCommits({
Expand Down

0 comments on commit 054a4f7

Please sign in to comment.