/
ScrutinizerCheck.php
58 lines (48 loc) · 1.51 KB
/
ScrutinizerCheck.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace SilverStripe\ModuleRatings\Check;
use Exception;
use SilverStripe\ModuleRatings\Check;
class ScrutinizerCheck extends Check
{
const THRESHOLD = 6.5;
public function getKey()
{
return 'good_scrutinizer_score';
}
public function getDescription()
{
return 'Has Scrutinizer CI configured and a "good" score (greater than '
. self::THRESHOLD . '/10, requires slug)';
}
public function run()
{
// This check requires a repository slug to be provided
$slug = $this->getSuite()->getRepositorySlug();
if (!$slug) {
return;
}
try {
$result = $this->getRequestClient()
->get('https://scrutinizer-ci.com/api/repositories/g/' . $slug)
->getBody();
} catch (Exception $ex) {
if ($logger = $this->getSuite()->getLogger()) {
$logger->debug($ex->getMessage());
}
$result = '';
}
$response = json_decode($result, true);
// Fetch failure
if (!$response) {
return;
}
// Not set up (404)
if (!isset($response['applications']['master']['index']['_embedded']['project']['metric_values'])) {
return;
}
$metrics = $response['applications']['master']['index']['_embedded']['project']['metric_values'];
if ($metrics['scrutinizer.quality'] >= self::THRESHOLD) {
$this->setSuccessful(true);
}
}
}