diff --git a/src/PHPCensor/Model/Build/BitbucketBuild.php b/src/PHPCensor/Model/Build/BitbucketBuild.php index b6a7b8e4..0268fd3a 100644 --- a/src/PHPCensor/Model/Build/BitbucketBuild.php +++ b/src/PHPCensor/Model/Build/BitbucketBuild.php @@ -44,7 +44,7 @@ class BitbucketBuild extends RemoteGitBuild /** * Send status updates to any relevant third parties (i.e. Bitbucket) * - * @return bool + * @return boolean */ public function sendStatusPostback() { @@ -95,7 +95,7 @@ class BitbucketBuild extends RemoteGitBuild $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 @@ class BitbucketBuild extends RemoteGitBuild ); $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(), diff --git a/src/PHPCensor/Model/Build/GithubBuild.php b/src/PHPCensor/Model/Build/GithubBuild.php index 524dffc4..cb6b4053 100644 --- a/src/PHPCensor/Model/Build/GithubBuild.php +++ b/src/PHPCensor/Model/Build/GithubBuild.php @@ -42,8 +42,10 @@ class GithubBuild extends RemoteGitBuild } /** - * 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 @@ class GithubBuild extends RemoteGitBuild $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 @@ class GithubBuild extends RemoteGitBuild ] ]); - return true; + $status = (integer)$response->getStatusCode(); + + return ($status >= 200 && $status < 300); } /**