Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
currently, this is a temporary stucture. But at least now the main code is more readable
- Loading branch information
1 parent
3c7338d
commit b9a2f2d
Showing
5 changed files
with
380 additions
and
257 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
var _ = require('lodash'); | ||
|
||
var breakingBad = { | ||
name: 'Breaking Bad', | ||
check: function(pullRequest, shall) { | ||
if (atLeast80PrecentCommitsFailedBuild(pullRequest)) { | ||
|
||
var achievement = { | ||
avatar : '//ca.audubon.org/sites/g/files/amh421/f/styles/bean_wysiwyg_full_width/public/blog/wp-content/uploads/2013/09/saul-150x150.jpg?itok=FmjiSkJL', | ||
name: 'Breaking Bad', | ||
short: 'Look, let\'s start with some tough love. You two suck at peddling meth. Period.', | ||
description: 'You merged a Pull Request with 5 or more commits with failing status', | ||
relatedPullRequest: pullRequest._id | ||
}; | ||
|
||
shall.grant(pullRequest.creator.username, achievement); | ||
} | ||
} | ||
}; | ||
|
||
function atLeast80PrecentCommitsFailedBuild(pullRequest) { | ||
var failedCommits = 0; | ||
var totalCommits = pullRequest.commits.length; | ||
_.forEach(pullRequest.commits, function(commit) { | ||
var prBuildStatus = commit.statuses['continuous-integration/travis-ci/pr']; | ||
var pushBuildStatus = commit.statuses['continuous-integration/travis-ci/push']; | ||
if ((prBuildStatus && _.isEqual(prBuildStatus.state, 'error')) || | ||
(pushBuildStatus && _.isEqual(pushBuildStatus.state, 'error'))) { | ||
failedCommits++; | ||
} | ||
}); | ||
|
||
return ((failedCommits / totalCommits) * 100) >= 80; | ||
} | ||
|
||
module.exports = breakingBad; |
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,44 @@ | ||
var _ = require('lodash'); | ||
var mongo = require('mongodb'); | ||
var monk = require('monk'); | ||
|
||
var url = process.env.MONGOLAB_URI; | ||
var db = monk(url); | ||
|
||
var collections = { | ||
repos: db.get('repos'), | ||
users: db.get('users') | ||
}; | ||
|
||
var achievibitDB = {}; | ||
|
||
initCollections(); | ||
|
||
achievibitDB.insertItem = insertItem; | ||
achievibitDB.updateItem = updateItem; | ||
achievibitDB.findItem = findItem; | ||
|
||
module.exports = achievibitDB; | ||
|
||
function initCollections() { | ||
collections.repos.index( { fullname: 1 }, { unique: true, sparse: true } ); | ||
collections.users.index( { username: 1 }, { unique: true, sparse: true } ); | ||
} | ||
|
||
function insertItem(collection, item) { | ||
if (_.isNil(collection) || _.isNil(item)) return; | ||
return collections[collection].insert(item); | ||
} | ||
|
||
function updateItem(collection, identityObject, updateWith) { | ||
if (_.isNil(collection) || _.isNil(identityObject) || _.isNil(updateWith)) { | ||
return; | ||
} | ||
|
||
return collections[collection].update(identityObject, updateWith); | ||
} | ||
|
||
function findItem(collection, identityObject) { | ||
if (_.isNil(collection) || _.isNil(identityObject)) return; | ||
return collections[collection].find(identityObject); | ||
} |
Oops, something went wrong.