|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TheAentMachine\AentGitLabCI\Command; |
|
4
|
|
|
|
|
5
|
|
|
use TheAentMachine\AentGitLabCI\Aenthill\Metadata; |
|
6
|
|
|
use TheAentMachine\AentGitLabCI\GitLabCI\GitLabCIFile; |
|
7
|
|
|
use TheAentMachine\Aenthill\CommonEvents; |
|
8
|
|
|
use TheAentMachine\Aenthill\Manifest; |
|
9
|
|
|
use TheAentMachine\Command\AbstractEventCommand; |
|
10
|
|
|
use TheAentMachine\AentGitLabCI\Exception\GitLabCIFileException; |
|
11
|
|
|
use TheAentMachine\Question\CommonValidators; |
|
12
|
|
|
|
|
13
|
|
|
final class AddEventCommand extends AbstractEventCommand |
|
14
|
|
|
{ |
|
15
|
|
|
protected function getEventName(): string |
|
16
|
|
|
{ |
|
17
|
|
|
return CommonEvents::ADD_EVENT; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param null|string $payload |
|
22
|
|
|
* @return null|string |
|
23
|
|
|
* @throws GitLabCIFileException |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function executeEvent(?string $payload): ?string |
|
26
|
|
|
{ |
|
27
|
|
|
$aentHelper = $this->getAentHelper(); |
|
28
|
|
|
$aentHelper->title('Installing GitLab CI file'); |
|
29
|
|
|
|
|
30
|
|
|
$file = new GitLabCIFile(); |
|
31
|
|
|
if ($file->exist()) { |
|
32
|
|
|
$this->output->writeln('🦊 <info>' . GitLabCIFile::DEFAULT_FILENAME . '</info> found!'); |
|
33
|
|
|
} else { |
|
34
|
|
|
$file->findOrCreate(); |
|
35
|
|
|
$this->output->writeln('🦊 <info>' . GitLabCIFile::DEFAULT_FILENAME . '</info> was successfully created!'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$aentHelper->spacer(); |
|
39
|
|
|
|
|
40
|
|
|
if (null === Manifest::getMetadata(Metadata::REGISTRY_DOMAIN_NAME_KEY)) { |
|
41
|
|
|
$registryDomainName = $this->askForRegistryDomainName(); |
|
42
|
|
|
Manifest::addMetadata(Metadata::REGISTRY_DOMAIN_NAME_KEY, $registryDomainName); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if (null === Manifest::getMetadata(Metadata::PROJECT_GROUP_KEY)) { |
|
46
|
|
|
$projectGroup = $this->askForProjectGroup(); |
|
47
|
|
|
Manifest::addMetadata(Metadata::PROJECT_GROUP_KEY, $projectGroup); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if (null === Manifest::getMetadata(Metadata::PROJECT_NAME_KEY)) { |
|
51
|
|
|
$projectName = $this->askForProjectName(); |
|
52
|
|
|
Manifest::addMetadata(Metadata::PROJECT_NAME_KEY, $projectName); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return null; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function askForRegistryDomainName(): string |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->getAentHelper()->question('Registry domain name') |
|
61
|
|
|
->setHelpText('The domain name of the Docker Container Registry integrated with your Git repository on your GitLab. This is the space where your Docker images are stored.') |
|
62
|
|
|
->compulsory() |
|
63
|
|
|
->setValidator(CommonValidators::getDomainNameWithPortValidator()) |
|
64
|
|
|
->ask(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
private function askForProjectGroup(): string |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->getAentHelper()->question('Project group') |
|
70
|
|
|
->setHelpText('The group defined in the project path on GitLab. For example: for the project with URL "https://git.yourcompany.com/foo/bar", "foo" is the group name.') |
|
71
|
|
|
->compulsory() |
|
72
|
|
|
->setValidator(CommonValidators::getAlphaValidator(['-'])) |
|
73
|
|
|
->ask(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
private function askForProjectName(): string |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->getAentHelper()->question('Project name') |
|
79
|
|
|
->setHelpText('The project name defined in the project path on GitLab. For example: for the project with URL "https://git.yourcompany.com/foo/bar", "bar" is the project name.') |
|
80
|
|
|
->compulsory() |
|
81
|
|
|
->setValidator(CommonValidators::getAlphaValidator(['-'])) |
|
82
|
|
|
->ask(); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|