Fix VcsDrivers initialization of tags and branches, and VcsRepository swallowing exceptions (#10319)
* Drivers: avoid early initialize of tags and branches * VcsRepository: do not continue if fetching root information fails because of unexpected exceptions Also rethrow 5XX exception in addition to select 4XX exceptionspull/10327/head
parent
9efe4290b6
commit
f5ffedfe60
|
@ -293,7 +293,7 @@ class GitBitbucketDriver extends VcsDriver
|
|||
}
|
||||
|
||||
if (null === $this->tags) {
|
||||
$this->tags = array();
|
||||
$tags = array();
|
||||
$resource = sprintf(
|
||||
'%s?%s',
|
||||
$this->tagsUrl,
|
||||
|
@ -311,7 +311,7 @@ class GitBitbucketDriver extends VcsDriver
|
|||
while ($hasNext) {
|
||||
$tagsData = $this->fetchWithOAuthCredentials($resource)->decodeJson();
|
||||
foreach ($tagsData['values'] as $data) {
|
||||
$this->tags[$data['name']] = $data['target']['hash'];
|
||||
$tags[$data['name']] = $data['target']['hash'];
|
||||
}
|
||||
if (empty($tagsData['next'])) {
|
||||
$hasNext = false;
|
||||
|
@ -319,6 +319,8 @@ class GitBitbucketDriver extends VcsDriver
|
|||
$resource = $tagsData['next'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
||||
return $this->tags;
|
||||
|
@ -334,7 +336,7 @@ class GitBitbucketDriver extends VcsDriver
|
|||
}
|
||||
|
||||
if (null === $this->branches) {
|
||||
$this->branches = array();
|
||||
$branches = array();
|
||||
$resource = sprintf(
|
||||
'%s?%s',
|
||||
$this->branchesUrl,
|
||||
|
@ -352,7 +354,7 @@ class GitBitbucketDriver extends VcsDriver
|
|||
while ($hasNext) {
|
||||
$branchData = $this->fetchWithOAuthCredentials($resource)->decodeJson();
|
||||
foreach ($branchData['values'] as $data) {
|
||||
$this->branches[$data['name']] = $data['target']['hash'];
|
||||
$branches[$data['name']] = $data['target']['hash'];
|
||||
}
|
||||
if (empty($branchData['next'])) {
|
||||
$hasNext = false;
|
||||
|
@ -360,6 +362,8 @@ class GitBitbucketDriver extends VcsDriver
|
|||
$resource = $branchData['next'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->branches = $branches;
|
||||
}
|
||||
|
||||
return $this->branches;
|
||||
|
|
|
@ -322,18 +322,20 @@ class GitHubDriver extends VcsDriver
|
|||
return $this->gitDriver->getTags();
|
||||
}
|
||||
if (null === $this->tags) {
|
||||
$this->tags = array();
|
||||
$tags = array();
|
||||
$resource = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/tags?per_page=100';
|
||||
|
||||
do {
|
||||
$response = $this->getContents($resource);
|
||||
$tagsData = $response->decodeJson();
|
||||
foreach ($tagsData as $tag) {
|
||||
$this->tags[$tag['name']] = $tag['commit']['sha'];
|
||||
$tags[$tag['name']] = $tag['commit']['sha'];
|
||||
}
|
||||
|
||||
$resource = $this->getNextPage($response);
|
||||
} while ($resource);
|
||||
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
||||
return $this->tags;
|
||||
|
@ -348,7 +350,7 @@ class GitHubDriver extends VcsDriver
|
|||
return $this->gitDriver->getBranches();
|
||||
}
|
||||
if (null === $this->branches) {
|
||||
$this->branches = array();
|
||||
$branches = array();
|
||||
$resource = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/git/refs/heads?per_page=100';
|
||||
|
||||
do {
|
||||
|
@ -357,12 +359,14 @@ class GitHubDriver extends VcsDriver
|
|||
foreach ($branchData as $branch) {
|
||||
$name = substr($branch['ref'], 11);
|
||||
if ($name !== 'gh-pages') {
|
||||
$this->branches[$name] = $branch['object']['sha'];
|
||||
$branches[$name] = $branch['object']['sha'];
|
||||
}
|
||||
}
|
||||
|
||||
$resource = $this->getNextPage($response);
|
||||
} while ($resource);
|
||||
|
||||
$this->branches = $branches;
|
||||
}
|
||||
|
||||
return $this->branches;
|
||||
|
|
|
@ -222,7 +222,7 @@ class SvnDriver extends VcsDriver
|
|||
public function getTags()
|
||||
{
|
||||
if (null === $this->tags) {
|
||||
$this->tags = array();
|
||||
$tags = array();
|
||||
|
||||
if ($this->tagsPath !== false) {
|
||||
$output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->tagsPath);
|
||||
|
@ -231,7 +231,7 @@ class SvnDriver extends VcsDriver
|
|||
$line = trim($line);
|
||||
if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
|
||||
if (isset($match[1], $match[2]) && $match[2] !== './') {
|
||||
$this->tags[rtrim($match[2], '/')] = $this->buildIdentifier(
|
||||
$tags[rtrim($match[2], '/')] = $this->buildIdentifier(
|
||||
'/' . $this->tagsPath . '/' . $match[2],
|
||||
$match[1]
|
||||
);
|
||||
|
@ -240,6 +240,8 @@ class SvnDriver extends VcsDriver
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
||||
return $this->tags;
|
||||
|
@ -251,7 +253,7 @@ class SvnDriver extends VcsDriver
|
|||
public function getBranches()
|
||||
{
|
||||
if (null === $this->branches) {
|
||||
$this->branches = array();
|
||||
$branches = array();
|
||||
|
||||
if (false === $this->trunkPath) {
|
||||
$trunkParent = $this->baseUrl . '/';
|
||||
|
@ -265,11 +267,11 @@ class SvnDriver extends VcsDriver
|
|||
$line = trim($line);
|
||||
if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
|
||||
if (isset($match[1], $match[2]) && $match[2] === './') {
|
||||
$this->branches['trunk'] = $this->buildIdentifier(
|
||||
$branches['trunk'] = $this->buildIdentifier(
|
||||
'/' . $this->trunkPath,
|
||||
$match[1]
|
||||
);
|
||||
$this->rootIdentifier = $this->branches['trunk'];
|
||||
$this->rootIdentifier = $branches['trunk'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -284,7 +286,7 @@ class SvnDriver extends VcsDriver
|
|||
$line = trim($line);
|
||||
if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
|
||||
if (isset($match[1], $match[2]) && $match[2] !== './') {
|
||||
$this->branches[rtrim($match[2], '/')] = $this->buildIdentifier(
|
||||
$branches[rtrim($match[2], '/')] = $this->buildIdentifier(
|
||||
'/' . $this->branchesPath . '/' . $match[2],
|
||||
$match[1]
|
||||
);
|
||||
|
@ -293,6 +295,8 @@ class SvnDriver extends VcsDriver
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->branches = $branches;
|
||||
}
|
||||
|
||||
return $this->branches;
|
||||
|
|
|
@ -212,6 +212,10 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
|
|||
$this->packageName = !empty($data['name']) ? $data['name'] : null;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if ($e instanceof TransportException && $this->shouldRethrowTransportException($e)) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($isVeryVerbose) {
|
||||
$this->io->writeError('<error>Skipped parsing '.$driver->getRootIdentifier().', '.$e->getMessage().'</error>');
|
||||
}
|
||||
|
@ -303,7 +307,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
|
|||
if ($e->getCode() === 404) {
|
||||
$this->emptyReferences[] = $identifier;
|
||||
}
|
||||
if (in_array($e->getCode(), array(401, 403, 429), true)) {
|
||||
if ($this->shouldRethrowTransportException($e)) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
@ -392,7 +396,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
|
|||
if ($e->getCode() === 404) {
|
||||
$this->emptyReferences[] = $identifier;
|
||||
}
|
||||
if (in_array($e->getCode(), array(401, 403, 429), true)) {
|
||||
if ($this->shouldRethrowTransportException($e)) {
|
||||
throw $e;
|
||||
}
|
||||
if ($isVeryVerbose) {
|
||||
|
@ -531,4 +535,12 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldRethrowTransportException(TransportException $e)
|
||||
{
|
||||
return in_array($e->getCode(), array(401, 403, 429), true) || $e->getCode() >= 500;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue