Skip to content

Commit

Permalink
[ACHIEVEMENT] helping hand (#35)
Browse files Browse the repository at this point in the history
* fixed typo && pullrequest reviewers reference

* added WebStrom ".idea" files to .gitignore (as in Kibibit code-editor)

* added "Helping Hand" achievement

* changed commit.creator to commit author and _.includes to _.find

* added commiter achievement in addition to reviewer achievement

* added reviewer(s) name(s) to committer achievement and vice versa

* changing _.find to the right syntax

* general fixes for helping hand achievement

- don't give the creator the reviewer's achievement
- remove the brackets for `isMultipleCommittedReviewers`
- fix usernames in each other's achievements

* add reviewers to the allPRUsers variable
  • Loading branch information
ortichon committed Jan 27, 2017
1 parent 9bd8dd2 commit 89b8492
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,3 +1,4 @@

node_modules/
logs/
logs/
.idea/
2 changes: 1 addition & 1 deletion achievements/doubleReview.achievement.js
Expand Up @@ -9,7 +9,7 @@ var doubleReview = {
avatar : 'images/achievements/doubleReview.achievement.gif',
name : 'We\'re ready, master',
short : _.escape('"This way!"-"No, that way!"'),
description : 'double headed code review.<br>It doesn\'t matter who added you, apperantly, both of you are needed for a one man job 😇',
description : 'double headed code review.<br>It doesn\'t matter who added you, apparently, both of you are needed for a one man job 😇',
relatedPullRequest: pullRequest.id
};

Expand Down
58 changes: 58 additions & 0 deletions achievements/helpingHand.achievement.js
@@ -0,0 +1,58 @@
var _ = require('lodash');

var helpingHand = {
name: 'Helping Hand',
check: function(pullRequest, shall) {
var committedReviewers = reviewersWhoCommittedToPullRequest(pullRequest);

if (!_.isEmpty(committedReviewers)) {

var isMultipleCommittedReviewers = committedReviewers.length > 1 ? 's ' : ' ';

var reviewerAchievement = {
avatar: 'images/achievements/helpingHandHelloThere.achievement.jpg',
name: 'Helping Hand',
short: 'Hello there. Slow going?',
description: [
'You\'ve committed to ', pullRequest.creator.username,
'\'s Pull Request you are reviewing'
].join(''),
relatedPullRequest: pullRequest._id
};

var committerAchievement = {
avatar: 'images/achievements/helpingHandManInBlack.achievement.jpg',
name: 'Helping Hand',
short: 'Look, I don\'t mean to be rude but this is not as easy as it looks',
description: [
'Your reviewer', isMultipleCommittedReviewers,
_.map(committedReviewers, 'username').join(', '),
' committed to your Pull Request'
].join(''),
relatedPullRequest: pullRequest._id
};

_.forEach(committedReviewers, function(reviewer) {
shall.grant(reviewer.username, reviewerAchievement);
});

shall.grant(pullRequest.creator.username, committerAchievement);
}
}
};


function reviewersWhoCommittedToPullRequest(pullRequest) {
var committedReviewers = [];

_.forEach(pullRequest.commits, function(commit) {
if (commit.author.username !== pullRequest.creator.username &&
_.find(pullRequest.reviewers, {username: commit.author.username})) {
committedReviewers.push(commit.author);
}
});

return committedReviewers;
}

module.exports = helpingHand;
2 changes: 1 addition & 1 deletion achievements/neverGoFullRetard.achievement.js
Expand Up @@ -14,7 +14,7 @@ var neverGoFullRetard = {
relatedPullRequest: pullRequest.id
};
shall.grant(pullRequest.creator.username, achieve);
_.forEach(pullRequest.reviewer, function(reviewer) {
_.forEach(pullRequest.reviewers, function(reviewer) {
shall.grant(reviewer.username, achieve);
});
}
Expand Down
2 changes: 1 addition & 1 deletion eventManager.js
Expand Up @@ -292,7 +292,7 @@ var EventManager = function() {

var allPRUsers = [pullRequests[id].creator];
if (_.isArray(pullRequests[id].reviewers)) {
allPRUsers.concat(pullRequests[id].reviewers);
allPRUsers = allPRUsers.concat(pullRequests[id].reviewers);
}
grantAchievements(allPRUsers, pullRequests[id], io);
});
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 89b8492

Please sign in to comment.