Skip to content

Instantly share code, notes, and snippets.

Created July 18, 2012 20:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mreidsma/3138516 to your computer and use it in GitHub Desktop.
PHP script for Botriot to deploy code to server from git

Deploy code from git from your chatroom

This is a simple php script that can be used with the Botriot ( service to deploy code hosted on Github. The script needs to live on the same server your live code will be on, but you can use it to deploy any project or site on a server.


In your Campfire chatroom with your bot active, type:

!deploy directory/path OR botname directory/path

The directory/path should be the directory structure from the web root of your server (you need to set this in the php script). Your bot will then paste in the response fro the server or tell you there was a problem.


Edit the above php script to have the correct path for your server, and then upload it to the server. Next, turn on webhooks for your botriot bot and point them to this url:

!webhook set

Now Botriot will ping that URL for any command it doesn't understand. This command, "deploy," is just one of many. You can go nuts adding commands.

Let me know if you have questions, but read the Botriot webhooks instructions first.

$data = file_get_contents('php://input');
if($data != NULL) {
$values = json_decode($data);
$command = $values->{'text'};
if($cmd[0] == "deploy") {
header('HTTP/1.1 200 OK');
$deploy = shell_exec('cd path/to/site/root/' . $cmd[1] . '; git pull origin master');
if($deploy) { // Strip line breaks from response
$breaks = array("\r\n", "\n", "\r");
$deploy = str_replace($breaks, ":", $deploy);
$message = '{"paste": "' . $deploy . '"}';
} else {
$message = '{"speak": "Well, I think there is a problem."}';
echo $message;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment