bgh

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

服务器对接码云webhooks

Posted on 2019-01-10 14:13  bgh  阅读(708)  评论(0编辑  收藏  举报

服务安装git

 

php代码(外网必须可以访问)

 1 <?php
 2 //本地路径滚adminasdfdasfasdf
 3 $file = "/wwwroot/webhooksLog.txt";
 4 $_File = fopen($file, "a+");
 5 $local = '/wwwroot/test';
 6 //仓库地址
 7 $remote = '远程仓库地址';
 8  
 9 //密码
10 $password = '123456';
11  
12 //获取请求参数
13 $request = file_get_contents('php://input');
14 if (empty($request)) {
15   die('请求参数为空');
16 }
17  
18 //验证密码是否正确
19 $data = json_decode($request, true);
20 if ($data['password'] != $password) {
21   die('密码错误');
22 }
23 fwrite($_File, "************************************************\r\n");
24 fwrite($_File, "推送人Name: ");
25 fwrite($_File, $data["pusher"]["name"] . "\r\n");
26 fwrite($_File, "推送人Email: ");
27 fwrite($_File, $data["pusher"]["email"] . "\r\n");
28 fwrite($_File, "推送人UserName: ");
29 fwrite($_File, $data["pusher"]["username"] . "\r\n");
30 fwrite($_File, "推送人备注: ");
31 fwrite($_File, $data["head_commit"]["message"] . "\r\n");
32 fwrite($_File, "推送项目: ");
33 fwrite($_File, $data["repository"]["full_name"] . "\r\n");
34 fwrite($_File, "推送分支: ");
35 fwrite($_File, $data["ref"] . "\r\n");
36 fwrite($_File, "推送日期: ");
37 fwrite($_File, $data["head_commit"]["timestamp"] . "\r\n");
38 fwrite($_File, "************************************************\r\n");
39 fclose($_File);
40 //return;
41 //echo shell_exec("cd {$local} && git pull {$remote} 2>&1");
42 system('cd '.$local.' && "C:/Program Files/Git/cmd/git.exe" pull '.$remote.' 2>&1', $out);
43 echo $out;
44 die('done' . date('Y-m-d H:i:s'));
45 ?>

填入域名,点击提交