Skip to content

Commit 8eb9cef

Browse files
committed
Init
1 parent bfe0e11 commit 8eb9cef

File tree

4 files changed

+94
-10
lines changed

4 files changed

+94
-10
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
5+
namespace App\CodeRepository;
6+
7+
8+
class CodeRepositoryFactory
9+
{
10+
11+
}

src/CodeRepository/GithubCodeRepository.php renamed to src/CodeRepository/GitCodeRepository.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33

44
namespace App\CodeRepository;
55

6+
use App\Configuration\Value\Source;
67
use App\Value\Folder;
78
use Symfony\Component\Process\Exception\ProcessFailedException;
89
use Symfony\Component\Process\Process;
910

1011
class GithubCodeRepository implements CodeRepository
1112
{
12-
public function downloadCode(string $repoName): Folder
13+
public function downloadCode(Source $source): Folder
1314
{
14-
$repoPath = new Folder(self::CODE_DOWNLOAD_PATH . $repoName . '/');
15+
$localPath = new Folder(self::CODE_DOWNLOAD_PATH . $source->getLocalFolder() . '/');
1516

16-
$this->runProcess($this->getCloneOrPullProcess($repoPath, $repoName));
17-
$this->runProcess($this->getComposerInstallProcess($repoPath));
17+
$this->runProcess($this->getCloneOrPullProcess($localPath, $source->getPath()));
18+
$this->runProcess($this->getComposerInstallProcess($localPath));
1819

19-
return $repoPath;
20+
return $localPath;
2021
}
2122

2223
private function runProcess(Process $process): void
@@ -28,21 +29,21 @@ private function runProcess(Process $process): void
2829
}
2930
}
3031

31-
private function getCloneOrPullProcess(Folder $repoPath, string $repoName): Process
32+
private function getCloneOrPullProcess(Folder $localPath, string $sourcePath): Process
3233
{
33-
if (!is_dir((string)$repoPath)) {
34+
if (!is_dir((string)$localPath)) {
3435
return new Process([
3536
'git',
3637
'clone',
37-
'git@github.com:' . $repoName,
38-
$repoPath
38+
$sourcePath,
39+
(string)$localPath
3940
]);
4041
}
4142

4243
return new Process([
4344
'git',
4445
'-C',
45-
$repoPath,
46+
(string)$localPath,
4647
'pull'
4748
]);
4849
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\CodeRepository;
5+
6+
use App\Configuration\Value\Source;
7+
use App\Value\Folder;
8+
use Symfony\Component\Process\Exception\ProcessFailedException;
9+
use Symfony\Component\Process\Process;
10+
11+
class GitCodeRepository implements CodeRepository
12+
{
13+
public function downloadCode(Source $source): Folder
14+
{
15+
$localPath = new Folder(self::CODE_DOWNLOAD_PATH . $source->getLocalFolder() . '/');
16+
17+
$this->runProcess($this->getCloneOrPullProcess($localPath, $source->getPath()));
18+
$this->runProcess($this->getComposerInstallProcess($localPath));
19+
20+
return $localPath;
21+
}
22+
23+
private function runProcess(Process $process): void
24+
{
25+
$process->run();
26+
27+
if (!$process->isSuccessful()) {
28+
throw new ProcessFailedException($process);
29+
}
30+
}
31+
32+
private function getCloneOrPullProcess(Folder $localPath, string $sourcePath): Process
33+
{
34+
if (!is_dir((string)$localPath)) {
35+
return new Process([
36+
'git',
37+
'clone',
38+
$sourcePath,
39+
(string)$localPath
40+
]);
41+
}
42+
43+
return new Process([
44+
'git',
45+
'-C',
46+
(string)$localPath,
47+
'pull'
48+
]);
49+
}
50+
51+
private function getComposerInstallProcess(Folder $repoPath): Process
52+
{
53+
return new Process([
54+
'composer',
55+
'install',
56+
'-d',
57+
$repoPath
58+
]);
59+
}
60+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Tests\CodeRepository;
5+
6+
use App\CodeRepository\GitCodeRepository;
7+
use PHPUnit\Framework\TestCase;
8+
9+
/** @covers \App\CodeRepository\GitCodeRepository */
10+
class GitCodeRepositoryTest extends TestCase
11+
{
12+
}

0 commit comments

Comments
 (0)