Commit:    2320705c2bcedccf694c8e88eb3e6c1a7bb247f6
Author:    Nikita Popov <[email protected]>         Tue, 15 Nov 2016 21:45:13 +0100
Parents:   4611f79bd1cb18e53ee1fd55e541e2999a5d6d00
Branches:  master

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

Log:
Try to make PR mails less spammy

Changed paths:
  M  github-webhook.php


Diff:
diff --git a/github-webhook.php b/github-webhook.php
index 2a5b08c..7578916 100644
--- a/github-webhook.php
+++ b/github-webhook.php
@@ -51,25 +51,44 @@ if (!verify_signature($body)) {
 }
 
 $payload = json_decode($body);
+$action = $payload->action;
 $PR = $payload->pull_request;
 $htmlUrl = $PR->html_url;
 $repoName = $PR->base->repo->name;
-$description = $PR->body;
 
-switch  ($_SERVER['HTTP_X_GITHUB_EVENT']) {
+switch ($_SERVER['HTTP_X_GITHUB_EVENT']) {
        case 'ping':
                break;
        case 'pull_request':
-               $mergeable = $PR->mergeable;
+        $description = $PR->body;
+        $username = $PR->user->login;
 
         $to = get_repo_email($CONFIG["repos"], $repoName);
         $subject = prep_title($PR, $PR->base);
 
                $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!";
-               }
-               $message .= sprintf("\r\n\r\nPull Request Description:\r\n%s", 
$description);
+        switch ($action) {
+            case 'opened':
+                $message .= sprintf(
+                    "\r\n\r\nOpened By: %s\r\nPull Request Description:\r\n%s",
+                    $username, $description);
+                break;
+            case 'closed':
+                $message .= "\r\n\r\nClosed.";
+                break;
+            case 'reopened':
+                $message .= "\r\n\r\nReopened.";
+                break;
+            case 'assigned':
+            case 'unassigned':
+            case 'labeled':
+            case 'unlabeled':
+            case 'edited':
+            case 'synchronize':
+                // Ignore these actions
+                break 2;
+        }
+
                $headers = "From: [email protected]\r\nContent-Type: text/plain; 
charset=utf-8\r\n";
                mail($to, '=?utf-8?B?'.base64_encode($subject).'?=', $message, 
$headers, "[email protected]");
                break;
@@ -81,8 +100,15 @@ switch  ($_SERVER['HTTP_X_GITHUB_EVENT']) {
         $to = get_repo_email($CONFIG["repos"], $repoName);
         $subject = prep_title($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", 
$comment);
-               $message .= sprintf("\r\nMade by: %s", $username);
+        switch ($action) {
+            case 'created':
+                $message .= sprintf("\r\n\r\nComment by %s:\r\n%s", $username, 
$comment);
+                break;
+            case 'edited':
+            case 'deleted':
+                // Ignore these actions
+                break 2;
+        }
 
                $headers = "From: [email protected]\r\nContent-Type: text/plain; 
charset=utf-8\r\n";
                mail($to, '=?utf-8?B?'.base64_encode($subject).'?=', $message, 
$headers, "[email protected]");


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

Reply via email to