Skip to content

Instantly share code, notes, and snippets.

@RJ
Created March 15, 2012 10:37
Show Gist options
  • Save RJ/2043539 to your computer and use it in GitHub Desktop.
Save RJ/2043539 to your computer and use it in GitHub Desktop.
Crusty old php 3 or 4 from back in the day
<?php
// test str/*{{{*/:
$str = <<<EOF
{
"before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
"repository": {
"url": "http://github.com/defunkt/github",
"name": "github",
"description": "You're lookin' at it.",
"watchers": 5,
"forks": 2,
"private": 1,
"owner": {
"email": "chris@ozmm.org",
"name": "defunkt"
}
},
"commits": [
{
"id": "41a212ee83ca127e3c8cf465891ab7216a705f59",
"url": "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
"author": {
"email": "chris@ozmm.org",
"name": "Chris Wanstrath"
},
"message": "okay i give in",
"timestamp": "2008-02-15T14:57:17-08:00",
"added": ["filepath.rb"]
},
{
"id": "de8251ff97ee194a289832576287d6f8ad74e3d0",
"url": "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
"author": {
"email": "chris@ozmm.org",
"name": "Chris Wanstrath"
},
"message": "update pricing a tad",
"timestamp": "2008-02-15T14:36:34-08:00"
}
],
"after": "de8251ff97ee194a289832576287d6f8ad74e3d0",
"ref": "refs/heads/master"
}
EOF;
/*}}}*/
$str = stripslashes($_POST['payload']);
$j = new Services_JSON();
$obj = $j->decode($str);
$output = "";
$repo = $obj->repository->name;
$repo = $obj->repository->owner->name . "/" . $repo;
$output = "PUSH -> $repo [". $obj->ref ."] ";
$commits=0;
foreach($obj->commits as $c)
{
$name = $c->author->name . " <" . $c->author->email . ">";
$url = tinyurl($c->url);
$msg = str_replace("\n", ' // ', $c->message);
$output .= "$name $url\n$msg\n";
$commits++;
}
if($commits==0) exit;
$fh = fsockopen("irccat-host.example.com", 12345);
if($fh)
{
if($obj->repository->name == "lastfm-android")
{
fwrite($fh, "#chan1 $output");
}else{
fwrite($fh, "#chan2 $output");
}
}
fclose($fh);
function tinyurl($url){
return(trim(file_get_contents('http://tinyurl.com/api-create.php?url='.$url)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment