• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

violinist-dev / composer-changelog-fetcher / 11879349127

17 Nov 2024 01:39PM UTC coverage: 87.586% (-4.8%) from 92.366%
11879349127

Pull #12

github

eiriksm
Code style
Pull Request #12: Make it possible and easier to retrieve dependency repos

6 of 14 new or added lines in 1 file covered. (42.86%)

10 existing lines in 1 file now uncovered.

127 of 145 relevant lines covered (87.59%)

3.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.75
/src/DependencyRepoRetriever.php
1
<?php
2

3
namespace Violinist\ChangelogFetcher;
4

5
use Violinist\ProcessFactory\ProcessFactoryInterface;
6

7
use Violinist\RepoAndTokenToCloneUrl\ToCloneUrl;
8
use function peterpostmann\uri\parse_uri;
9

10
class DependencyRepoRetriever
11
{
12
    protected $processFactory;
13

14
    protected $authToken;
15

16
    public function __construct(ProcessFactoryInterface $processFactory)
17
    {
18
        $this->processFactory = $processFactory;
13✔
19
    }
20

21
    public function setAuthToken($token)
22
    {
23
        $this->authToken = $token;
11✔
24
    }
25

26
    public function retrieveDependencyRepo($data)
27
    {
28
        // First find the repo source.
29
        if (!isset($data->source) || $data->source->type != 'git') {
13✔
30
            throw new \Exception(sprintf('Unknown source or non-git source found for %s. Aborting.', $data->name));
1✔
31
        }
32
        if (empty($data->name)) {
12✔
UNCOV
33
            throw new \Exception('No package name found');
×
34
        }
35
        // We could have this cached in the md5 of the package name.
36
        $clone_path = '/tmp/' . md5($data->name);
12✔
37
        $repo_path = $data->source->url;
12✔
38
        $repo_path_overridden = false;
12✔
39
        if (!empty($this->authToken)) {
12✔
40
            $repo_path = ToCloneUrl::fromRepoAndToken($repo_path, $this->authToken);
9✔
41
            if ($repo_path !== $data->source->url) {
9✔
42
                $repo_path_overridden = true;
9✔
43
            }
44
        }
45
        $repo_parsed = parse_uri($repo_path);
12✔
46
        if (!empty($repo_parsed)) {
12✔
47
            if (!$repo_path_overridden && $this->authToken) {
12✔
NEW
UNCOV
48
                switch ($repo_parsed["host"]) {
×
49
                    default:
NEW
UNCOV
50
                        $port = 443;
×
NEW
UNCOV
51
                        if ($repo_parsed['scheme'] === 'http') {
×
NEW
UNCOV
52
                            $port = 80;
×
53
                        }
NEW
UNCOV
54
                        if (!empty($repo_parsed["port"])) {
×
NEW
UNCOV
55
                            $port = $repo_parsed["port"];
×
56
                        }
NEW
UNCOV
57
                        $repo_path = sprintf('%s://oauth2:%s@%s:%d/%s', $repo_parsed["scheme"], $this->authToken, $repo_parsed["host"], $port, $repo_parsed["path"]);
×
NEW
UNCOV
58
                        break;
×
59
                }
60
            }
61
        }
62
        if (!file_exists($clone_path)) {
12✔
63
            $command = ['git', 'clone', $repo_path, $clone_path];
12✔
64
        } else {
UNCOV
65
            $command = ['git', '-C', $clone_path, 'pull'];
×
66
        }
67
        $process = $this->processFactory->getProcess($command);
12✔
68
        $process->run();
12✔
69
        if ($process->getExitCode()) {
12✔
70
            throw new \Exception('Wrong exit code from retrieving git repo: ' . $process->getExitCode());
1✔
71
        }
72
        return $clone_path;
11✔
73
    }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc