Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 (http://botriot.com) 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.

Syntax

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.

Setup

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 http://my.com/path/to/php/file.php

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.

<?php
$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');
set_time_limit(0);
$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