Skip to content

Commit

Permalink
Hit it twice
Browse files Browse the repository at this point in the history
  • Loading branch information
ekinhbayar committed Dec 6, 2016
1 parent 861e6b2 commit ccc64e1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Plugins/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,29 @@ protected function getCommitReference(Command $command, string $path)

$branch = $command->getParameter(1) ?? 'master';

/** @var HttpResponse $response */
$response = yield $this->httpClient->request(
/** @var HttpResponse $heads, $branch */
$heads = yield $this->httpClient->request(

This comment has been minimized.

Copy link
@staabm

staabm Dec 6, 2016

Contributor

You could do those 2 requests in parallel

self::BASE_URL . '/repos/'
. urlencode($user) . '/'
. urlencode($repo) . '/git/refs/heads/'
);

$branchRef = yield $this->httpClient->request(
self::BASE_URL . '/repos/'
. urlencode($user) . '/'
. urlencode($repo) . '/git/refs/heads/'
. urlencode($branch)
);

if ($response->getStatus() !== 200) {
if ($heads->getStatus() !== 200) {
throw new ReferenceNotFoundException("Failed to fetch repository for $path");
}

$commit = json_decode($response->getBody(), true);
if ($branchRef->getStatus() !== 200) {
throw new ReferenceNotFoundException("Failed to fetch branch $branch for $path");
}

$commit = json_decode($branchRef->getBody(), true);
if (!isset($commit['object']['sha'])) {
return $this->chatClient->postMessage($command->getRoom(), "Failed to fetch reference SHA for $path");
}
Expand Down

0 comments on commit ccc64e1

Please sign in to comment.