Skip to content

Instantly share code, notes, and snippets.

@rluisr
Created December 17, 2015 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rluisr/6be220ef95c66740e6ba to your computer and use it in GitHub Desktop.
Save rluisr/6be220ef95c66740e6ba to your computer and use it in GitHub Desktop.
GitHub Webhook. Deploy to Twitter.
<?php
require_once 'tweet/tweet.php';
$secret = "3LxNHeLXEzJS";
//全てのリクエストヘッダーを取得
$headers = getallheaders();
//署名されたのを取得
$hubSignature = $headers['X-Hub-Signature'];
//$alog にアルゴリズム $hash にハッシュ
list($algo, $hash) = explode('=', $hubSignature);
//存在する全てのデータを取得
$payload = file_get_contents('php://input');
//ハッシュ値を生成
$payloadHash = hash_hmac('sha1', $payload, $secret);
//ここでセキュリティチェック
if ($hash !== $payloadHash) {
die("E R R O R ");
}
$data = json_decode($payload, true);
$repository = $data['repository']['name'];
$url = $data['repository']['html_url'];
$author = $data['commits']['author']['name'];
$message = $data['head_commit']['message'];
toTweet("@int_sorarinu @Ailice_ @lu_iskun \r\nRepository has been updated!\r\n[${repository}]-${url}-♡${author}♡-${message}");
function getallheaders()
{
$headers = '';
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment