欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

git钩子自动更新代码

程序员文章站 2022-06-11 09:13:34
...
<?php

    if (!isset($_SERVER['HTTP_X_GITLAB_TOKEN']) || !isset($_SERVER['REMOTE_ADDR'])) {
        exit('403');
    }

    //检测token
    $token = '**************';
    if ($_SERVER['HTTP_X_GITLAB_TOKEN'] != $token) {
        exit('token is invaild');
    }

    $whiteIp = ['127.0.0.1'];
    //检测ip
    $ip = $_SERVER['REMOTE_ADDR'];
    if (!in_array($ip, $whiteIp)) {
        exit('ip is invaild');
    }

    $config = [
        '分支名称' => '站点路径',
    ];


    //获取参数
    $post = (array)json_decode(file_get_contents('php://input'), true);

    $eventName = !empty($post['event_name']) ? $post['event_name'] : '';

    $currentRef = '';//当前操作分支

    switch (strtolower($eventName)) {
        case 'push' :
            $ref = !empty($post['ref']) ? $post['ref'] : '';
            
相关标签: php git