com web/master: Support issues in github webhook: github-webhook.php
| From: | Nikita Popov | Date: | Wed, 21 Dec 2016 22:18:05 +0000 |
| Subject: | com web/master: Support issues in github webhook: github-webhook.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-25443@lists.php.net to get a copy of this message | ||
Commit: 6bd9ac552a382e63a14a4e03e9d91497a40b5bc0
Author: Nikita Popov <nikic@php.net> Wed, 21 Dec 2016 23:18:05 +0100
Parents: ed329ef22c59228b5736cf2750283fedf87f733a
Branches: master
Link: http://git.php.net/?p=web/master.git;a=commitdiff;h=6bd9ac552a382e63a14a4e03e9d91497a40b5bc0
Log:
Support issues in github webhook
It does not look like the webhook payloads explicitly tell you
whether an issue comment is on a issue or PR. As such, we use the
HTML URL to determine whether it's an issue or PR.
Changed paths:
M github-webhook.php
Diff:
diff --git a/github-webhook.php b/github-webhook.php
index f52f1b4..e2ebd35 100644
--- a/github-webhook.php
+++ b/github-webhook.php
@@ -19,11 +19,12 @@ function get_repo_email($repos, $repoName) {
return $to;
}
-function prep_title($PR, $repoName) {
- $PRNumber = $PR->number;
- $title = $PR->title;
+function prep_title($issue, $repoName) {
+ $issueNumber = $issue->number;
+ $title = $issue->title;
+ $type = strpos($issue->html_url, '/pull/') !== false ? 'PR' :
'Issue';
- $subject = sprintf('[PR][%s][#%s] - %s', $repoName, $PRNumber, $title);
+ $subject = sprintf('[%s][%s #%s] - %s', $repoName, $type, $issueNumber, $title);
return $subject;
}
@@ -54,14 +55,15 @@ switch ($event) {
case 'ping':
break;
case 'pull_request':
- $PR = $payload->pull_request;
- $htmlUrl = $PR->html_url;
+ case 'issues':
+ $issue = $event == 'issues' ? $payload->issue : $payload->pull_request;
+ $htmlUrl = $issue->html_url;
- $description = $PR->body;
- $username = $PR->user->login;
+ $description = $issue->body;
+ $username = $issue->user->login;
$to = get_repo_email($CONFIG["repos"], $repoName);
- $subject = prep_title($PR, $repoName);
+ $subject = prep_title($issue, $repoName);
$message = sprintf("You can view the Pull Request on github:\r\n%s", $htmlUrl);
switch ($action) {
@@ -82,6 +84,8 @@ switch ($event) {
case 'unlabeled':
case 'edited':
case 'synchronize':
+ case 'milestoned':
+ case 'demilestoned':
// Ignore these actions
break 2;
}
@@ -92,14 +96,14 @@ switch ($event) {
case 'pull_request_review_comment':
case 'issue_comment':
- $PR = $event == 'issue_comment' ? $payload->issue : $payload->pull_request;
- $htmlUrl = $PR->html_url;
+ $issue = $event == 'issue_comment' ? $payload->issue :
$payload->pull_request;
+ $htmlUrl = $issue->html_url;
$username = $payload->comment->user->login;
$comment = $payload->comment->body;
$to = get_repo_email($CONFIG["repos"], $repoName);
- $subject = prep_title($PR, $repoName);
+ $subject = prep_title($issue, $repoName);
$message = sprintf("You can view the Pull Request on github:\r\n%s", $htmlUrl);
switch ($action) {
case 'created':