"**An error occurred with GitScord**\nPlease report in Issues tab on cr@ns Gitlab (gitlab.crans.org/elkmaennchen/gitscord-webhook)\n".$message, 'username' => 'GitScord in fail')); } // _layout functions : markdown and JSON encapsulation for Discord function push_layout($messageJSON,$JSON,$lang) { $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',]; $txt_mod_push=["fr"=>'Modifiés',"es"=>'Modificados',"en"=>'Modified',]; $txt_suppr_push=["fr"=>'Supprimés',"es"=>'Suprimidos',"en"=>'Deleted',]; $messageJSON['content'] = $JSON['total_commits_count'].' '.$txt_ligne_push[$lang] ; $messageJSON['embeds'] = array(); for ($numCommit=$JSON['total_commits_count']-1; $numCommit>=0; $numCommit--) { // strings of added, modified and deleted files in a single commit $lst_added = ""; $lst_modified = ""; $lst_deleted = ""; foreach ($JSON['commits'][$numCommit]['added'] as $filename) { $lst_added = $lst_added.$filename."\n"; } foreach ($JSON['commits'][$numCommit]['modified'] as $filename) { $lst_modified = $lst_modified.$filename."\n"; } foreach ($JSON['commits'][$numCommit]['removed'] as $filename) { $lst_deleted = $lst_deleted.$filename."\n"; } // an embed message for each commit array_push($messageJSON['embeds'], array('title'=> $txt_title_push[$lang].' *'.$JSON['project']['name'].'*', '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'])) ); } return($messageJSON); } function tag_layout($messageJSON,$JSON,$lang) { $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] ; $messageJSON['embeds'] = array(array('title'=> $txt_title_tag[$lang].' *'.$JSON['project']['name'].'*', 'description'=> $JSON['message'], 'url'=> $JSON['project']['web_url'], 'timestamp'=> $JSON['commits'][0]['timestamp'], 'author'=> array('name'=> $JSON['user_name'])),); return($messageJSON); } function issue_layout($messageJSON,$JSON,$lang) { $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',]; $txt_title_close_issue=["fr"=>'a fermé une issue dans',"es"=>'cierró un asunto en',"en"=>'closed an issue in',]; if ($JSON['object_attributes']['action'] == "open") { $txt_title_issue=$txt_title_open_issue[$lang]; } else if ($JSON['object_attributes']['action'] == "close") { $txt_title_issue=$txt_title_close_issue[$lang]; } else { $txt_title_issue=$txt_title_update_issue[$lang]; } $messageJSON['content'] = $txt_ligne_issue[$lang] ; $messageJSON['embeds'] = array(array('title'=> $txt_title_issue.' *'.$JSON['project']['name'].'*', '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'])),); return($messageJSON); } function note_layout($messageJSON,$JSON,$lang) { $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=""; if ($JSON['object_attributes']['noteable_type'] == "Issue") { $txt_object_name=$JSON['issue']['title']; } else if ($JSON['object_attributes']['noteable_type'] == "Commit") { $txt_object_name=$JSON['commit']['message']; } else if ($JSON['object_attributes']['noteable_type'] == "MergeRequest") { $txt_object_name=$JSON['merge_request']['title']; } $messageJSON['content'] = $txt_ligne_note[$lang] ; $messageJSON['embeds'] = array(array('title'=> $txt_title_note[$lang].' *'.$JSON['project']['name'].'*', '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'])),); return($messageJSON); } function MR_layout($messageJSON,$JSON,$lang,$hl) { $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',]; $txt_unknown_action=["fr"=>'a modifié une MR dans',"es"=>'cambió una MR en',"en"=>'modified a MR in',]; if ($JSON['object_attributes']['action'] == "open") { $txt_action=$txt_open_action[$lang]; $txt_action_description=$JSON['object_attributes']['description']; } else if ($JSON['object_attributes']['action'] == "merge") { $txt_action=$txt_merge_action[$lang]; $txt_action_description=$JSON['object_attributes']['source_branch'].'->'.$JSON['object_attributes']['target_branch']; } else { $txt_action=$txt_unkown_action[$lang]; $txt_action_description="*Problem with GitScord, please report.*"; } $messageJSON['content'] = $txt_ligne_MR[$lang].$hl; $messageJSON['allowed_mentions'] = array('parse'=>array("users","roles","everyone"),); $messageJSON['embeds'] = array(array('title'=> $txt_action.' *'.$JSON['project']['name'].'*', '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'])),); return($messageJSON); } ?>