Skip to content
Open
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
11 changes: 7 additions & 4 deletions examples/deploys.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"webui": true,
"username": "khanh.tq",
"password": "********",
"deploys": [{
"name": "Webhook Deployer",
"type": "github",
"repo": "https://github.com/Camme/webhook-deployer",
"basepath": "/Users/camilo/Projects/24hr-deployer",
"name": "Skeleton",
"type": "gitlab",
"repo": "git@gitlab.com:*****/skeleton.git",
"basepath": "/Users/khanh/****",
"command": "git pull",
"branch": "master"
}]
Expand Down
70 changes: 58 additions & 12 deletions lib/incoming.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var webdep = require('./webdep');
var fs = require("fs");
var path = require("path");
var exec = require('child_process').exec;
var exec = require('child_process').exec;

exports.control = function(options) {
exports.control = function (options) {

return function incoming(req, res, next) {

Expand All @@ -14,15 +14,15 @@ exports.control = function(options) {
var error = false;

var repoData = {};
try {
repoData = JSON.parse(req.body.payload);
try {
repoData = JSON.parse(req.body);
}
catch (err) {
repoData = { error: err };
error = true;
}

deploysList.forEach(function(deploy) {
deploysList.forEach(function (deploy) {

if (deploy.type == "github") {

Expand Down Expand Up @@ -70,6 +70,52 @@ exports.control = function(options) {
webdep.log("Error while parsing post body");
}
}
else if (deploy.type == "gitlab") {

if (!repoData.error && !repoData.project) {
webdep.log("Webhook payload was not for a push.");
return;
}

if (!repoData.error) {

webdep.log("Checking incoming repo " + repoData.repository.url + "...");

// remove .git from the repo string, since the hook will not have that address when it comes from github
// so instead of explaining that you shouldnt enter ".git", we just remove it here.
if (repoData.repository.git_ssh_url == deploy.repo) {

var branch = repoData.ref.split("/").pop();

webdep.log("> Checking branch '" + branch + "' ...");

if (branch == deploy.branch) {

runDeploy(deploy);

}
else {
webdep.log("> No, wrong branch, nothing to do");
webdep.log("> Got:");
webdep.log("> " + branch);
webdep.log("> But expected:");
webdep.log("> " + deploy.branch);
}
}
else {
webdep.log("No, wrong repo, nothing to do");
webdep.log("Got:");
webdep.log(repoData.repository.url);
webdep.log("But expected:");
webdep.log(deploy.repo.replace(".git", ""));
}

}
else {
webdep.log("");
webdep.log("Error while parsing post body");
}
}
});

if (error) {
Expand Down Expand Up @@ -97,7 +143,7 @@ function runDeploy(deploy) {

var cmd = exec(deploy.command, {
cwd: localPath
}, function(error, stdout, stderr) {
}, function (error, stdout, stderr) {
if (error) {
webdep.log("> ERROR (error): " + error);
}
Expand All @@ -110,22 +156,22 @@ function runDeploy(deploy) {


webdep.log("--------------------------");
cmd.stdout.on('data', function(data) {
cmd.stdout.on('data', function (data) {
webdep.log(data.toString());
});
cmd.stdout.on('close', function(data) {
cmd.stdout.on('close', function (data) {
//webdep.log(data.toString());
});
cmd.stdout.on('exit', function(data) {
cmd.stdout.on('exit', function (data) {
//webdep.log(data.toString());
});
cmd.stdout.on('disconnect', function(data) {
cmd.stdout.on('disconnect', function (data) {
//webdep.log(data.toString());
});
cmd.stdout.on('message', function(data) {
cmd.stdout.on('message', function (data) {
webdep.log("MESSAGE: " + data.toString());
});
cmd.stderr.on('data', function(data) {
cmd.stderr.on('data', function (data) {
webdep.log(data.toString());
});

Expand Down
Loading