Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created the achievement + tests + minor fixes to dontYellAtMe (#68)
- Loading branch information
1 parent
9a27b40
commit de390c5
Showing
5 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var _ = require('lodash'); | ||
|
||
var inspectorGadget = { | ||
name: 'Inspector Gadget', | ||
check: function(pullRequest, shall) { | ||
|
||
var coveragePercentageIncreased = coverageIncreased(pullRequest); | ||
|
||
if (coveragePercentageIncreased) { | ||
|
||
var achievement = { | ||
avatar: 'images/achievements/inspectorGadget.achievement.jpg', | ||
name: 'Inspector Gadget', | ||
short: [ | ||
'I\'m always careful, Penny. That\'s what makes me ', | ||
'a great inspector.' | ||
].join(''), | ||
description: [ | ||
'You\'ve increased your project coverage by ', | ||
coveragePercentageIncreased | ||
].join(''), | ||
relatedPullRequest: pullRequest.id | ||
}; | ||
|
||
shall.grant(pullRequest.creator.username, achievement); | ||
} | ||
} | ||
}; | ||
|
||
function coverageIncreased(pullRequest) { | ||
var lastCoverageUpdate = _.findLast(pullRequest.comments, | ||
['author.username', 'coveralls']); | ||
|
||
var lastCoverageUpdateMessage = _.get(lastCoverageUpdate, 'message'); | ||
var getIncreasedPercentageRegexp = /Coverage increased \((.*?)\)/g; | ||
var match = getIncreasedPercentageRegexp.exec(lastCoverageUpdateMessage); | ||
var percentageString = _.get(match, 1); | ||
var percentageNumberOnly = _.replace(percentageString, /[+%]/g, ''); | ||
|
||
return _.parseInt(percentageNumberOnly, 10) >= 2 ? percentageString : false; | ||
|
||
} | ||
|
||
module.exports = inspectorGadget; | ||
|
File renamed without changes
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
var inspectorGadget = | ||
require('../achievements/inspectorGadget.achievement'); | ||
var expect = require('chai').expect; | ||
|
||
var MESSAGE_INCREASED = [ | ||
'[![Coverage Status](https://coveralls.io/builds/10085689/badge)]', | ||
'(https://coveralls.io/builds/10085689)\n\nCoverage increased (+2.6%) to ', | ||
'39.32% when pulling **c07c2c6c1d5043fe4e916625ab3c537ca6d1b966 on ', | ||
'achievement-dont-yell-at-me** into ', | ||
'**ed92c7d04925ad4b4972c69b45daea5c595eb2a9 on master**.' | ||
].join(''); | ||
|
||
|
||
var MESSAGE_INCREASED_EVEN_MORE = [ | ||
'[![Coverage Status](https://coveralls.io/builds/10085689/badge)]', | ||
'(https://coveralls.io/builds/10085689)\n\nCoverage increased (+10.6%) to ', | ||
'39.32% when pulling **c07c2c6c1d5043fe4e916625ab3c537ca6d1b966 on ', | ||
'achievement-dont-yell-at-me** into ', | ||
'**ed92c7d04925ad4b4972c69b45daea5c595eb2a9 on master**.' | ||
].join(''); | ||
|
||
var MESSAGE_NOT_ENOUGH_INCREASED = [ | ||
'[![Coverage Status](https://coveralls.io/builds/10085689/badge)]', | ||
'(https://coveralls.io/builds/10085689)\n\nCoverage increased (+1.6%) to ', | ||
'39.32% when pulling **c07c2c6c1d5043fe4e916625ab3c537ca6d1b966 on ', | ||
'achievement-dont-yell-at-me** into ', | ||
'**ed92c7d04925ad4b4972c69b45daea5c595eb2a9 on master**.' | ||
].join(''); | ||
|
||
var MESSAGE_DECREASED = [ | ||
'[![Coverage Status](https://coveralls.io/builds/10076567/badge)]', | ||
'(https://coveralls.io/builds/10076567)\n\nCoverage decreased (-6.2%) to ', | ||
'31.285% when pulling **f63b4b15d94e67fbd37f58342d9899390ea05224 on ', | ||
'fix-port** into **e3ad341b991dc9bac57f50fc87a15113b7e62735 on master**.' | ||
].join(''); | ||
|
||
|
||
describe('inspectorGadget achievement', function() { | ||
it('should not be granted if comments undefined', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
inspectorGadget.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.not.exist; | ||
expect(testShall.grantedAchievement).to.not.exist; | ||
}); | ||
|
||
it('should not be granted if no comments', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.comments = []; | ||
|
||
inspectorGadget.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.not.exist; | ||
expect(testShall.grantedAchievement).to.not.exist; | ||
}); | ||
|
||
it('should not be granted if no coverall comments', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.comments = []; | ||
pullRequest.comments | ||
.push(createComment('inspector gadget', MESSAGE_INCREASED)); | ||
|
||
inspectorGadget.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.not.exist; | ||
expect(testShall.grantedAchievement).to.not.exist; | ||
}); | ||
|
||
it('should not be granted if coverage decreased', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.comments = []; | ||
pullRequest.comments | ||
.push(createComment('coveralls', MESSAGE_DECREASED)); | ||
|
||
inspectorGadget.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.not.exist; | ||
expect(testShall.grantedAchievement).to.not.exist; | ||
}); | ||
|
||
it('should not be granted if percentage lower than 2', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.comments = []; | ||
pullRequest.comments | ||
.push(createComment('coveralls', MESSAGE_NOT_ENOUGH_INCREASED)); | ||
|
||
inspectorGadget.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.not.exist; | ||
expect(testShall.grantedAchievement).to.not.exist; | ||
}); | ||
|
||
it('should be granted to PR creator if coverage increased by 2+', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.comments = []; | ||
pullRequest.comments | ||
.push(createComment('coveralls', MESSAGE_INCREASED)); | ||
|
||
inspectorGadget.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.be.a('string'); | ||
expect(testShall.grantedToUsername).to.equal('creator'); | ||
expect(testShall.grantedAchievement).to.be.an('object'); | ||
}); | ||
|
||
it('should parse only last coverall comment', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.comments = []; | ||
pullRequest.comments | ||
.push(createComment('coveralls', MESSAGE_DECREASED)); | ||
pullRequest.comments | ||
.push(createComment('coveralls', MESSAGE_INCREASED)); | ||
|
||
inspectorGadget.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.be.a('string'); | ||
expect(testShall.grantedToUsername).to.equal('creator'); | ||
expect(testShall.grantedAchievement).to.be.an('object'); | ||
}); | ||
|
||
it('should write in description last increased percentage', function() { | ||
var testShallBiggerLast = new Shall(); | ||
var testShallBiggerFirst = new Shall(); | ||
var pullRequestBiggerLast = new PullRequest(); | ||
var pullRequestBiggerFirst = new PullRequest(); | ||
|
||
pullRequestBiggerLast.comments = []; | ||
pullRequestBiggerLast.comments | ||
.push(createComment('coveralls', MESSAGE_INCREASED)); | ||
pullRequestBiggerLast.comments | ||
.push(createComment('coveralls', MESSAGE_INCREASED_EVEN_MORE)); | ||
|
||
pullRequestBiggerFirst.comments = []; | ||
pullRequestBiggerFirst.comments | ||
.push(createComment('coveralls', MESSAGE_INCREASED_EVEN_MORE)); | ||
pullRequestBiggerFirst.comments | ||
.push(createComment('coveralls', MESSAGE_INCREASED)); | ||
|
||
inspectorGadget.check(pullRequestBiggerLast, testShallBiggerLast); | ||
expect(testShallBiggerLast.grantedToUsername).to.be.a('string'); | ||
expect(testShallBiggerLast.grantedToUsername).to.equal('creator'); | ||
expect(testShallBiggerLast.grantedAchievement).to.be.an('object'); | ||
expect(testShallBiggerLast.grantedAchievement.description) | ||
.to.have.string('+10.6'); | ||
|
||
inspectorGadget.check(pullRequestBiggerFirst, testShallBiggerFirst); | ||
expect(testShallBiggerFirst.grantedToUsername).to.be.a('string'); | ||
expect(testShallBiggerFirst.grantedToUsername).to.equal('creator'); | ||
expect(testShallBiggerFirst.grantedAchievement).to.be.an('object'); | ||
expect(testShallBiggerFirst.grantedAchievement.description) | ||
.to.have.string('+2.6'); | ||
}); | ||
|
||
|
||
}); | ||
|
||
function createComment(username, message) { | ||
return { | ||
"author": { | ||
"username": username | ||
}, | ||
"message": message | ||
} | ||
} | ||
|
||
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' | ||
} | ||
}; | ||
} |