require_once "GitHub_WebHook.php"; /** * This config file contains URL to my Flock's webhook in variable. * * Example: * $flockWebHook = "https://api.flock.co/hooks/sendMessage/<token>"; * * For the purpose of security, this file is not added to the git repository. */ require_once "config.php"; try { $githubHook = new GitHub_WebHook(); $githubHook->ProcessRequest(); $eventType = $githubHook->GetEventType(); $repositoryFullName = $githubHook->GetFullRepositoryName(); $payload = $githubHook->GetPayload(); if ($eventType == "pull_request") { logMessage('Payload ' . json_encode($payload)); $action = $payload->action; if ($action == "opened" || $action == "closed" || $action == "reopened") { $pullRequest = $payload->pull_request; $merged = $pullRequest->merged; logMessage('PR: ' . json_encode($pullRequest)); $title = $pullRequest->title; $url = $pullRequest->html_url; $user = $pullRequest->user->login; if ($merged && $action == "closed") { $action = "merged"; $user = $pullRequest->merged_by->login; } $msg = "{$user} {$action} a pull request: '{$title}', {$url}";
require __DIR__ . '/config.php'; require __DIR__ . '/GitHub_WebHook.php'; require __DIR__ . '/GitHub_IRC.php'; $Socket = false; $Hook = new GitHub_WebHook(); try { // This check is optional, you can implement some secret GET param for example if (!$Hook->ValidateIPAddress()) { throw new Exception('Unauthorized.'); } $Hook->ProcessRequest(); $RepositoryName = $Hook->GetFullRepositoryName(); echo 'Received ' . $Hook->GetEventType() . ' in repository ' . $RepositoryName . PHP_EOL; //print_r( $Hook->GetPayload() ); // Format IRC message $IRC = new GitHub_IRC($Hook->GetEventType(), $Hook->GetPayload(), 'shorten_url'); $Message = $IRC->GetMessage(); if (isset($_GET['strip_colors'])) { $Message = strip_colors($Message); } if (empty($Message)) { throw new Exception('Empty message, not sending.'); } // Format irker payload $IrkerPayload = ''; foreach ($Channels as $Channel => $SendTargets) { if (!wild($RepositoryName, $Channel)) { continue; } echo 'Matched "' . $RepositoryName . '" as "' . $Channel . '"' . PHP_EOL; foreach ($SendTargets as $Target) {
require __DIR__ . '/GitHub_WebHook.php'; require __DIR__ . '/GitHub_IRC.php'; $Hook = new GitHub_WebHook(); try { $Hook->ProcessRequest(); // This check is optional, you can implement some secret GET param for example if (!$Hook->ValidateIPAddress()) { http_response_code(401); exit; } // This check is optional, checks if your hook secret matches if (!$Hook->ValidateHubSignature('My secret key')) { http_response_code(401); exit; } echo 'Received ' . $Hook->GetEventType() . ' in repository ' . $Hook->GetFullRepositoryName() . PHP_EOL; //var_dump( $Hook->GetPayload() ); http_response_code(202); } catch (Exception $e) { echo 'Exception: ' . $e->getMessage() . PHP_EOL; http_response_code(500); exit; } try { $IRC = new GitHub_IRC($Hook->GetEventType(), $Hook->GetPayload()); var_dump($IRC->GetMessage()); // Optional } catch (Exception $e) { echo 'Exception: ' . $e->getMessage() . PHP_EOL; http_response_code(500); }