当前位置: 移动技术网 > IT编程>开发语言>PHP > 服务器对接码云webhooks

服务器对接码云webhooks

2019年01月10日  | 移动技术网IT编程  | 我要评论

服务安装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 ?>

填入域名,点击提交

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网