Skip to content

Commit

Permalink
Update code style
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Jul 25, 2016
1 parent ac6a055 commit f29c6fb
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 23 deletions.
8 changes: 5 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# Settings specific to Markdown files
[*.md]
trim_trailing_whitespace = false
[*.hbs]
insert_final_newline = false

[*.{diff,md}]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"semi": [2, "always"],
"comma-style": [2, "last"],
"one-var": [2, "never"],
"strict": [2, "global"],
"prefer-template": 2,
"no-console": 0,
"no-use-before-define": [2, "nofunc"],
"no-underscore-dangle": 0,
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var Runner = require('./lib');

function create(emitter, config, context, done) {
Expand Down
4 changes: 2 additions & 2 deletions lib/cachier.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ function cachier(base) {
function copy(from, to, done) {
fs.exists(from, function (exists) {
if (!exists) {
return done(new Error('Source does not exist: ' + from));
return done(new Error(`Source does not exist: ${from}`));
}

fs.remove(to, function () {
fs.mkdirp(path.dirname(to), function () {
fs.copy(from, to, function (err) {
return done(err && new Error('Failed to retrieve cached code: ' + err));
return done(err && new Error(`Failed to retrieve cached code: ${err}`));
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/consts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// constants and things
'use strict';

var phases = ['environment', 'prepare', 'test', 'deploy', 'cleanup'];

Expand Down
34 changes: 18 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var fs = require('fs-extra');
var path = require('path');

Expand All @@ -21,7 +23,7 @@ function t(time, done) {
done = time;
time = 2000;
}
var error = new Error('Callback took too long (max: ' + time + ')');
var error = new Error(`Callback took too long (max: ${time})`);
var waiting = true;

var timeout = setTimeout(function () {
Expand Down Expand Up @@ -78,7 +80,7 @@ function Runner(emitter, config) {
function initJobDirs(branchBase, job, cache, done) {
var dirs = {
base: branchBase,
data: path.join(branchBase, 'job-' + job._id.toString()),
data: path.join(branchBase, `job-${job._id.toString()}`),
cache: cache
};

Expand Down Expand Up @@ -183,15 +185,15 @@ Runner.prototype = {
this.jobdata.add(job);
this.queue.push(job, config);
this.emitter.emit('browser.update', job.project.name, 'job.status.queued', [job._id, now]);
debug('[runner:' + this.id + '] Queued new job. Project: ' + job.project.name + ' Job ID: ' + job._id);
debug(`[runner:${this.id}] Queued new job. Project: ${job.project.name} Job ID: ${job._id}`);
},

cancelJob: function (id) {
var jobdata;
for (var i = 0; i < this.queue.tasks.length; i++) {
if (this.queue.tasks[i].job._id.toString() === id.toString()) {
this.queue.tasks.splice(i, 1);
debug('[runner:' + this.id + '] Cancelled job. Job ID: ' + id);
debug(`[runner:${this.id}] Cancelled job. Job ID: ${id}`);
jobdata = this.jobdata.pop(id);
jobdata.errored = true;
jobdata.error = {
Expand All @@ -216,7 +218,7 @@ Runner.prototype = {
var tasks = [function (next) {
var plugin = self.extensions.provider[job.project.provider.id];
if (!plugin) {
var msg = 'Provider plugin "' + job.project.provider.id + '" not found in this environment!';
var msg = `Provider plugin '${job.project.provider.id}' not found in this environment!`;
return next(new Error(msg));
}
var finished = t(function (err, provider) {
Expand All @@ -238,16 +240,16 @@ Runner.prototype = {
};
var anyPluginFailed = config.plugins.some(function (plugin) {
if (false === plugin.enabled) {
debug('[runner:' + self.id + '] Found a disabled plugin: ' + plugin.id + ' Project: ' + job.project.name + ' Job ID: ' + job._id);
debug(`[runner:${self.id}] Found a disabled plugin: ${plugin.id} Project: ${job.project.name} Job ID: ${job._id}`);
return;
}
if (!self.extensions.job[plugin.id]) {
debug('[runner:' + self.id + '] Error: Plugin not found ' + plugin.id + ' Project: ' + job.project.name + ' Job ID: ' + job._id);
debug(`[runner:${self.id}] Error: Plugin not found ${plugin.id} Project: ${job.project.name} Job ID: ${job._id}`);
debug('Plugin not found', plugin.id);
done(new Error('Plugin required but not found: ' + plugin.id));
done(new Error(`Plugin required but not found: ${plugin.id}`));
return true;
}
debug('Initializing plugin "' + plugin.id + '"...');
debug(`Initializing plugin '${plugin.id}'...`);
tasks.push(function (next) {
var fn = self.extensions.job[plugin.id].init;
var cb = t(function (err, obj) {
Expand Down Expand Up @@ -279,7 +281,7 @@ Runner.prototype = {

clearCache: function (project, done) {
fs.remove(this.cacheDir(project), function (err) {
done(err && new Error('Failed to clear the cache. Error code: ' + err));
done(err && new Error(`Failed to clear the cache. Error code: ${err}`));
});
},

Expand All @@ -296,7 +298,7 @@ Runner.prototype = {

var projectName = job.project.name.replace('/', '-');
var branchName = branchFromJob(job).replace('/', '-');
var branchBase = path.join(self.config.dataDir, 'data', projectName + '-' + branchName);
var branchBase = path.join(self.config.dataDir, 'data', `${projectName}-${branchName}`);
var recentBuilds = _.get(config, 'runner.config.recentBuilds');

if (typeof recentBuilds === 'undefined') {
Expand All @@ -306,7 +308,7 @@ Runner.prototype = {
recentBuilds = Math.max(recentBuilds, 1);

if (recentBuilds > 1) {
debug('Preserving the most recent ' + recentBuilds + ' builds within ' + branchBase + '.');
debug(`Preserving the most recent ${recentBuilds} builds within ${branchBase}.`);
}

// Keep around N most recent build directories for this branch.
Expand Down Expand Up @@ -336,7 +338,7 @@ Runner.prototype = {
}
self.jobdata.get(job._id).started = now;
self.emitter.emit('browser.update', job.project.name, 'job.status.started', [job._id, now]);
debug('[runner:' + self.id + '] Job started. Project: ' + job.project.name + ' Job ID: ' + job._id);
debug(`[runner:${self.id}] Job started. Project: ${job.project.name} Job ID: ${job._id}`);
debug('Initializing plugins...');
self.plugins(job.project.creator, config, job, dirs, function (err, workers) {
if (err) {
Expand All @@ -351,7 +353,7 @@ Runner.prototype = {
delete jobdata.data;
jobdata.finished = new Date();
self.emitter.emit('job.done', jobdata);
debug('[runner:' + self.id + '] Job done with error. Project: ' + job.project.name + ' Job ID: ' + job._id);
debug(`[runner:${self.id}] Job done with error. Project: ${job.project.name} Job ID: ${job._id}`);
next(null);
return;
}
Expand Down Expand Up @@ -379,13 +381,13 @@ Runner.prototype = {
stack: err.stack
};
self.emitter.emit('browser.update', job.project.name, 'job.status.errored', [job._id, jobdata.error]);
debug('[runner:' + self.id + '] Job done with error. Project: ' + job.project.name + ' Job ID: ' + job._id);
debug(`[runner:${self.id}] Job done with error. Project: ${job.project.name} Job ID: ${job._id}`);
}

delete jobdata.data;
jobdata.finished = new Date();
self.emitter.emit('job.done', jobdata);
debug('[runner:' + self.id + '] Job done without error. Project: ' + job.project.name + ' Job ID: ' + job._id);
debug(`[runner:${self.id}] Job done without error. Project: ${job.project.name} Job ID: ${job._id}`);
next(null);
});
});
Expand Down
4 changes: 3 additions & 1 deletion lib/jobdata.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

// A class for collecting and managing job data

var _ = require('lodash');
Expand Down Expand Up @@ -42,7 +44,7 @@ JobData.prototype = {
attach: function () {
var self = this;
Object.keys(this.listeners).forEach(function (name) {
self.io.on('job.status.' + name, function (id) {
self.io.on(`job.status.${name}`, function (id) {
if (!self.jobs[id]) {
debug('[simple-runner][jobdata] got a status update, but the job was never added', id, Object.keys(self.jobs));
return;
Expand Down
2 changes: 2 additions & 0 deletions lib/jobqueue.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var branchFromJob = require('./utils').branchFromJob;

module.exports = JobQueue;
Expand Down
2 changes: 2 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var _ = require('lodash');
var consts = require('./consts');
var stringify = require('json-stable-stringify');
Expand Down

0 comments on commit f29c6fb

Please sign in to comment.