|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|