php实现webhook自动部署代码

<?php

$json = file_get_contents("php://input");

$data = json_decode($json,true);

if (isset($data['ref']) && $data['total_commits_count']>0) {

	$res = PHP_EOL."pull start ---------------------------------------------".PHP_EOL;

	$res .= shell_exec("cd /www/cqc_blog && git pull https://iamchenqicheng:password@gitee.com/iamchenqicheng/cqc_blog.git 2>&1 ");

	$res_log = '------------------------------------------------------------'.PHP_EOL;

	$res_log .= $data['user_name'] . ' 在' . date('Y-m-d H: i:s') . '向' . $data['repository']['name'] . '项目的' . $data['ref'] . '分支push了' . $data['total_commits_count'] . '个commit:'.$data['commits'][0]['message'];

	$res_log .= $res.PHP_EOL;

	$res_log .= "pull end -----------------------------------------------------".PHP_EOL;

	file_put_contents("/www/cqc_blog/public/webhooks/".date('Y-m-d',time()).".txt", $res_log, FILE_APPEND);//写入日志到log文件中

}

?>

zed
请先登录后发表评论
  • latest comments
  • 总共0条评论