2 Star 0 Fork 0

JerryXu/tubuTravel

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
hook.php 3.18 KB
一键复制 编辑 原始数据 按行查看 历史
张宏业 提交于 2016-08-18 09:34 . 时间处理
<?php
/**
* 钩子文件(注意别删)
* 利用web hooks
* 目前
* */
require(__DIR__ . '/Application/Common/Common/Mail.php');
$developInfo = require(__DIR__ . '/Application/Common/Conf/config.php');
$password = !empty($developInfo['PASSWORD']) ? $developInfo['PASSWORD'] : '';
$developInfo = !empty($developInfo['DEVELOPMENT']) ? $developInfo['DEVELOPMENT'] : [];
$hookData = $_REQUEST['hook'];
$hookData = json_decode($hookData, true);
if (md5($hookData['password']) != $password) {
$cmd = 'echo error_password >> ../git_log/log.txt';
exec($cmd);
die('ERROR');
} else {
$cmd = 'git clean -f .>> ../git_log/log.txt';
exec($cmd);
$cmd = 'git pull >> ../git_log/log.txt';
exec($cmd, $output);
$body = 'Git操作了一次并无法识别是何种操作!';
parseHook($hookData, $body);
$date = toDay();
foreach ($developInfo as $person) {
if (think_send_mail($hookData['password'], $person['email'], $person['name'], '自动邮件', $body)) {
exec("echo '$date:send Ok' >> ../git_log/email_status.txt");
} else {
exec("echo '$date:send False' >> ../git_log/email_status.txt");
}
}
die('SUCCESS');
}
function parseHook($hookData, &$body)
{
switch ($hookData['hook_name']) {
case 'push_hooks' :
$pushData = $hookData['push_data'];
if (!empty($pushData['commits']) && !empty($pushData['user'])) {
$name = $pushData['user']['name'];
$mail = $pushData['user']['email'];
$time = $pushData['user']['time'];
$body = '<h1>Operation is Commit</h1>'
. "<p>From $name $mail at $time</p>";
$i = 1;
$sum = $pushData['total_commits_count'];
$body .= "<p>$sum Commit</p>";
foreach ($pushData['commits'] as $data) {
$message = $data['message'];
$time = $data['timestamp'];
$url = $data['url'];
$authorName = $data['author']['name'];
$authorEmail = $data['author']['email'];
$authorTime = $data['author']['time'];
$body .= "<p>$i. $message $url</p>";
$body .= "<p>Author: $authorName $authorEmail at $authorTime</p>";
}
}
break;
case 'issue_hooks' :
$hookData = $hookData['push_data'];
$title = $hookData['title'];
$state = $hookData['state'];
$assignee = $hookData['assignee'];
$milestone = $hookData['milestone'];
$body = "<h1>Operation is Issue</h1>";
$body .= "<h3>$title</h3>";
$body .= "<p>state: $state</p>";
$body .= "<p>assignee : $assignee</p>";
$body .= "<p>milestone: $milestone</p>";
break;
case 'note_hooks' :
$hookData = $hookData['push_data'];
$note = $hookData['note'];
$noteType = $hookData['noteable_type'];
$authorName = $hookData['author']['user_name'];
$authorEmail = $hookData['author']['email'];
$body = "<h1>$noteType 的评论:</h1>";
$body .= "<p>$authorName $authorEmail :</p>";
$body .= "<p>$note</p>";
break;
case 'merge_request_hooks' :
$body = "<h1>一个分支合并,具体自行查看</h1>";
break;
default :
unset($hookData['password']);
$body .= "<p>" . json_encode($hookData) . "</p>";
break;
}
}
function toDay()
{
if(date_default_timezone_get() != "1Asia/Shanghai") {
date_default_timezone_set("Asia/Shanghai");
}
$date = date('Y:m;d h:i', time());
return $date;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Xjr/tubuTravel.git
git@gitee.com:Xjr/tubuTravel.git
Xjr
tubuTravel
tubuTravel
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385