예제 #1
0
<?php

$ts = microtime(true);
$config = (require __DIR__ . '/config.php');
require_once __DIR__ . '/lib.php';
$payload = get_payload();
$access_log = date('Y-m-d H:i:s') . PHP_EOL . 'GET: ' . print_r($_GET, 1) . PHP_EOL . 'POST: ' . print_r($_POST, 1) . PHP_EOL . 'SERVER: ' . print_r($_SERVER, 1) . PHP_EOL . 'PAYLOAD: ' . print_r($payload, 1) . PHP_EOL;
_log($access_log, __DIR__ . '/log/access.log');
!$payload && exit(_404());
$provider = get_git_provider();
!$provider && exit(_404());
$app_conf = get_app_conf($config);
!$app_conf && exit(_403());
$path = rtrim($app_conf['path'], '/') . '/';
if ($provider === 'github') {
    // Github API v3
    // https://developer.github.com/v3/activity/events/types/#pushevent
    //
    // you should put deploy keys inside /var/www/.ssh/id_rsa
    // also verify if user www-data has access to private repo:
    // sudo -u www-data ssh -T git@github.com
    //
    $event = strtolower($_SERVER['HTTP_X_GITHUB_EVENT']);
    if (in_array($event, array('create', 'push'))) {
        $clone_url = $payload['repository'][$app_conf['is_private'] ? 'ssh_url' : 'clone_url'];
        $ref = $payload['ref'];
        $git_hash = $payload['head_commit']['id'];
        if ($clone_url && $ref) {
            $ok = deploy_git($ref, $path, $clone_url, $app_conf);
        }
        !$ok && _503();
예제 #2
0
파일: lib.php 프로젝트: yfix/deploy-webhook
function get_app_conf($config)
{
    $provider = get_git_provider();
    if ($provider === 'github') {
        return github_get_app_conf($config);
    } elseif ($provider === 'bitbucket') {
        return bitbucket_get_app_conf($config);
    }
    return false;
}