Passed
Push — master ( a0c2c0...1d066e )
by Ronan
05:56 queued 02:14
created

Github::getRepositoryLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 9
ccs 0
cts 8
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\Provider;
4
5
use App\Builder;
6
use App\Facades\Log;
7
use App\Facades\Settings;
8
use App\Model\Deployment;
9
use App\Model\Project;
10
use App\Provider\AbstractProvider;
11
use App\Provider\ProviderInterface;
12
use Closure;
13
use Exception;
14
use GuzzleHttp\ClientInterface;
15
use GuzzleHttp\Psr7\stream_for;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\Psr7\stream_for was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Psr\Http\Message\StreamInterface;
17
use Ronanchilvers\Foundation\Config;
18
use Ronanchilvers\Utility\Str;
19
use RuntimeException;
20
use Symfony\Component\Process\Exception\ProcessFailedException;
21
use Symfony\Component\Process\Process;
22
use Symfony\Component\Yaml\Yaml;
23
24
/**
25
 * Github source control provider
26
 *
27
 * @author Ronan Chilvers <[email protected]>
28
 */
29
class Github extends AbstractProvider implements ProviderInterface
30
{
31
    /**
32
     * @var array
33
     */
34
    protected $typesHandled = ['github'];
35
36
    /**
37
     * @var string
38
     */
39
    protected $headUrl = 'https://api.github.com/repos/{repository}/git/refs/heads/{branch}';
40
41
    /**
42
     * @var string
43
     */
44
    protected $commitUrl = 'https://api.github.com/repos/{repository}/commits/{sha}';
45
46
    /**
47
     * @var string
48
     */
49
    protected $downloadUrl = 'https://api.github.com/repos/{repository}/tarball/{sha}';
50
51
    /**
52
     * @var string
53
     */
54
    protected $configUrl = 'https://api.github.com/repos/{repository}/contents/deploy.yaml?ref={sha}';
55
56
    /**
57
     * @var string
58
     */
59
    protected $repoUrl = 'https://github.com/{repository}';
60
61
    /**
62
     * @var string
63
     */
64
    protected $branchUrl = 'https://github.com/{repository}/tree/{branch}';
65
66
    /**
67
     * @var string
68
     */
69
    protected $shaUrl = 'https://github.com/{repository}/commit/{sha}';
70
71
    /**
72
     * @see \App\Provider\ProviderInterface::getHeadInfo()
73
     */
74
    public function getHeadInfo(string $repository, string $branch)
75
    {
76
        $params = [
77
            'repository' => $repository,
78
            'branch'     => $branch,
79
        ];
80
        $url = Str::moustaches(
81
            $this->headUrl,
82
            $params
83
        );
84
        $data = $this->getJSON($url);
85
        $params['sha'] = $data['object']['sha'];
86
        $url = Str::moustaches(
87
            $this->commitUrl,
88
            $params
89
        );
90
        $data = $this->getJSON($url);
91
92
        return [
93
            'sha'       => $data['sha'],
94
            'author'    => $data['commit']['author']['email'],
95
            'committer' => $data['commit']['committer']['email'],
96
            'message'   => $data['commit']['message'],
97
        ];
98
    }
99
}
100