commit
66dc66c283
|
@ -51,6 +51,9 @@ EOT
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$composer = $this->getComposer(false);
|
$composer = $this->getComposer(false);
|
||||||
|
@ -98,8 +101,9 @@ EOT
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->getIO()->write('Checking github.com rate limit: ', false);
|
$this->getIO()->write('Checking github.com rate limit: ', false);
|
||||||
|
try {
|
||||||
$rate = $this->getGithubRateLimit('github.com');
|
$rate = $this->getGithubRateLimit('github.com');
|
||||||
|
$this->outputResult(true);
|
||||||
if (10 > $rate['remaining']) {
|
if (10 > $rate['remaining']) {
|
||||||
$this->getIO()->write('<warning>WARNING</warning>');
|
$this->getIO()->write('<warning>WARNING</warning>');
|
||||||
$this->getIO()->write(sprintf(
|
$this->getIO()->write(sprintf(
|
||||||
|
@ -111,8 +115,13 @@ EOT
|
||||||
$rate['remaining'],
|
$rate['remaining'],
|
||||||
$rate['limit']
|
$rate['limit']
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
if ($e instanceof TransportException && $e->getCode() === 401) {
|
||||||
|
$this->outputResult('<comment>The oauth token for '.$domain.' seems invalid, run "composer config --global --unset github-oauth.'.$domain.'" to remove it</comment>');
|
||||||
} else {
|
} else {
|
||||||
$this->getIO()->write('<info>OK</info>');
|
$this->outputResult($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,25 +272,23 @@ EOT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $domain
|
||||||
|
* @param string $token
|
||||||
|
* @return array
|
||||||
|
* @throws TransportException
|
||||||
|
*/
|
||||||
private function getGithubRateLimit($domain, $token = null)
|
private function getGithubRateLimit($domain, $token = null)
|
||||||
{
|
{
|
||||||
if ($token) {
|
if ($token) {
|
||||||
$this->getIO()->setAuthentication($domain, $token, 'x-oauth-basic');
|
$this->getIO()->setAuthentication($domain, $token, 'x-oauth-basic');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
$url = $domain === 'github.com' ? 'https://api.'.$domain.'/rate_limit' : 'https://'.$domain.'/api/rate_limit';
|
$url = $domain === 'github.com' ? 'https://api.'.$domain.'/rate_limit' : 'https://'.$domain.'/api/rate_limit';
|
||||||
$json = $this->rfs->getContents($domain, $url, false, array('retry-auth-failure' => false));
|
$json = $this->rfs->getContents($domain, $url, false, array('retry-auth-failure' => false));
|
||||||
$data = json_decode($json, true);
|
$data = json_decode($json, true);
|
||||||
|
|
||||||
return $data['resources']['core'];
|
return $data['resources']['core'];
|
||||||
} catch (\Exception $e) {
|
|
||||||
if ($e instanceof TransportException && $e->getCode() === 401) {
|
|
||||||
return '<comment>The oauth token for '.$domain.' seems invalid, run "composer config --global --unset github-oauth.'.$domain.'" to remove it</comment>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkDiskSpace($config)
|
private function checkDiskSpace($config)
|
||||||
|
@ -308,6 +315,9 @@ EOT
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool|string|\Exception $result
|
||||||
|
*/
|
||||||
private function outputResult($result)
|
private function outputResult($result)
|
||||||
{
|
{
|
||||||
if (true === $result) {
|
if (true === $result) {
|
||||||
|
|
Loading…
Reference in New Issue