1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CompoLab\Application\Cli; |
4
|
|
|
|
5
|
|
|
use CompoLab\Application\GitlabRepositoryManager; |
6
|
|
|
use Gitlab\Client as Gitlab; |
7
|
|
|
use Gitlab\Model\Project; |
8
|
|
|
use Symfony\Component\Console\Command\Command; |
9
|
|
|
use Symfony\Component\Console\Exception\InvalidArgumentException; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
|
14
|
|
|
final class UpdateCommand extends Command |
15
|
|
|
{ |
16
|
|
|
/** @var Gitlab */ |
17
|
|
|
private $gitlab; |
18
|
|
|
|
19
|
|
|
/** @var GitlabRepositoryManager */ |
20
|
|
|
private $repositoryManager; |
21
|
|
|
|
22
|
|
|
public function __construct(Gitlab $gitlab, GitlabRepositoryManager $repositoryManager) |
23
|
|
|
{ |
24
|
|
|
$this->gitlab = $gitlab; |
25
|
|
|
$this->repositoryManager = $repositoryManager; |
26
|
|
|
|
27
|
|
|
parent::__construct(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function configure() |
31
|
|
|
{ |
32
|
|
|
$this |
33
|
|
|
->setName('update') |
34
|
|
|
->setDescription('Update a GitLab project in CompoLab') |
35
|
|
|
->setHelp('This command will update a specific project (tags and branches) in the packages.json file, and download associated package archives into the web-accessible cache directory.') |
36
|
|
|
->addArgument('project', InputArgument::REQUIRED, 'Project ID (can be found from GitLab in project settings') |
37
|
|
|
; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
41
|
|
|
{ |
42
|
|
|
$projectId = $input->getArgument('project'); |
43
|
|
|
|
44
|
|
|
$output->write(sprintf('Find project %d from GitLab...', $projectId)); |
|
|
|
|
45
|
|
|
|
46
|
|
|
$project = (new Project($projectId, $this->gitlab))->show(); |
47
|
|
|
if (!$project) { |
|
|
|
|
48
|
|
|
throw new InvalidArgumentException(sprintf('Impossible to retrieve Gitlab project %d', $projectId)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$output->writeln(' OK'); |
52
|
|
|
|
53
|
|
|
$output->write('Update project in CompoLab...'); |
54
|
|
|
|
55
|
|
|
$this->repositoryManager->registerProject($project); |
56
|
|
|
$this->repositoryManager->save(); |
57
|
|
|
|
58
|
|
|
$output->writeln(' OK'); |
59
|
|
|
|
60
|
|
|
$output->writeln('Finished'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|