Skip to content

Instantly share code, notes, and snippets.

@krewenki
Created April 17, 2015 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krewenki/c3de830da21023367cd5 to your computer and use it in GitHub Desktop.
Save krewenki/c3de830da21023367cd5 to your computer and use it in GitHub Desktop.
Slack SVN post-commit in PHP
<?php
# An SVN post-commit handler for posting to Slack. Setup the channel and get the token
# from your team's services page. Change the options below to reflect your team's settings.
#
$opt_domain = ""; # Your team's domain
$opt_token = ""; # The token from your SVN services page
exec("/usr/bin/svnlook log -r $argv[2] $argv[1]", $log);
exec("/usr/bin/svnlook author -r $argv[2] $argv[1]", $who);
$log = implode("\n", $log);
$who = implode("\n", $who);
$payload = new stdClass;
$payload->revision = $argv[2];
$payload->url = '';
$payload->author = $who;
$payload->log = $log;
$url = "https://".$opt_domain."/services/hooks/subversion?token=".$opt_token;
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, "payload=".urlencode(json_encode($payload)));
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment