Skip to content

Commit

Permalink
Try to hit it in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
ekinhbayar committed Dec 7, 2016
1 parent d6f4a12 commit 3410e92
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/Plugins/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,26 @@ protected function getCommitReference(Command $command, string $path)
list($user, $repo) = explode('/', $path, 2);

$branch = $command->getParameter(1) ?? 'master';
$heads = self::BASE_URL . '/repos/' . urlencode($user) . '/' . urlencode($repo) . '/git/refs/heads/';

/** @var HttpResponse $heads, $branch */
$heads = yield $this->httpClient->request(
self::BASE_URL . '/repos/'
. urlencode($user) . '/'
. urlencode($repo) . '/git/refs/heads/'
);
$promises = \Amp\some($this->httpClient->requestMulti([
'heads' => $heads,
'branch' => $heads . urlencode($branch)
]));

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

if ($heads->getStatus() !== 200) {
throw new ReferenceNotFoundException("Failed to fetch repository for $path");
if($responses['heads']->getStatus() !== 200){
throw new ReferenceNotFoundException("Failed to fetch repository for $path. Typo?");
}

if ($branchRef->getStatus() !== 200) {
throw new ReferenceNotFoundException("Failed to fetch branch $branch for $path");
if($responses['branch']->getStatus() !== 200){
throw new ReferenceNotFoundException("Failed to fetch branch $branch for $path. Typo?");
}

$commit = json_decode($branchRef->getBody(), true);
$commit = json_decode($responses['branch']->getBody(), true);
if (!isset($commit['object']['sha'])) {
return $this->chatClient->postMessage($command->getRoom(), "Failed to fetch reference SHA for $path");
throw new ReferenceNotFoundException("Failed to fetch the last commit reference for branch $branch of $path. Typo?");
}

return $commit['object']['sha'];
Expand Down

0 comments on commit 3410e92

Please sign in to comment.