Skip to content

Commit

Permalink
Merge pull request #19 from Kibibit/start-splitting-up-event-manager
Browse files Browse the repository at this point in the history
splitting things up
  • Loading branch information
thatkookooguy committed Jan 12, 2017
2 parents 3c7338d + b9a2f2d commit 9b1761a
Show file tree
Hide file tree
Showing 5 changed files with 380 additions and 257 deletions.
36 changes: 36 additions & 0 deletions achievements/breakingBad.achievement.js
@@ -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;
44 changes: 44 additions & 0 deletions achievibitDB.js
@@ -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);
}

0 comments on commit 9b1761a

Please sign in to comment.