diff --git a/.gitignore b/.gitignore index 03687377..2dcf22df 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ monkeyDB.json mochawesome-report/ -privateConfig.json \ No newline at end of file +privateConfig.json +package-lock.json +yarn.lock diff --git a/README.md b/README.md index 38b240a6..a6cc395c 100644 --- a/README.md +++ b/README.md @@ -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 :-)** diff --git a/achievements/cuttingEdges.achievement.js b/achievements/cuttingEdges.achievement.js new file mode 100644 index 00000000..ddd353a5 --- /dev/null +++ b/achievements/cuttingEdges.achievement.js @@ -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; diff --git a/public/images/achievements/cuttingEdges.achievement.jpeg b/public/images/achievements/cuttingEdges.achievement.jpeg new file mode 100644 index 00000000..fa90f959 Binary files /dev/null and b/public/images/achievements/cuttingEdges.achievement.jpeg differ diff --git a/test/cuttingEdges.specs.js b/test/cuttingEdges.specs.js new file mode 100644 index 00000000..d6003bd7 --- /dev/null +++ b/test/cuttingEdges.specs.js @@ -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' + } + }; +}