Skip to content

Commit

Permalink
feat(achievements): cutting edge (#171)
Browse files Browse the repository at this point in the history
* Add cutting edge tests and achievement

* Untrack yarn lock

* Update README

* Rename achievement to Cutting Edges because it sounds more dangerous
  • Loading branch information
andrearosr authored and thatkookooguy committed Apr 12, 2021
1 parent 2631e44 commit 046425b
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ monkeyDB.json

mochawesome-report/

privateConfig.json
privateConfig.json
package-lock.json
yarn.lock
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
4. click on ***add webhook***
5. paste achievibit's url (`http://achievibit.kibibit.io`) into the ***payload url***
6. change ***Content type*** to `application/json`
7. on ***Which events would you like to trigger this webhook?***, select `Let me select individual events.` and check `Pull request`
7. on ***Which events would you like to trigger this webhook?***, select `Let me select individual events.` and check `Pull request` and `Pull request reviews`

**Maybe sometime later we'll also support repo achievements. open an issue if you're interested :-)**

Expand Down
26 changes: 26 additions & 0 deletions achievements/cuttingEdges.achievement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var _ = require('lodash');

var cuttingEdge = {
name: 'Cutting Edges',
check: function(pullRequest, shall) {
if (pullRequest.merged) {
const anyApprovals = _.some(pullRequest.reviews, function(review) {
return review.state === 'APPROVED';
});

if (!anyApprovals) {
var achieve = {
avatar: 'images/achievements/cuttingEdges.achievement.jpg',
name: 'Cutting Edges',
short: 'Cutting corners? I also like to live dangerously',
description: 'You\'ve merged a pull request without a reviewer confirming',
relatedPullRequest: pullRequest.id
};

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

module.exports = cuttingEdge;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions test/cuttingEdges.specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
var cuttingEdge =
require('../achievements/cuttingEdges.achievement');
var expect = require('chai').expect;

describe('Cutting Edges achievement', function() {
it('should not be granted if pull request is not merged', function() {
var testShall = new Shall();
var pullRequest = new PullRequest();

cuttingEdge.check(pullRequest, testShall);
expect(testShall.grantedToUsername).to.not.exist;
expect(testShall.grantedAchievement).to.not.exist;
});

it('should not be granted if pull request was merged with approvals', function() {
var testShall = new Shall();
var pullRequest = new PullRequest();

pullRequest.merged = true;
pullRequest.reviews = [
{
id: 'review',
state: 'APPROVED',
}
];

cuttingEdge.check(pullRequest, testShall);
expect(testShall.grantedToUsername).to.not.exist;
expect(testShall.grantedAchievement).to.not.exist;
});

it('should be granted if pull request was merged without approvals', function() {
var testShall = new Shall();
var pullRequest = new PullRequest();

pullRequest.merged = true;
pullRequest.reviews = [];

cuttingEdge.check(pullRequest, testShall);
expect(testShall.grantedToUsername).to.be.a('string');
expect(testShall.grantedToUsername).to.equal('creator');
expect(testShall.grantedAchievement).to.be.an('object');
});
});

function Shall() {
var self = this;

self.grantedAchievement = undefined;
self.grantedToUsername = undefined;

self.grant = function(username, achievementObject) {
self.grantedToUsername = username;
self.grantedAchievement = achievementObject;
};
}

function PullRequest() {
return {
'title': 'this is a happy little title',
'id': 'test',
'url': 'url',
'description': '',
'creator': {
'username': 'creator'
}
};
}

0 comments on commit 046425b

Please sign in to comment.