Ejemplo n.º 1
0
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) {
Ejemplo n.º 2
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);
}