Exemplo n.º 1
0
}
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;
            }
Exemplo n.º 2
0
// Don't do this in production!
ini_set('error_reporting', -1);
ini_set('display_errors', 1);
http_response_code(500);
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)) {
Exemplo n.º 3
0
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);
}