Ejemplo n.º 1
0
SlaveConnection.prototype.state_running.reportfallback = function (S) {
	mod_assert.ok(this.sc_status !== 0,
	    'this impl assumes the "make check" failed');

	var self = this;
	var review = {};
	review.labels = {};
	review.message = '"make check" exited with status ' + this.sc_status;
	review.labels['CI-Testing'] = '-1';

	var start = this.sc_out.length - 50;
	if (start < 0)
		start = 0;
	var lines = this.sc_out.slice(start,
	    this.sc_out.length);
	lines = lines.map(function (v) { return (' ' + v); });
	review.message += '\n\n' + lines.join('\n');

	review.project = this.sc_change.project;
	var spec = this.sc_change.number + ',' + this.sc_patchset.number;
	gerrit.review(spec, review, S.callback(function (err) {
		if (err) {
			self.sc_log.error({ err: err },
			    'failed to post review (reportfallback)');
		}
		S.gotoState('closing');
	}));
};
Ejemplo n.º 2
0
evs.on('bootstrap', function () {
	var q = 'status:open AND NOT label:CI-Testing>=-1';
	var incl = ['patch-sets'];
	var qstream = gerrit.queryStream(q, incl);
	qstream.on('readable', function () {
		var change;
		while ((change = qstream.read()) !== null) {
			if (change.project === undefined ||
			    change.id === undefined) {
				continue;
			}
			var ps = change.patchSets[change.patchSets.length - 1];
			if (ps.isDraft === false)
				handleNewPatchset(change, ps);
		}
	});
});
Ejemplo n.º 3
0
SlaveConnection.prototype.state_running.report = function (S) {
	var self = this;
	var review = {};
	review.labels = {};
	if (this.sc_status === 0) {
		review.message = '"make check" passed ok';
		review.labels['CI-Testing'] = '+1';
	} else {
		review.message = '"make check" exited with status ' +
		    this.sc_status;
		review.labels['CI-Testing'] = '-1';

		var comments = [];
		var ls = this.sc_out;
		var mode = 'none';
		var esfile;
		var c, m;

		for (var i = 0; i < ls.length; ++i) {
			if (ls[i].match(/^\s*$/))
				continue;
			if (mode === 'jsl') {
				m = ls[i].match(JSL_RE);
				if (m) {
					c = {};
					c.path = m[1];
					c.line = parseInt(m[2], 10);
					c.message = m[3];
					comments.push(c);
					continue;
				} else if (ls[i].match(JSL_NULL_RE)) {
					continue;
				} else {
					mode = 'none';
				}
			}
			if (mode === 'jsstyle') {
				m = ls[i].match(JSSTYLE_RE);
				if (m) {
					c = {};
					c.path = m[1];
					c.line = parseInt(m[2], 10);
					c.message = m[3];
					comments.push(c);
					continue;
				} else if (ls[i].match(/^Unescaped left br/)) {
					continue;
				} else {
					mode = 'none';
				}
			}
			if (mode === 'eslint') {
				m = ls[i].match(ESLINT_FILE_RE);
				if (m) {
					esfile = m[1];
					continue;
				}
				m = ls[i].match(ESLINT_RE);
				if (m && esfile !== undefined) {
					c = {};
					c.path = esfile;
					c.line = parseInt(m[1], 10);
					c.message = m[3].trim();
					comments.push(c);
					continue;
				} else {
					mode = 'none';
				}
			}
			if (mode === 'bashsty') {
				m = ls[i].match(BASHSTY_RE);
				if (m) {
					c = {};
					c.path = m[1];
					c.line = parseInt(m[2], 10);
					c.message = m[3];
					comments.push(c);
					continue;
				} else {
					mode = 'none';
				}
			}
			if (ls[i].match(/^([^ ]+\/)?jsl /)) {
				mode = 'jsl';
			} else if (ls[i].match(/^([^ ]+\/)?jsstyle /)) {
				mode = 'jsstyle';
			} else if (ls[i].match(/^([^ ]+\/)?eslint /)) {
				mode = 'eslint';
			} else if (ls[i].match(/^([^ ]+\/)?bashstyle /)) {
				mode = 'bashsty';
			}
		}

		review.comments = {};
		comments.forEach(function (comment) {
			if (review.comments[comment.path] === undefined)
				review.comments[comment.path] = [];
			review.comments[comment.path].push(comment);
		});

		if (comments.length < 1) {
			var start = this.sc_out.length - 50;
			if (start < 0)
				start = 0;
			var lines = this.sc_out.slice(start,
			    this.sc_out.length);
			lines = lines.map(function (v) { return (' ' + v); });
			review.message += '\n\n' + lines.join('\n');
		}
	}
	review.project = this.sc_change.project;
	var spec = this.sc_change.number + ',' + this.sc_patchset.number;
	gerrit.review(spec, review, S.callback(function (err) {
		if (err) {
			self.sc_log.error({ err: err },
			    'failed to post review (report)');
			/*
			 * If we hit
			 * <https://bugs.chromium.org/p/gerrit/issues/detail?id=3475>
			 * then fallback to a dumber report that doesn't try
			 * to match 'make check' output to patchset files.
			 * See arekinath/gerritbot#1.
			 */
			var marker = 'not found in revision';
			if (err.message.search(marker) !== -1) {
				S.gotoState('running.reportfallback');
				return;
			}
		}
		S.gotoState('closing');
	}));
};
Ejemplo n.º 4
0
var dockerKeyPem = mod_fs.readFileSync(config.docker.keyFile);
var dockerKey = mod_sshpk.parsePrivateKey(dockerKeyPem);
var id = mod_sshpk.identityFromDN('CN=' + config.docker.user);
var cert = mod_sshpk.createSelfSignedCertificate(id, dockerKey);

config.gerrit.log = log;
config.gerrit.recovery = {
	default: {
		timeout: 30000,
		maxTimeout: 120000,
		delay: 5000,
		maxDelay: 15000,
		retries: Infinity
	}
};
var gerrit = new mod_gbot.Client(config.gerrit);

var docker = mod_restify.createJsonClient({
	url: 'https://' + config.docker.host + ':2376',
	rejectUnauthorized: false,
	key: dockerKeyPem,
	cert: cert.toBuffer('pem')
});

const COOKIE = mod_crypto.randomBytes(8).toString('base64');

var spawning = {};

function spawnWorker() {
	var spawnCookie = mod_crypto.randomBytes(8).toString('base64');
	spawning[spawnCookie] = true;