|
|
|
@ -23,7 +23,13 @@ if ($plainJSON != '') {
|
|
|
|
|
$languages = array("fr", "es", "en");
|
|
|
|
|
$lang = $configJSON['language']; // language used for messages
|
|
|
|
|
if (!in_array($lang, $languages)) {
|
|
|
|
|
$lang="en"; // default language if asked language not available
|
|
|
|
|
$lang = "en"; // default language if asked language not available
|
|
|
|
|
}
|
|
|
|
|
if ($configJSON['message_highlight_color'] == '') {
|
|
|
|
|
$mhl_color = "FF7000"; // default orange color if not given
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$mhl_color = $configJSON['highlight_color'];
|
|
|
|
|
}
|
|
|
|
|
$messageJSON = array(); // JSON to send to Discord
|
|
|
|
|
if ($configJSON['bot_name'] != '') {
|
|
|
|
@ -37,24 +43,24 @@ if ($plainJSON != '') {
|
|
|
|
|
if (is_array($JSON)) { // valid JSON
|
|
|
|
|
switch ($JSON['object_kind']){ // type of event
|
|
|
|
|
case "push": // push event
|
|
|
|
|
$messageJSON = push_layout($messageJSON,$JSON,$lang);
|
|
|
|
|
$messageJSON = push_layout($messageJSON,$JSON,$lang,$mhl_color);
|
|
|
|
|
break;
|
|
|
|
|
case "tag_push":
|
|
|
|
|
$messageJSON = tag_layout($messageJSON,$JSON,$lang);
|
|
|
|
|
$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);
|
|
|
|
|
$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);
|
|
|
|
|
$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);
|
|
|
|
|
$messageJSON = MR_layout($messageJSON,$JSON,$lang,$hl,$mhl_color);
|
|
|
|
|
break;
|
|
|
|
|
case "job":
|
|
|
|
|
break;
|
|
|
|
@ -91,7 +97,7 @@ function send_error($url,$message="") { // showing an error on Discord chan
|
|
|
|
|
|
|
|
|
|
// _layout functions : markdown and JSON encapsulation for Discord
|
|
|
|
|
|
|
|
|
|
function push_layout($messageJSON,$JSON,$lang) {
|
|
|
|
|
function push_layout($messageJSON,$JSON,$lang,$mhl_color) {
|
|
|
|
|
$txt_ligne_push=["fr"=>'nouveau(x) commit(s)',"es"=>'nuevo(s) commit(s)',"en"=>'new commit(s)',];
|
|
|
|
|
$txt_title_push=["fr"=>'a push dans',"es"=>'hizo un push en',"en"=>'pushed in',];
|
|
|
|
|
$txt_add_push=["fr"=>'Ajoutés',"es"=>'Añadidos',"en"=>'Added',];
|
|
|
|
@ -119,13 +125,14 @@ function push_layout($messageJSON,$JSON,$lang) {
|
|
|
|
|
'description'=> "**".$JSON['commits'][$numCommit]['message']."**\n\n__".$txt_add_push[$lang]."__\n".$lst_added."\n__".$txt_mod_push[$lang]."__\n".$lst_modified."\n__".$txt_suppr_push[$lang]."__\n".$lst_deleted,
|
|
|
|
|
'url'=> $JSON['commits'][$numCommit]['url'],
|
|
|
|
|
'timestamp'=> $JSON['commits'][$numCommit]['timestamp'],
|
|
|
|
|
'author'=> array('name'=> $JSON['commits'][$numCommit]['author']['name'], 'icon_url'=> $JSON['user_avatar']))
|
|
|
|
|
'author'=> array('name'=> $JSON['commits'][$numCommit]['author']['name'], 'icon_url'=> $JSON['user_avatar']),
|
|
|
|
|
'color'=> hexdec($mhl_color))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return($messageJSON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tag_layout($messageJSON,$JSON,$lang) {
|
|
|
|
|
function tag_layout($messageJSON,$JSON,$lang,$mhl_color) {
|
|
|
|
|
$txt_ligne_tag=["fr"=>'Nouveau tag',"es"=>'Nuevo tag',"en"=>'New tag',];
|
|
|
|
|
$txt_title_tag=["fr"=>'a tagué un commit dans',"es"=>'hizo un tag en',"en"=>'tagged a commit in',];
|
|
|
|
|
$messageJSON['content'] = $txt_ligne_tag[$lang] ;
|
|
|
|
@ -133,11 +140,12 @@ function tag_layout($messageJSON,$JSON,$lang) {
|
|
|
|
|
'description'=> $JSON['message'],
|
|
|
|
|
'url'=> $JSON['project']['web_url'],
|
|
|
|
|
'timestamp'=> $JSON['commits'][0]['timestamp'],
|
|
|
|
|
'author'=> array('name'=> $JSON['user_name'])),);
|
|
|
|
|
'author'=> array('name'=> $JSON['user_name'], 'icon_url'=> $JSON['user_avatar']),
|
|
|
|
|
'color'=> hexdec($mhl_color)),);
|
|
|
|
|
return($messageJSON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function issue_layout($messageJSON,$JSON,$lang) {
|
|
|
|
|
function issue_layout($messageJSON,$JSON,$lang,$mhl_color) {
|
|
|
|
|
$txt_ligne_issue=["fr"=>'Nouveau problème',"es"=>'Nuevo problema',"en"=>'New issue',];
|
|
|
|
|
$txt_title_open_issue=["fr"=>'a ouvert une issue dans',"es"=>'abrió un asunto en',"en"=>'opened an issue in',];
|
|
|
|
|
$txt_title_update_issue=["fr"=>'a mis à jour une issue dans',"es"=>'actualizó un asunto en',"en"=>'modified an issue in',];
|
|
|
|
@ -156,11 +164,12 @@ function issue_layout($messageJSON,$JSON,$lang) {
|
|
|
|
|
'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'])),);
|
|
|
|
|
'author'=> array('name'=> $JSON['user']['name'], 'icon_url'=> $JSON['user_avatar']),
|
|
|
|
|
'color'=> hexdec($mhl_color)),);
|
|
|
|
|
return($messageJSON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function note_layout($messageJSON,$JSON,$lang) {
|
|
|
|
|
function note_layout($messageJSON,$JSON,$lang,$mhl_color) {
|
|
|
|
|
$txt_ligne_note=["fr"=>'Nouvelle note',"es"=>'Nueva note',"en"=>'New note',];
|
|
|
|
|
$txt_title_note=["fr"=>'a noté quelque chose dans',"es"=>'marcó algo en',"en"=>'noted something in',];
|
|
|
|
|
$txt_object_name="";
|
|
|
|
@ -178,11 +187,12 @@ function note_layout($messageJSON,$JSON,$lang) {
|
|
|
|
|
'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'])),);
|
|
|
|
|
'author'=> array('name'=> $JSON['user']['name'], 'icon_url'=> $JSON['user_avatar']),
|
|
|
|
|
'color'=> hexdec($mhl_color)),);
|
|
|
|
|
return($messageJSON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function MR_layout($messageJSON,$JSON,$lang,$hl) {
|
|
|
|
|
function MR_layout($messageJSON,$JSON,$lang,$hl,$mhl_color) {
|
|
|
|
|
$txt_ligne_MR=["fr"=>'Nouvelle merge request',"es"=>'Nueva merge request',"en"=>'New merge request',];
|
|
|
|
|
$txt_open_action=["fr"=>'a ouvert une MR dans',"es"=>'abrió una MR en',"en"=>'opened a MR in',];
|
|
|
|
|
$txt_merge_action=["fr"=>'a mergé une MR dans',"es"=>'ejecutó una MR en',"en"=>'merged a MR in',];
|
|
|
|
@ -205,7 +215,8 @@ function MR_layout($messageJSON,$JSON,$lang,$hl) {
|
|
|
|
|
'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'])),);
|
|
|
|
|
'author'=> array('name'=> $JSON['user']['name'], 'icon_url'=> $JSON['user_avatar']),
|
|
|
|
|
'color'=> hexdec($mhl_color)),);
|
|
|
|
|
return($messageJSON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|