From c9dc32f35f7f93788b54f77a119b63781968bac2 Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Wed, 15 Jan 2025 10:43:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BF=AE=E6=94=B9git=20webhook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/gitea_webhook.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/public/gitea_webhook.php b/public/gitea_webhook.php index 9e2b40f2..df220816 100644 --- a/public/gitea_webhook.php +++ b/public/gitea_webhook.php @@ -6,32 +6,28 @@ try { // check for POST request if ($_SERVER['REQUEST_METHOD'] != 'POST') { - error_log('FAILED - not POST - '. $_SERVER['REQUEST_METHOD']); - exit(); + throw new \Exception('FAILED - not POST - '. $_SERVER['REQUEST_METHOD']); } // get content type $content_type = isset($_SERVER['CONTENT_TYPE']) ? strtolower(trim($_SERVER['CONTENT_TYPE'])) : ''; if ($content_type != 'application/json') { - error_log('FAILED - not application/json - '. $content_type); - exit(); + throw new \Exception('FAILED - not application/json - '. $content_type); } // get payload $payload = trim(file_get_contents("php://input")); if (empty($payload)) { - error_log('FAILED - no payload'); - exit(); + throw new \Exception('FAILED - no payload'); } // get header signature $header_signature = isset($_SERVER['HTTP_X_GITEA_SIGNATURE']) ? $_SERVER['HTTP_X_GITEA_SIGNATURE'] : ''; if (empty($header_signature)) { - error_log('FAILED - header signature missing'); - exit(); + throw new \Exception('FAILED - header signature missing'); } // calculate payload signature @@ -39,8 +35,7 @@ try { // check payload signature against header signature if ($header_signature !== $payload_signature) { - error_log('FAILED - payload signature'); - exit(); + throw new \Exception('FAILED - payload signature'); } // convert json to array @@ -48,8 +43,7 @@ try { // check for json decode errors if (json_last_error() !== JSON_ERROR_NONE) { - error_log('FAILED - json decode - '. json_last_error()); - exit(); + throw new \Exception('FAILED - json decode - '. json_last_error()); } exec('sudo git pull origin dev --rebase 2>&1', $result);