File tree Expand file tree Collapse file tree 4 files changed +94
-10
lines changed Expand file tree Collapse file tree 4 files changed +94
-10
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+
5
+ namespace App \CodeRepository ;
6
+
7
+
8
+ class CodeRepositoryFactory
9
+ {
10
+
11
+ }
Original file line number Diff line number Diff line change 3
3
4
4
namespace App \CodeRepository ;
5
5
6
+ use App \Configuration \Value \Source ;
6
7
use App \Value \Folder ;
7
8
use Symfony \Component \Process \Exception \ProcessFailedException ;
8
9
use Symfony \Component \Process \Process ;
9
10
10
11
class GithubCodeRepository implements CodeRepository
11
12
{
12
- public function downloadCode (string $ repoName ): Folder
13
+ public function downloadCode (Source $ source ): Folder
13
14
{
14
- $ repoPath = new Folder (self ::CODE_DOWNLOAD_PATH . $ repoName . '/ ' );
15
+ $ localPath = new Folder (self ::CODE_DOWNLOAD_PATH . $ source -> getLocalFolder () . '/ ' );
15
16
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 ));
18
19
19
- return $ repoPath ;
20
+ return $ localPath ;
20
21
}
21
22
22
23
private function runProcess (Process $ process ): void
@@ -28,21 +29,21 @@ private function runProcess(Process $process): void
28
29
}
29
30
}
30
31
31
- private function getCloneOrPullProcess (Folder $ repoPath , string $ repoName ): Process
32
+ private function getCloneOrPullProcess (Folder $ localPath , string $ sourcePath ): Process
32
33
{
33
- if (!is_dir ((string )$ repoPath )) {
34
+ if (!is_dir ((string )$ localPath )) {
34
35
return new Process ([
35
36
'git ' ,
36
37
'clone ' ,
37
- ' git@github.com: ' . $ repoName ,
38
- $ repoPath
38
+ $ sourcePath ,
39
+ ( string ) $ localPath
39
40
]);
40
41
}
41
42
42
43
return new Process ([
43
44
'git ' ,
44
45
'-C ' ,
45
- $ repoPath ,
46
+ ( string ) $ localPath ,
46
47
'pull '
47
48
]);
48
49
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments