get('php-censor.bitbucket.username'); $appPassword = Config::getInstance()->get('php-censor.bitbucket.app_password'); if (empty($username) || empty($appPassword)) { return; } $url = '/1.0/repositories/' . $repo . '/pullrequests/' . $pullId . '/comments/'; $client = new Client(['base_uri' => 'https://api.bitbucket.org']); $client->post($url, [ 'auth' => [$username, $appPassword], 'headers' => [ 'Content-Type' => 'application/json', ], 'json' => [ 'content' => $comment, 'anchor' => substr($commitId, 0, 12), 'filename' => $file, 'line_to' => $line, ], ]); } /** * Create a comment on a Bitbucket commit. * * @param $repo * @param $commitId * @param $file * @param $line * @param $comment * @return null */ public function createCommitComment($repo, $commitId, $file, $line, $comment) { $username = Config::getInstance()->get('php-censor.bitbucket.username'); $appPassword = Config::getInstance()->get('php-censor.bitbucket.app_password'); if (empty($username) || empty($appPassword)) { return; } $url = '/1.0/repositories/' . $repo . '/changesets/' . $commitId . '/comments'; $client = new Client(['base_uri' => 'https://api.bitbucket.org']); $client->post($url, [ 'auth' => [$username, $appPassword], 'headers' => [ 'Content-Type' => 'application/json', ], 'json' => [ 'content' => $comment, 'filename' => $file, 'line_to' => $line, ], ]); } /** * @param string $repo * @param int $pullRequestId * * @return string */ public function getPullRequestDiff($repo, $pullRequestId) { $username = Config::getInstance()->get('php-censor.bitbucket.username'); $appPassword = Config::getInstance()->get('php-censor.bitbucket.app_password'); if (empty($username) || empty($appPassword)) { return; } $url = '/2.0/repositories/' . $repo . '/pullrequests/' . $pullRequestId . '/diff'; $client = new Client(['base_uri' => 'https://api.bitbucket.org']); $response = $client->get($url, ['auth' => [$username, $appPassword]]); return (string)$response->getBody(); } }