Skip to content

Commit

Permalink
Initial test of CI hook
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthaeusHarris committed Apr 11, 2015
1 parent 0e9798c commit 8efc8a2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
node_modules
credentials.js
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ auth.registerRoutes(app);
app.use(require('./routes/index'));
app.use(require('./routes/user'));
app.use(require('./routes/package'));
app.use(require('./routes/ci'));

app.use(function(req, res) {
res.status(404);
Expand Down
2 changes: 1 addition & 1 deletion lib/gitlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var fs = require('fs');
var options = {
repo: fs.realpathSync(__dirname + '/../'),
number: 20,
fields: [ 'subject', 'authorName', 'authorDateRel', 'authorDate' ]
fields: [ 'subject', 'authorName', 'authorDateRel', 'authorDate', 'hash' ]
};

var log = [];
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"serve-favicon": "^2.2.0",
"shipping-fedex": "git+https://github.com/MatthaeusHarris/node-shipping-fedex.git",
"shipping-ups": "^0.4.26",
"shipping-usps": "0.0.3"
"shipping-usps": "0.0.3",
"node-github": "0.0.3"
}
}
45 changes: 45 additions & 0 deletions routes/ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Created by matt on 4/10/15.
*/

var githubApi = require('node-github');
var express = require('express');
var router = express.Router();
var gitlog = require('../lib/gitlog');

var githubInstance = new githubApi({
version: '3.0.0'
});

router.get('/ci/hook/update', function(req, res) {
githubInstance.repos.getCommits({
user: "MatthaeusHarris",
repo: "packagetracker"
}, function(err, data) {
if (err) {
return res.render('500', err);
}

if (data[0].sha !== gitlog.log[0].hash) {
// We need to update
child_process.exec('git pull', function(err, stdout, stderr) {
if (err) {
return res.render('500', [err, stdout, stderr].join('\n'));
}
child_process.exec('npm install', function(err, stdout, stderr) {
if (err) {
return res.render('500', [err, stdout, stderr].join('\n'))
}
process.nextTick(function() {
console.log("Process exiting to restart after CI chain trigger");
process.exit(0);
});
});
});
} else {
res.json({'status': 'ok'});
}
});
});

module.exports = router;

0 comments on commit 8efc8a2

Please sign in to comment.