My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
CatchingWebHooks  
Here's how you'd catch Google Code's post-commit web hooks in PHP with joshlib
Phase-Implementation
Updated Apr 5, 2010 by josh.reisner

You can just make some simple db and formatting substitutions if you want to use your own code and skip using this library.

<?php
include('joshlib/index.php');
$key	= ''; //your secret key
$data	= file_get_contents('php://input'); //raw POST data
$digest	= hash_hmac('md5', $data, $key); //hash created with data + key
$hook	= @$_SERVER['HTTP_GOOGLE_CODE_PROJECT_HOSTING_HOOK_HMAC']; //the special header google sends

if ($hook && ($hook == $digest)) { //valid request
	
	//extract the JSON and store the variables in a relational db
	$data = json_decode($data, true);
	if (!$project_id = db_grab('SELECT id FROM svn_projects WHERE name = "' . $data['project_name'] . '"')) {
		$project_id = db_query('INSERT INTO svn_projects ( name ) VALUES ( "' . $data['project_name'] . '" )');
	}

	//read the dictionary on the postCommitWebHooks page to create your db structure
	foreach ($data['revisions'] as $d) {
		db_query('INSERT INTO svn_revisions ( project_id, revision, url, author, timestamp, message, path_count ) VALUES (
			' . $project_id . ',
			"' . $d['revision'] . '",
			"' . $d['url'] . '",
			"' . $d['author'] . '",
			"' . format_date($d['timestamp'], '', 'sql') . '",
			"' . $d['message'] . '",
			'  . $d['path_count'] . '
		)');
	}
	
} else { //invalid request
	echo 'skipping, no special google header, or it was invalid';
}
?>

Sign in to add a comment
Powered by Google Project Hosting