Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions controllers/githubHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,15 @@ const HooksController = {
dbUpdated = dbManager.updateComment(comment);
}
} else if (event === "check_run") {
const state = utils.mapCheckToStatus(
body.check_run.conclusion || body.check_run.status
);
const conclusion = body.check_run.conclusion || body.check_run.status;
const state = utils.mapCheckToStatus(conclusion);

const status = new Status({
repo: body.repository.full_name,
sha: body.check_run.head_sha,
state: state,
context: body.check_run.name,
description: state,
description: conclusion,
target_url: body.check_run.html_url,
started_at: body.check_run.started_at,
completed_at: body.check_run.completed_at,
Expand Down
5 changes: 3 additions & 2 deletions lib/git-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ export default {
});

let checks = jobRuns.map(function (jobRun) {
let state = utils.mapCheckToStatus(jobRun.conclusion || jobRun.status);
let desc = state;
let conclusion = jobRun.conclusion || jobRun.status;
let state = utils.mapCheckToStatus(conclusion);
let desc = conclusion;
let url = jobRun.html_url;
let context = jobRun.name;

Expand Down
145 changes: 74 additions & 71 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,88 @@
import config from "./config-loader.js";
import Bluebird from "bluebird";
import _ from "underscore";
import config from './config-loader.js';
import Bluebird from 'bluebird';
import _ from 'underscore';

const Promise = global.Promise;

// Set the global Promise object up with the done method
Promise.prototype.done = function (callback) {
return Bluebird.cast(this).done(callback);
return Bluebird.cast(this).done(callback);
};

export default {
/**
* Converts `t` to a Unix timestamp from a Date object unless it's already
* a number.
*/
toUnixTime: function (date) {
const type = typeof date;
if (!date || type == "number") {
/**
* Converts `t` to a Unix timestamp from a Date object unless it's already
* a number.
*/
toUnixTime: function (date) {
const type = typeof date;
if (!date || type == 'number') {
return date;
}
if (type === 'object') {
return date.getTime() / 1000;
}
if (type === 'string') {
return Date.parse(date) / 1000;
}
return date;
}
if (type === "object") {
return date.getTime() / 1000;
}
if (type === "string") {
return Date.parse(date) / 1000;
}
return date;
},
},

/**
* Converts `t` to a Date object from a Unix timestamp unless it's not a
* number.
*/
fromUnixTime: function (t) {
return typeof t === "number" ? new Date(t * 1000) : t;
},
/**
* Converts `t` to a Date object from a Unix timestamp unless it's not a
* number.
*/
fromUnixTime: function (t) {
return typeof t === 'number' ? new Date(t * 1000) : t;
},

/**
* Converts `str` to a Date object from a Date string (or null).
* Returns null if str is falsy.
*/
fromDateString: function (str) {
return str ? (str instanceof Date ? str : new Date(str)) : null;
},
/**
* Converts `str` to a Date object from a Date string (or null).
* Returns null if str is falsy.
*/
fromDateString: function (str) {
return str ? (str instanceof Date ? str : new Date(str)) : null;
},

/**
* Provide a function that returns an array of values for a given repo.
* The second argument should be all arguments after the repository, since the
* repository argument will be dealt with by this function.
*
* The function should take a repository name, and return an array of values.
*/
forEachRepo: function (singleRepoLambda, args) {
// default value
args = args || [];
args.unshift(null);
var allRepoMap = function (currentRepo) {
args[0] = currentRepo.name;
return singleRepoLambda.apply(this, args);
};
return Promise.all(config.repos.map(allRepoMap)).then(function (repoItems) {
return _.flatten(repoItems, /* shallow */ true);
});
},
/**
* Provide a function that returns an array of values for a given repo.
* The second argument should be all arguments after the repository, since the
* repository argument will be dealt with by this function.
*
* The function should take a repository name, and return an array of values.
*/
forEachRepo: function (singleRepoLambda, args) {
// default value
args = args || [];
args.unshift(null);
var allRepoMap = function (currentRepo) {
args[0] = currentRepo.name;
return singleRepoLambda.apply(this, args);
};
return Promise.all(config.repos.map(allRepoMap)).then(function (repoItems) {
return _.flatten(repoItems, /* shallow */ true);
});
},

/**
* Statuses and checks have slightly different status names. Let's map the
* check values to match the status values.
*/
mapCheckToStatus: function (status) {
switch (status) {
case "in_progress":
case "queued":
return "pending";
case "success":
case "skipped":
return "success";
case "failure":
return "failure";
default:
return "error";
}
},
/**
* Statuses and checks have slightly different status names. Let's map the
* check values to match the status values.
*/
mapCheckToStatus: function (status) {
switch (status) {
case 'in_progress':
case 'queued':
return 'pending';
case 'success':
case 'skipped':
return 'success';
case 'failure':
case 'cancelled':
case 'timed_out':
case 'startup_failure':
return 'failure';
default:
return 'error';
}
},
};