Hallo elitepvpers,
kleines Snippet um die Discord webhooks für gitlab zu benutzen.
Einfach Irgendwo hochladen wo cUrl erlaubt ist und gitlab darauf verlinken.
kleines Snippet um die Discord webhooks für gitlab zu benutzen.
Einfach Irgendwo hochladen wo cUrl erlaubt ist und gitlab darauf verlinken.
PHP Code:
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'On');
/* Variables editing */
$GitlabToken = "";
$DiscordWebHook = "https://ptb.discordapp.com/api/webhooks/";
if( $_SERVER['HTTP_X_GITLAB_TOKEN'] ) {
if( $_SERVER['HTTP_X_GITLAB_TOKEN'] = $GitlabToken ) {
$json = file_get_contents('php://input');
$action = json_decode($json, true);
$payloadArr = array(
"username" => "Gitlab",
"icon_url" => "http://i.epvpimg.com/Rdh7c.jpg",
"text" => $action['project']['name'],
"attachments" => array(
array(
"author_icon" => $action['user_avatar'],
"author_name" => $action['commits'][0]['author']['name'],
"color" => "#ffffff",
"fields" => array(
array(
"title" => $action['event_name'],
"value" => "[" . substr($action['commits'][0]['id'], 0, 7) . "](" . $action['commits'][0]['url'] . ") ",
),
),
),
),
);
$payload = json_encode($payloadArr);
$ch = curl_init();
$options = array(
CURLOPT_URL => $DiscordWebHook . "/slack",
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$httpCodeReturned = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result_str = json_decode($result);
/*
* print_r($result_str);
* print($payload);
* */
print($httpCodeReturned);
}
}