Skip to content

Commit

Permalink
Merge pull request arturadib#7 from jbuck/multiple-push
Browse files Browse the repository at this point in the history
Allow for pushes to multiple branches
  • Loading branch information
arturadib committed Jun 25, 2012
2 parents 1a11c94 + ccc206a commit 11468c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ The bot should write back a hello world response in the PR discussion. At this p

When Github sends a new notification, Botio automatically fires up the corresponding script. For example, `push` (post-receive) notifications will trigger `on_push.js`, whereas a PR comment containg a command like `/botio preview` will trigger `on_cmd_preview.js`.

If you want to write a script that triggers on pushes to branches other than master, simply name the file `on_push_to_branchname.js`.

Bot.io uses [ShellJS](http://github.com/arturadib/shelljs) to enable portable shell-like scripting, so your scripts look like traditional Unix shell scripts but work verbatim on different platforms (like Windows). See [mozilla/botio-files-pdfjs](http://github.com/mozilla/botio-files-pdfjs) for real-world examples.

When you `require()` the main Botio module, it automatically takes care of the necessary cloning and merging into a temporary (private) directory, and executes your script in that directory. The module also exposes the following job information properties:
Expand Down
18 changes: 13 additions & 5 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ function runJob(jobInfo, callback) {
scriptPath = shell.pwd()+'/on_'+jobInfo.event+'.js',
commandLine = 'node '+scriptPath+' > '+outputPath;

if (jobInfo.event === 'push' && jobInfo.head_ref !== 'master') {
scriptPath = shell.pwd()+'/on_push_to_'+jobInfo.head_ref+'.js';
commandLine = 'node '+scriptPath+' > '+outputPath;
}

shell.mkdir('-p', jobInfo.public_dir);
shell.mkdir('-p', jobInfo.private_dir);

Expand Down Expand Up @@ -333,18 +338,21 @@ app.post('/', function(req, res) {
}
}); // postComment()
}; // maybeEnqueueJob()
break;

//
// Event: push
//
case 'push':
if (payload.ref !== 'refs/heads/master') {
debug('push event not to master branch ('+payload.ref+'). skipping req');
var ref = payload.ref.split('/')[2];

if (ref === 'master' && !shell.test('-f', './on_push.js')) {
log('Command not implemented (push)');
return;
}

if (!shell.test('-f', './on_push.js')) {
log('Command not implemented (push)');
if (ref !== 'master' && !shell.test('-f', './on_push_to_' + ref + '.js')) {
log('Command not implemented (push_to_' + ref + ')');
return;
}

Expand All @@ -358,7 +366,7 @@ app.post('/', function(req, res) {
public_url: 'http://'+config.host+':'+config.port+'/'+id,
base_url: null,
head_url: 'git://github.com/'+config.repo+'.git',
head_ref: 'master',
head_ref: ref,
head_sha: payload.head_commit.id,
debug: global.debug
};
Expand Down

0 comments on commit 11468c4

Please sign in to comment.