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

violinist-dev / composer-changelog-fetcher / 11873058236

16 Nov 2024 08:34PM UTC coverage: 89.865% (+0.9%) from 88.971%
11873058236

push

github

web-flow
Support bitbucket ssh if we have a token (#20)

5 of 12 new or added lines in 2 files covered. (41.67%)

133 of 148 relevant lines covered (89.86%)

1.93 hits per line

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

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

3
namespace Violinist\ChangelogFetcher;
4

5
use Violinist\ProcessFactory\ProcessFactoryInterface;
6

7
use function peterpostmann\uri\parse_uri;
8

9
class DependencyRepoRetriever
10
{
11
    protected $processFactory;
12

13
    protected $authToken;
14

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

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

25
    public function retrieveDependencyRepo($data)
26
    {
27
        // First find the repo source.
28
        if (!isset($data->source) || $data->source->type != 'git') {
5✔
29
            throw new \Exception(sprintf('Unknown source or non-git source found for %s. Aborting.', $data->name));
1✔
30
        }
31
        if (empty($data->name)) {
4✔
32
            throw new \Exception('No package name found');
×
33
        }
34
        // We could have this cached in the md5 of the package name.
35
        $clone_path = '/tmp/' . md5($data->name);
4✔
36
        $repo_path = $data->source->url;
4✔
37
        $repo_parsed = parse_uri($repo_path);
4✔
38
        if (!empty($repo_parsed)) {
4✔
39
            switch ($repo_parsed['_protocol']) {
4✔
40
                case 'git@github.com':
4✔
41
                    $repo_path = sprintf(
1✔
42
                        'https://x-access-token:%s@github.com/%s',
1✔
43
                        $this->authToken,
1✔
44
                        $repo_parsed['path']
1✔
45
                    );
1✔
46
                    break;
1✔
47

48
                case 'git@bitbucket.org':
3✔
49
                    $repo_path = sprintf('https://x-token-auth:%s@bitbucket.org/%s', $this->authToken, $repo_parsed['path']);
1✔
50
                    if (strlen($this->authToken) < 50 && strpos($this->authToken, ':') !== false) {
1✔
NEW
51
                        $repo_path = sprintf(
×
NEW
52
                            'https://%s@bitbucket.org/%s',
×
NEW
53
                            $this->authToken,
×
NEW
54
                            $repo_parsed['path']
×
NEW
55
                        );
×
56
                    }
57
                    break;
1✔
58
            }
59
        }
60
        if (!file_exists($clone_path)) {
4✔
61
            $command = ['git', 'clone', $repo_path, $clone_path];
4✔
62
        } else {
63
            $command = ['git', '-C', $clone_path, 'pull'];
×
64
        }
65
        $process = $this->processFactory->getProcess($command);
4✔
66
        $process->run();
4✔
67
        if ($process->getExitCode()) {
4✔
68
            throw new \Exception('Wrong exit code from retrieving git repo: ' . $process->getExitCode());
1✔
69
        }
70
        return $clone_path;
3✔
71
    }
72
}
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

© 2025 Coveralls, Inc