Permalink
Browse files

Fixed error with Github commit status.

  • Loading branch information...
corpsee committed Dec 28, 2017
1 parent daac392 commit b95992b0058a12f6f808c7c2467e82b2c7536f49
Showing with 19 additions and 12 deletions.
  1. +6 −6 src/PHPCensor/Model/Build/BitbucketBuild.php
  2. +13 −6 src/PHPCensor/Model/Build/GithubBuild.php
@@ -44,7 +44,7 @@ public function getTagLink()
/**
* Send status updates to any relevant third parties (i.e. Bitbucket)
*
* @return bool
* @return boolean
*/
public function sendStatusPostback()
{
@@ -95,7 +95,7 @@ public function sendStatusPostback()
$phpCensorUrl = Config::getInstance()->get('php-censor.url');
$url = sprintf(
$url = sprintf(
'/2.0/repositories/%s/commit/%s/statuses/build',
$this->getExtra('build_type') == 'pull_request'
? $this->getExtra('remote_reference')
@@ -104,15 +104,15 @@ public function sendStatusPostback()
);
$client = new Client([
'base_uri' => 'https://api.bitbucket.org',
'base_uri' => 'https://api.bitbucket.org',
'http_errors' => false,
]);
$response = $client->post($url, [
'auth' => [$username, $appPassword],
'headers' => [
'auth' => [$username, $appPassword],
'headers' => [
'Content-Type' => 'application/json',
],
'json' => [
'json' => [
'state' => $status,
'key' => 'PHP-CENSOR',
'url' => $phpCensorUrl . '/build/view/' . $this->getId(),
@@ -42,8 +42,10 @@ public function getTagLink()
}
/**
* Send status updates to any relevant third parties (i.e. Github)
*/
* Send status updates to any relevant third parties (i.e. Github)
*
* @return boolean
*/
public function sendStatusPostback()
{
if (!in_array($this->getSource(), [Build::SOURCE_WEBHOOK, Build::SOURCE_WEBHOOK_PULL_REQUEST], true)) {
@@ -91,9 +93,12 @@ public function sendStatusPostback()
$phpCensorUrl = Config::getInstance()->get('php-censor.url');
$url = 'https://api.github.com/repos/' . $project->getReference() . '/statuses/' . $this->getCommitId();
$client = new Client();
$client->post($url, [
$url = '/repos/' . $project->getReference() . '/statuses/' . $this->getCommitId();
$client = new Client([
'base_uri' => 'https://api.github.com',
'http_errors' => false,
]);
$response = $client->post($url, [
'headers' => [
'Authorization' => 'token ' . $token,
'Content-Type' => 'application/x-www-form-urlencoded'
@@ -106,7 +111,9 @@ public function sendStatusPostback()
]
]);
return true;
$status = (integer)$response->getStatusCode();
return ($status >= 200 && $status < 300);
}
/**

0 comments on commit b95992b

Please sign in to comment.