0
Gitlab 配置自定义Git Hooks,检查PHP语法错误
首先查考Gitlab官方的Hook配置
https://docs.gitlab.com/ee/administration/custom_hooks.html
配置<project>.git/custom_hooks/pre-receive
pre-receive的内容如下
#!/usr/bin/php
<?php
echo "\nRunning php linter...\n";
$params = explode(' ', file_get_contents('php://stdin'));
$ref = trim($params[1]);
$diff = array();
$return = 0;
exec("git diff --name-only $params[0] $params[1] 2> /dev/null", $diff, $return);
if ($return > 0) {
echo "Could not run git diff\n\n";
// exit(1);
}
$filename_pattern = '/\.php$/';
foreach ($diff as $file) {
if (!preg_match($filename_pattern, $file)) {
continue;
}
$tree = array();
$return = 0;
exec("git ls-tree $ref $file 2> /dev/null", $tree, $return);
if ($return > 0 || empty($tree)) {
echo "Could not run git ls-tree\n\n";
exit(1);
}
$tree = preg_split('/\s/', $tree[0]);
$fileContents = array();
exec("git cat-file $tree[1] $tree[2] 2> /dev/null", $fileContents, $return);
if ($return > 0) {
echo "Could not run git cat-file\n\n";
exit(1);
}
$fileContents = implode("\n", $fileContents);
$pipes = array();
$proc = proc_open('php -l',
array(0 => array('pipe', 'r'),
1 => array('pipe', 'w')),
$pipes);
if (!is_resource($proc)) {
echo "Could not creater php linter process\n\n";
exit(1);
}
fwrite($pipes[0], $fileContents);
fclose($pipes[0]);
fclose($pipes[1]);
$resultCode = proc_close($proc);
if ($resultCode != 0) {
echo "Error parsing file '$file'\n\n";
exit($resultCode);
}
}
echo "No errors detected\n\n";
exit(0);
Recommend
Recent search keywords
- 回来找我
- inspector calls
- Louisiana
- Self-enabling
- flexibility
- Infrastructure
- United Arab Emirates
- repurpose
- El Salvador Colon US Dollar
- Mountains
- Switzerland
- indexing
- Ergonomic
- e-markets
- Administrator
- Sausages
- Program
- engineer
- Bahrain
- cross-media
- product
- holistic
- Ports
- Open-architected
- Synergistic
- Automotive
- Moroccan Dirham
- Generic Steel Salad
- communities
- algorithm
- Kina
- reboot
- Future
- SMTP
- Lake
- Cotton
- Clothing
- monetize
- revolutionize
- purple
- Generic
- Tirol
- Applications
- architecture
- Customizable
- portals
- Rubber
- Integrated
- Total
- Credit Card Account
- Avon
- User-friendly
- Angola
- schemas
- US Dollar
- clicks-and-mortar
- Pants
- Grnit
- Intelligent
- multi-byte
- Filippinerna
- online
- -1" or 3+860-860-1=0+0+0+1 --
- answers
- @@l00ww
- iecho.cc
- golbel
- 129084
- cssbuilder
- DOVE加速器
- Graphcore
- n950f
- eb341820cd3a3485461a61b1e97d31b1
- onepiece
- Samsung gaming
- contact
- hindi
- golang9478590
- http\x3A\x2F\x2Fbestbuy.com
- 哥们
- 黑兽
- -4307" or 5781=5781 and "yvut"="yvut
- yiyo
- Inda
- -1" or 2+501-501-1=0+0+0+1 --
- upi
- 印度支付通道
- AC8227L+Android+head+unit+4gb/32gb
- xperia+5+v
- org+chart
- Iptv+2023
- san+francisco+web+development
- 8257+logo
- hacks+in+blooket
- 深入理解+Gem5
- xperia+5+v+kernel
- hacks in blooket
- Iptv 2023
- teligu
- Read.Me
一般我都是本地配置