Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
date_default_timezone_set('Asia/Tokyo');
$url = "[webhookurl]";
header('Content-type: application/json; charset=utf-8');
function create_message($payload) {
$build_url = "https://magnum.travis-ci.com/" . $payload['repository']['owner_name']
. "/" . $payload['repository']['name'] . "/builds/" . $payload['id'];
$commit_url = $payload['repository']['url'] . "/commit/" . $payload['commit'];
$compare_url = $payload['compare_url'];
$committer = $payload['committer_name'];
if ($payload['status'] === 0) {
$message = array(
"username" => "Eri Ayase",
"icon_emoji" => ":eri:",
"attachments" => array(
array(
"color" => "good",
"title" => "ハラショー!ビルド成功!",
"title_link" => $build_url,
"text" => "releaseにマージしてデプロイしてね♪"
)
)
);
} else {
$message = array(
"username" => "Umi Sonoda",
"icon_emoji" => ":umi:",
"attachments" => array(
array(
"color" => "danger",
"title" => "ビルド失敗なんて破廉恥です!",
"title_link" => $build_url,
"text" => "ハッキリ言いますが、ビルド失敗は迷惑です!だからすぐに直してください!"
)
)
);
}
return $message;
}
if ('POST' === $_SERVER['REQUEST_METHOD']) {
if (!isset($_POST['payload'])) {
header('HTTP/1.1 400 Bad Request');
exit;
}
$payload = json_decode($_POST['payload'], true);
$data = create_message($payload);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, 'Content-type: application/json');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.