Skip to content

Commit

Permalink
Merge 2e633ad into 8968e71
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerogiven committed May 2, 2022
2 parents 8968e71 + 2e633ad commit 69312e5
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions src/Check/AbstractCodeCoverageCheck.php
Expand Up @@ -39,9 +39,35 @@ public function getCodecovCoverage()
{
$slug = $this->getSuite()->getRepositorySlug();
try {
// Note: assume everyone uses the master branch
$result = $this->getRequestClient()
->get('https://codecov.io/api/gh/' . $slug . '/branch/master')
->get('https://codecov.io/api/gh/' . $slug . '/branches')
->getBody();
} catch (Exception $ex) {
if ($logger = $this->getSuite()->getLogger()) {
$logger->debug($ex->getMessage());
}
$result = '';
}
$response = json_decode($result, true);

// Fetch failure
if (!$response) {
return false;
}

// Not set up (404)
if (isset($response['meta']['status']) && (int) $response['meta']['status'] !== 200) {
return false;
}

$defaultBranch = 'master';
if (isset($response['repo']['branch'])) {
$defaultBranch = $response['repo']['branch'];
}

try {
$result = $this->getRequestClient()
->get('https://codecov.io/api/gh/' . $slug . '/branch/' . $defaultBranch)
->getBody();
} catch (Exception $ex) {
if ($logger = $this->getSuite()->getLogger()) {
Expand Down Expand Up @@ -95,15 +121,18 @@ public function getScrutinizerCoverage()
return false;
}

// Not set up (404)
if (!isset($response['applications']['master'])) {
$defaultBranch = 'master';
if (isset($response['default_branch'])) {
$defaultBranch = $response['default_branch'];
}

if (!isset($response['applications'][$defaultBranch]['index']['_embedded']['project']['metric_values'])) {
return false;
}

// Get coverage result
$metrics = $response['applications']['master']['index']['_embedded']['project']['metric_values'];
if (isset($metrics['scrutinizer.test_coverage'])) {
return $metrics['scrutinizer.test_coverage'] * 100;
$metrics = $response['applications'][$defaultBranch]['index']['_embedded']['project']['metric_values'];
if (isset($metrics['scrutinizer.quality'])) {
return $metrics['scrutinizer.quality'] * 100;
}

return 0;
Expand Down

0 comments on commit 69312e5

Please sign in to comment.