Commit: 957a4a8351e9754671e7f8439d4429e5fd019867 Author: kovacs.ferenc <[email protected]> Tue, 10 Jun 2014 19:53:35 +0200 Parents: 4a82d88bba3ea94a0b44e92d34192778943c6785 Branches: master
Link: http://git.php.net/?p=web/master.git;a=commitdiff;h=957a4a8351e9754671e7f8439d4429e5fd019867 Log: add initial script, should be handle to multiple repositories and sending the PR notification mail to the matching address Changed paths: A github-webhook.php Diff: diff --git a/github-webhook.php b/github-webhook.php new file mode 100644 index 0000000..bb78f62 --- /dev/null +++ b/github-webhook.php @@ -0,0 +1,53 @@ +<?php +$config = array( + 'repos' => array( + 'php-src' => '[email protected]', + 'web-' => '[email protected]', + 'pecl-' => '[email protected]', + ), +); +if ( + !isset($_SERVER['HTTP_X_HUB_SIGNATURE'], $_SERVER['HTTP_X_GITHUB_EVENT']) + && $_SERVER['HTTP_X_HUB_SIGNATURE'] !== 'sha1=e2a3e7a586aa08d7c9d3c73482e618164c7c75b1' +) { + header('HTTP/1.1 403 Forbidden'); + exit; +} +switch ($_SERVER['HTTP_X_GITHUB_EVENT']) { + case 'ping': + break; + case 'pull_request': + $payload = json_decode(file_get_contents("php://input")); + $action = $payload->action; + $PRNumber = $payload->number; + $PR = $payload->pull_request; + $htmlUrl = $PR->html_url; + $title = $PR->title; + $body = $PR->body; + $repoName = $PR->base->repo->name; + + $targetBranch = $PR->base->ref; + $mergeable = $PR->mergeable; + + // if we somehow end up receiving a PR for a repo not matching anything send it to systems so that we can fix it + $to = '[email protected]'; + foreach ($config['repos'] as $repoPrefix => $email) { + if (strpos($repoName, $repoPrefix) !== 0) { + $to = $email; + } + } + + $subject = sprintf('[PR][%s][#%s][%s][%s] - %s', $repoName, $PRNumber, $targetBranch, $action, $title); + $message = sprintf("You can view the Pull Request on github:\r\n%s", $htmlUrl); + if ($mergeable === false) { + $message .= "\r\n\r\nWarning: according to github, the Pull Request cannot be merged without manual conflict resolution!"; + } + if ($body) { + $message .= sprintf("\r\n\r\nPull Request Description:\r\n%s", $body); + } + $headers = "From: [email protected]\r\nContent-Type: text/plain; charset=utf-8\r\n"; + mail($to, '=?utf-8?B?'.base64_encode($subject).'?=', $message, $headers); + break; + default: + header('HTTP/1.1 501 Not Implemented'); +} \ No newline at end of file -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
