Skip to content

Instantly share code, notes, and snippets.

@cmbuckley
Created February 7, 2018 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cmbuckley/b713300e34396deefc8f8a8ea96d7f6b to your computer and use it in GitHub Desktop.
Save cmbuckley/b713300e34396deefc8f8a8ea96d7f6b to your computer and use it in GitHub Desktop.
Webhook from Contentful to Travis
<?php
$token = $_SERVER['HTTP_AUTHORIZATION'];
$slug = urlencode($_SERVER['HTTP_X_TRAVIS_REPOSITORY']);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://api.travis-ci.org/repo/$slug/requests",
CURLOPT_POSTFIELDS => json_encode([
'request' => [
'branch' => $_SERVER['HTTP_X_TRAVIS_BRANCH'],
'message' => $_SERVER['HTTP_X_CONTENTFUL_TOPIC'],
]
]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Accept: application/json',
'Travis-API-Version: 3',
"Authorization: $token",
],
CURLOPT_RETURNTRANSFER => true,
CURLINFO_HEADER_OUT => true,
CURLOPT_POST => true,
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$request = curl_getinfo($ch, CURLINFO_HEADER_OUT);
curl_close($ch);
header('Content-Type: application/json');
header('', true, $status);
echo $response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment