Compare commits

...

4 Commits

1
.gitignore vendored

@ -2,3 +2,4 @@ webhook_test_json_mail.php
webhook_test_envoi_discord.php
gitscord_webhook_config.json
send_post_request_like_gitlab.py
payloads_examples

@ -43,6 +43,8 @@ Définition des paramètres :
* MR_manager : nom de l'utilisateur/rôle à mentionner lors d'une merge request
* bot_name : nom du bot sur Discord (remplace le nom défini dans Discord)
* bot_avatar : image de profil du bot sur Discord (remplace l'image défini dans Discord), mettre une URL absolue
* message_highlight_color : code couleur hexadécimal de la bande sur le côté du message
* secret : valeur du champ *confidentiel/secret token* dans la création du webhook dans Gitlab/Gitea pour plus de sécurité
Il suffit ensuite de mettre le fichier PHP (*gitscord_webhook.php*, mais vous pouvez le renommer à votre convenance) dans un des dossiers servis par votre serveur HTTP(S), avec le fichier *gitscord_webhook_config.json* juste a côté (ne pas renommer, ou changer le nom dans le script PHP également).
@ -89,7 +91,9 @@ Definición de los parámetros :
* language : idioma de los mensajes enviados por el bot, elegir entre en, es y fr
* MR_manager : nombre del usuario/rol que mencionar para una merge request
* bot_name : nombre del bot en Discord (remplaza el nombre definido en Discord)
* bot_avatar : imagen de perfil del bot en Discord (remplaza la imagen definida en Discord), poner una URL absoluta.
* bot_avatar : imagen de perfil del bot en Discord (remplaza la imagen definida en Discord), poner una URL absoluta
* message_highlight_color : código de color hexadecimal para la banda en el lado del mensaje
* secret : *confidentiel/secret token* dado en la creación del webhook en Gitlab/Gitea para mas seguridad
Enseguida, solo poner el archivo PHP (*gitscord_webhook.php*, pero puede renombrar lo como quiere) en una de las carpetas de su servidor HTTP(S), con el archivo *gitscord_webhook_config.json* justo a su lado (no renombrar, o cambiar el nombre también en el script PHP).
@ -136,6 +140,8 @@ Definition of the parameters :
* MR_manager : name of the user/role to be mentioned on a merge request
* bot_name : name of the bot on Discord (override the name set in Discord)
* bot_avatar : avatar image of the bot on Discord (override the image set in Discord), put an absolute URL
* message_highlight_color : hexadecimal colour code of the message side band
* secret : value of *confidential/secret token* given during webhook creation in Gitlab/Gitea to improve security
Put the PHP file (*gitscord_webhook.php*, but you can rename it as you want) in a folder of your HTTP(S) server, with the file *gitscord_webhook_config.json* in the same folder (do not rename it, or change the name in the PHP script too).

@ -29,7 +29,15 @@ if ($plainJSON != '') {
$mhl_color = "FF7000"; // default orange color if not given
}
else {
$mhl_color = $configJSON['highlight_color'];
$mhl_color = $configJSON['message_highlight_color'];
}
if ($configJSON['secret'] == '') { // if secret checking is not needed
$is_secret_checked = true;
$secret_value = "";
}
else {
$is_secret_checked = false;
$secret_value = $configJSON['secret'];
}
$messageJSON = array(); // JSON to send to Discord
if ($configJSON['bot_name'] != '') {
@ -41,35 +49,42 @@ 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
if ($is_secret_checked || $_SERVER['HTTP_X_GITLAB_TOKEN']==$secret_value) {
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);
@ -164,7 +179,7 @@ function issue_layout($messageJSON,$JSON,$lang,$mhl_color) {
'description'=> "**".$JSON['object_attributes']['title']."**\n".$JSON['object_attributes']['description'],
'url'=> $JSON['object_attributes']['url'],
'timestamp'=> $JSON['object_attributes']['last_edited_at'],
'author'=> array('name'=> $JSON['user']['name'], 'icon_url'=> $JSON['user_avatar']),
'author'=> array('name'=> $JSON['user']['name'], 'icon_url'=> $JSON['user']['avatar_url']),
'color'=> hexdec($mhl_color)),);
return($messageJSON);
}
@ -187,7 +202,7 @@ function note_layout($messageJSON,$JSON,$lang,$mhl_color) {
'description'=> "**".$JSON['object_attributes']['noteable_type']." *".$txt_object_name."***\n".$JSON['object_attributes']['note'],
'url'=> $JSON['object_attributes']['url'],
'timestamp'=> $JSON['object_attributes']['created_at'],
'author'=> array('name'=> $JSON['user']['name'], 'icon_url'=> $JSON['user_avatar']),
'author'=> array('name'=> $JSON['user']['name'], 'icon_url'=> $JSON['user']['avatar_url']),
'color'=> hexdec($mhl_color)),);
return($messageJSON);
}
@ -215,7 +230,7 @@ function MR_layout($messageJSON,$JSON,$lang,$hl,$mhl_color) {
'description'=> "**".$JSON['object_attributes']['title']."**\n".$txt_action_description,
'url'=> $JSON['object_attributes']['url'],
'timestamp'=> $JSON['object_attributes']['created_at'],
'author'=> array('name'=> $JSON['user']['name'], 'icon_url'=> $JSON['user_avatar']),
'author'=> array('name'=> $JSON['user']['name'], 'icon_url'=> $JSON['user']['avatar_url']),
'color'=> hexdec($mhl_color)),);
return($messageJSON);
}

@ -4,5 +4,6 @@
"MR_manager":"role-in-charge-of-MR",
"bot_name":"Git Stalk",
"bot_avatar":"https://railsware.com/blog/wp-content/uploads/2014/08/git-housekeeping.png",
"message_highlight_color":"FF7000"
"message_highlight_color":"FF7000",
"secret":"secret token"
}

Loading…
Cancel
Save