Implemented GitHub commit status API client

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 11 years ago
parent 6b59eddf51
commit 9ded7ae76e
  1. 3
      BuildServer/.gitignore
  2. 55
      BuildServer/lib/builder.js
  3. 3
      BuildServer/package.json

@ -15,4 +15,5 @@ npm-debug.log
node_modules node_modules
data data
*.crt *.crt
settings.js

@ -2,8 +2,34 @@
var fs = require('fs'); var fs = require('fs');
var fse = require('fs-extra'); var fse = require('fs-extra');
var async = require('async');
var request = require('request');
var gitLoader = require('./git-loader'); var gitLoader = require('./git-loader');
var processor = require('./task-processor'); var processor = require('./task-processor');
var settings = require('../settings');
var notifyStatus = function (options, callback) {
var url = "https://github.pos/api/v3/repos/" + options.owner + "/" + options.reponame + "/statuses/" + options.hash;
request.post(url, {
auth: settings.getGithubAuth(options.owner),
json: {
state: options.state,
target_url: "https://mbs.pos/status/" + options.owner + "/" + options.reponame + "/" + options.hash,
description: options.description
}
}, function (err, response, body) {
if (err) {
console.log("Error: " + err);
return callback(err);
}
console.log("Status code: " + response.statusCode);
console.log(body);
if (response.statusCode !== 200) {
return callback(body);
}
return callback();
});
};
var build = function (options, callback) { var build = function (options, callback) {
var url = options.url, var url = options.url,
@ -14,7 +40,20 @@ var build = function (options, callback) {
local = options.app.get('gitpath') + "/" + owner + "/" + reponame + ".git", local = options.app.get('gitpath') + "/" + owner + "/" + reponame + ".git",
tmp = options.app.get('tmpcodepath') + "/" + rev, tmp = options.app.get('tmpcodepath') + "/" + rev,
exported = tmp + "/code", exported = tmp + "/code",
release = options.app.get('releasepath') + "/" + owner + "/" + reponame + "/" + branch + "/" + rev; release = options.app.get('releasepath') + "/" + owner + "/" + reponame + "/" + branch + "/" + rev,
statusQueue = async.queue(function (task, callback) {
task(callback);
}, 1);
statusQueue.push(function (callback) {
notifyStatus({
state: "pending",
description: "Preparing to build...",
owner: owner,
reponame: reponame,
hash: rev
}, callback);
});
fse.mkdirsSync(release); fse.mkdirsSync(release);
@ -23,7 +62,21 @@ var build = function (options, callback) {
fs.writeFileSync(options.app.get('releasepath') + "/" + owner + "/" + reponame + "/$revs/" + rev + ".branch", branch); fs.writeFileSync(options.app.get('releasepath') + "/" + owner + "/" + reponame + "/$revs/" + rev + ".branch", branch);
var done = function (err, result) { var done = function (err, result) {
var errorMessage = ((result.errors.$allMessages || [])[0] || {}).message,
warnMessage = ((result.warns.$allMessages || [])[0] || {}).message,
infoMessage = ((result.infos.$allMessages || [])[0] || {}).message;
fs.writeFile(release + "/report.json", JSON.stringify({err: err, result: result}), function (writeErr) { fs.writeFile(release + "/report.json", JSON.stringify({err: err, result: result}), function (writeErr) {
statusQueue.push(function (callback) {
notifyStatus({
state: err ? "error" : "success",
description: errorMessage || warnMessage || infoMessage || "Success",
owner: owner,
reponame: reponame,
hash: rev
}, callback);
});
if (writeErr) { if (writeErr) {
return callback(writeErr); return callback(writeErr);
} }

@ -10,6 +10,7 @@
"jade": "*", "jade": "*",
"async": "~0.2.9", "async": "~0.2.9",
"fs-extra": "~0.8.1", "fs-extra": "~0.8.1",
"git-node": "~0.1.1" "git-node": "~0.1.1",
"request": "~2.27.0"
} }
} }

Loading…
Cancel
Save