refactor: 修改git webhook
This commit is contained in:
@@ -6,32 +6,28 @@ try {
|
|||||||
|
|
||||||
// check for POST request
|
// check for POST request
|
||||||
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
||||||
error_log('FAILED - not POST - '. $_SERVER['REQUEST_METHOD']);
|
throw new \Exception('FAILED - not POST - '. $_SERVER['REQUEST_METHOD']);
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get content type
|
// get content type
|
||||||
$content_type = isset($_SERVER['CONTENT_TYPE']) ? strtolower(trim($_SERVER['CONTENT_TYPE'])) : '';
|
$content_type = isset($_SERVER['CONTENT_TYPE']) ? strtolower(trim($_SERVER['CONTENT_TYPE'])) : '';
|
||||||
|
|
||||||
if ($content_type != 'application/json') {
|
if ($content_type != 'application/json') {
|
||||||
error_log('FAILED - not application/json - '. $content_type);
|
throw new \Exception('FAILED - not application/json - '. $content_type);
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get payload
|
// get payload
|
||||||
$payload = trim(file_get_contents("php://input"));
|
$payload = trim(file_get_contents("php://input"));
|
||||||
|
|
||||||
if (empty($payload)) {
|
if (empty($payload)) {
|
||||||
error_log('FAILED - no payload');
|
throw new \Exception('FAILED - no payload');
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get header signature
|
// get header signature
|
||||||
$header_signature = isset($_SERVER['HTTP_X_GITEA_SIGNATURE']) ? $_SERVER['HTTP_X_GITEA_SIGNATURE'] : '';
|
$header_signature = isset($_SERVER['HTTP_X_GITEA_SIGNATURE']) ? $_SERVER['HTTP_X_GITEA_SIGNATURE'] : '';
|
||||||
|
|
||||||
if (empty($header_signature)) {
|
if (empty($header_signature)) {
|
||||||
error_log('FAILED - header signature missing');
|
throw new \Exception('FAILED - header signature missing');
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate payload signature
|
// calculate payload signature
|
||||||
@@ -39,8 +35,7 @@ try {
|
|||||||
|
|
||||||
// check payload signature against header signature
|
// check payload signature against header signature
|
||||||
if ($header_signature !== $payload_signature) {
|
if ($header_signature !== $payload_signature) {
|
||||||
error_log('FAILED - payload signature');
|
throw new \Exception('FAILED - payload signature');
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert json to array
|
// convert json to array
|
||||||
@@ -48,8 +43,7 @@ try {
|
|||||||
|
|
||||||
// check for json decode errors
|
// check for json decode errors
|
||||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
error_log('FAILED - json decode - '. json_last_error());
|
throw new \Exception('FAILED - json decode - '. json_last_error());
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exec('sudo git pull origin dev --rebase 2>&1', $result);
|
exec('sudo git pull origin dev --rebase 2>&1', $result);
|
||||||
|
|||||||
Reference in New Issue
Block a user