1
0
Fork 0
mirror of https://gitlab.crans.org/elkmaennchen/gitscord-webhook synced 2025-10-11 02:00:04 +02:00

check if the request come from Gitlab

This commit is contained in:
elkmaennchen 2020-10-29 18:36:41 +01:00
parent d0fa8493e7
commit 86e2d641b7

View file

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