Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #7 from jbuck/multiple-push

Allow for pushes to multiple branches
  • Loading branch information...
commit 11468c4a3c829c7f344383acac7c8c80fbaa783b 2 parents 1a11c94 + ccc206a
@arturadib authored
Showing with 15 additions and 5 deletions.
  1. +2 −0  README.md
  2. +13 −5 lib/server.js
View
2  README.md
@@ -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:
View
18 lib/server.js
@@ -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);
@@ -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;
}
@@ -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
};
Please sign in to comment.
Something went wrong with that request. Please try again.