diff --git a/gitscord_webhook.php b/gitscord_webhook.php index a61d454..636484b 100644 --- a/gitscord_webhook.php +++ b/gitscord_webhook.php @@ -41,35 +41,40 @@ if ($plainJSON != '') { // process Gitlab data $JSON = json_decode($plainJSON, true); if (is_array($JSON)) { // valid JSON - switch ($JSON['object_kind']){ // type of event - case "push": // push event - $messageJSON = push_layout($messageJSON,$JSON,$lang,$mhl_color); - break; - case "tag_push": - $messageJSON = tag_layout($messageJSON,$JSON,$lang,$mhl_color); - break; - case "issue": // do the same weather its confidential or not - case "confidential_issue": - $messageJSON = issue_layout($messageJSON,$JSON,$lang,$mhl_color); - break; - case "note": // do the same weather its confidential or not - case "confidential_note": - $messageJSON = note_layout($messageJSON,$JSON,$lang,$mhl_color); - break; - case "merge_request": - // if somebody/somerole to hl, add him/it in the message - if ($configJSON['MR_manager'] != '') { $hl = " @".$configJSON['MR_manager']." "; } - else { $hl = ""; } - $messageJSON = MR_layout($messageJSON,$JSON,$lang,$hl,$mhl_color); - break; - case "job": - break; - case "pipeline": - break; - case "wiki_page": - break; - default: - send_error($url,"Unknown type of event"); + if (isset($_SERVER['HTTP_X_GITLAB_EVENT'])) { // comming from a gitlab instance + switch ($JSON['object_kind']){ // type of event + case "push": // push event + $messageJSON = push_layout($messageJSON,$JSON,$lang,$mhl_color); + break; + case "tag_push": + $messageJSON = tag_layout($messageJSON,$JSON,$lang,$mhl_color); + break; + case "issue": // do the same weather its confidential or not + case "confidential_issue": + $messageJSON = issue_layout($messageJSON,$JSON,$lang,$mhl_color); + break; + case "note": // do the same weather its confidential or not + case "confidential_note": + $messageJSON = note_layout($messageJSON,$JSON,$lang,$mhl_color); + break; + case "merge_request": + // if somebody/somerole to hl, add him/it in the message + if ($configJSON['MR_manager'] != '') { $hl = " @".$configJSON['MR_manager']." "; } + else { $hl = ""; } + $messageJSON = MR_layout($messageJSON,$JSON,$lang,$hl,$mhl_color); + break; + case "job": + break; + case "pipeline": + break; + case "wiki_page": + break; + default: + send_error($url,"Unknown type of event"); + } + } + else { + send_error($url,"Unknown git manager. Gitscord only support Gitlab."); } // sending post request to Discord send_to_discord($url,$messageJSON);