Skip to content

Commit

Permalink
factor out update method; code cleanup; add external redis event trig…
Browse files Browse the repository at this point in the history
…gers (not just git); split dev & play based on master / tags
  • Loading branch information
bsparks committed Dec 12, 2014
1 parent d985f5c commit 893cf80
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 30 deletions.
80 changes: 57 additions & 23 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ team_add = Any time a team is added or modified on a Repository
watchAny = time a User watches the Repository
*/

var config = require('/opt/ironbane-secret/ironbot-settings/ibconfig.json');
var exec = require('exec');
var http = require('http');
Expand All @@ -31,6 +32,13 @@ var handler = createHandler({
secret: config.gitsecret
});

var NRP = require('node-redis-pubsub'),
nrpConfig = {
port: 6379, // TODO: use config
scope: 'ironbot'
},
nrp = new NRP(nrpConfig);

var hipchat = require('node-hipchat');

var HC = new hipchat(config.hipsecret);
Expand All @@ -51,24 +59,18 @@ handler.on('error', function (err) {
console.log('Error:', err.message);
});

handler.on('push', function (event) {
console.log('Received a push event for %s to %s',
event.payload.repository.name,
event.payload.ref);

// Send message to the HipChat so we all know what happened
if (event.payload.ref === 'refs/heads/master') {
HC.postMessage({
room: config.hiproom, // Found in the JSON response from the call above
from: 'IronBot',
message: '<strong>Ironbot</strong> will update ' + event.payload.repository.name + ' to ' + event.payload.ref,
color: 'yellow'
},
function (data) {
// TODO: something with this response?
});
function updateServer(serverId, revision) {
HC.postMessage({
room: config.hiproom, // Found in the JSON response from the call above
from: 'IronBot',
message: '<strong>Ironbot</strong> will update ' + serverId + ' to ' + revision,
color: 'yellow'
},
function (data) {
// TODO: something with this response?
});

switch (event.payload.repository.name) {
switch (serverId) {
case 'ironbane-ironbot':
// Just update the bot, don't do fancy stuff
console.log('Do stuff for ironbot');
Expand All @@ -85,20 +87,52 @@ handler.on('push', function (event) {
});
break;

case 'ironbane-server':
// Swtich between a normal push and a tag
// In case of a push update the dev server
// In case of a tag update the play server
console.log('Do stuff for server');
// TODO: pass revision in as arg $1 for checkout
case 'ironbane-dev-server':
console.log('Do stuff for dev server');
exec('/bin/bash /opt/ironbane-ironbot/update_dev.sh', function (err, out, code) {
console.log(out);
});
//exec('/bin/bash /opt/ironbane-ironbot/update_play.sh');
break;

case 'ironbane-play-server':
console.log('Do stuff for play server');
exec('/bin/bash /opt/ironbane-ironbot/update_play.sh', function (err, out, code) {
console.log(out);
});
break;

default:
// Don't do anything
break;
}
}

nrp.on('update', function (data) {
var server = data.server,
rev = data.rev;

// do it!
updateServer(server, rev);
});

handler.on('push', function (event) {
var repo = event.payload.repository.name,
ref = event.payload.ref;

console.log('Received a push event for %s to %s', repo, ref);

// we update all on master, tho the "ironbane-server" is split by master & tags... other servers are not updated based on tags
if (ref === 'refs/heads/master') {
if (repo === 'ironbane-server') {
repo = 'ironbane-dev-server';
}
updateServer(repo, ref);
} else if (ref.search('tags') >= 0) {
if (repo === 'ironbane-server') {
repo = 'ironbane-play-server';
updateServer(repo, ref);
}
}

});
14 changes: 8 additions & 6 deletions notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ var hipchat = require('node-hipchat');
var HC = new hipchat(config.hipsecret);

// Send message to the HipChat so we all know what happened
HC.postMessage( {room: config.hiproom, // Found in the JSON response from the call above
from: 'IronBot',
message: '<strong>Ironbot</strong> ' + process.argv[2],
color: process.argv[3]},
function(data) { }
)
HC.postMessage({
room: config.hiproom, // Found in the JSON response from the call above
from: 'IronBot',
message: '<strong>Ironbot</strong> ' + process.argv[2],
color: process.argv[3]
},
function (data) {}
);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"exec": "^0.1.2",
"fs": "0.0.2",
"github-webhook-handler": "^0.2.1",
"node-hipchat": "^0.4.5"
"node-hipchat": "^0.4.5",
"node-redis-pubsub": "^0.2.1"
}
}
1 change: 1 addition & 0 deletions update_play.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cd /opt/ironbane-play-server/
/usr/bin/sudo latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
# Checkout latest tag
/usr/bin/sudo git checkout $latestTag
/usr/bin/sudo npm install
/usr/bin/sudo cp /opt/ironbane-secret/ironbane-play-settings/ibconfig.json ./config/config.json
/usr/bin/sudo restart ironbane-play-server
/usr/bin/nodejs /opt/ironbane-ironbot/notify.js "ironbane-play-server up2date and restarted" red

0 comments on commit 893cf80

Please sign in to comment.