Commit:    f006fcfc79247fa060e6e72b5f35b68c3ebb6093
Author:    Hannes Magnusson <bj...@mongodb.com>         Thu, 31 Jul 2014 
13:27:12 -0700
Parents:   12e634636d73ce43608f3e13127c06edb23fc33d
Branches:  master

Link:       
http://git.php.net/?p=web/master.git;a=commitdiff;h=f006fcfc79247fa060e6e72b5f35b68c3ebb6093

Log:
Mailout the PR comments

Changed paths:
  M  github-webhook.php


Diff:
diff --git a/github-webhook.php b/github-webhook.php
index 7015b9c..7b7391d 100644
--- a/github-webhook.php
+++ b/github-webhook.php
@@ -1,6 +1,42 @@
 <?php
-$config = array(
+function verify_signature($requestBody) {
+       if(isset($_SERVER['HTTP_X_HUB_SIGNATURE'])){
+               $parts = explode("=", $_SERVER['HTTP_X_HUB_SIGNATURE'], 2);
+               if (count($parts) == 2) {
+                       return hash_hmac($parts[0], $requestBody, 
getenv('GITHUB_SECRET')) === $parts[1];
+               }
+       }
+       return false;
+}
+
+function get_repo_email($repos, $repoName) {
+    // 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 = 'syst...@php.net';
+    foreach ($repos as $repoPrefix => $email) {
+        if (strpos($repoName, $repoPrefix) === 0) {
+            $to = $email;
+        }
+    }
+
+    return $to;
+}
+
+function prep_title($action, $PR, $base) {
+    $PRNumber = $PR->number;
+    $title = $PR->title;
+
+    $repoName = $base->repo->name;
+    $targetBranch = $base->ref;
+
+    $subject = sprintf('[PR][%s][#%s][%s][%s] - %s', $repoName, $PRNumber, 
$targetBranch, $action, $title);
+
+    return $subject;
+}
+
+
+$CONFIG = array(
        'repos' => array(
+               'php-langspec' => 'standa...@lists.php.net',
                'php-src' => 'git-pu...@lists.php.net',
                'web-' => 'php-webmaster@lists.php.net',
                'pecl-' => 'pecl-...@lists.php.net',
@@ -20,25 +56,14 @@ switch  ($_SERVER['HTTP_X_GITHUB_EVENT']) {
        case 'pull_request':
                $payload = json_decode($body);
                $action = $payload->action;
-               $PRNumber = $payload->number;
                $PR = $payload->pull_request;
-               $htmlUrl = $PR->html_url;
-               $title = $PR->title;
-               $description = $PR->body;
-               $repoName = $PR->base->repo->name;
-
-               $targetBranch = $PR->base->ref;
                $mergeable = $PR->mergeable;
+        $htmlUrl = $PR->html_url;
+        $description = $PR->body;
 
-               // 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 = 'syst...@php.net';
-               foreach ($config['repos'] as $repoPrefix => $email) {
-                       if (strpos($repoName, $repoPrefix) === 0) {
-                               $to = $email;
-                       }
-               }
+        $to = get_repo_email($CONFIG["repos"], $repoName);
+        $subject = prep_title($action, $PR, $PR->base);
 
-               $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!";
@@ -47,16 +72,25 @@ switch  ($_SERVER['HTTP_X_GITHUB_EVENT']) {
                $headers = "From: nore...@php.net\r\nContent-Type: text/plain; 
charset=utf-8\r\n";
                mail($to, '=?utf-8?B?'.base64_encode($subject).'?=', $message, 
$headers, "-fnore...@php.net");
                break;
+
+    case 'pull_request_review_comment':
+               $payload = json_decode($body);
+               $action = $payload->action;
+               $PR = $payload->pull_request;
+        $username = $payload->user->login;
+               $comment = $payload->comment->body;
+
+        $to = get_repo_email($CONFIG["repos"], $repoName);
+        $subject = prep_title($action, $PR, $PR->base);
+               $message = sprintf("You can view the Pull Request on 
github:\r\n%s", $htmlUrl);
+               $message .= sprintf("\r\n\r\nPull Request Comment:\r\n%s", 
$description);
+               $message .= sprintf("\r\nMade by: %s", $username);
+
+               $headers = "From: nore...@php.net\r\nContent-Type: text/plain; 
charset=utf-8\r\n";
+               mail($to, '=?utf-8?B?'.base64_encode($subject).'?=', $message, 
$headers, "-fnore...@php.net");
+        break;
+
        default:
                header('HTTP/1.1 501 Not Implemented');
 }
 
-function verify_signature($requestBody) {
-       if(isset($_SERVER['HTTP_X_HUB_SIGNATURE'])){
-               $parts = explode("=", $_SERVER['HTTP_X_HUB_SIGNATURE'], 2);
-               if (count($parts) == 2) {
-                       return hash_hmac($parts[0], $requestBody, 
getenv('GITHUB_SECRET')) === $parts[1];
-               }
-       }
-       return false;
-}


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to