1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Thruster\Tool\ProjectGenerator\Console\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Process\Process; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class CreateRepoCommand |
13
|
|
|
* |
14
|
|
|
* @package Thruster\Tool\ProjectGenerator\Console\Command |
15
|
|
|
* @author Aurimas Niekis <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class CreateRepoCommand extends Command |
18
|
|
|
{ |
19
|
|
|
protected function configure() |
20
|
|
|
{ |
21
|
|
|
$this->setName('create:repo') |
22
|
|
|
->addOption( |
23
|
|
|
'organisation', |
24
|
|
|
'o', |
25
|
|
|
InputOption::VALUE_OPTIONAL, |
26
|
|
|
'GitHub Organisation Name', |
27
|
|
|
'ThrusterIO' |
28
|
|
|
) |
29
|
|
|
->addOption( |
30
|
|
|
'private', |
31
|
|
|
'p', |
32
|
|
|
InputOption::VALUE_NONE, |
33
|
|
|
'Create a private repository', |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
38
|
|
|
{ |
39
|
|
|
$workDir = getcwd(); |
40
|
|
|
|
41
|
|
|
if (false === file_exists($workDir . '/composer.json')) { |
42
|
|
|
$output->writeln('<error>Not a project directory (composer.json is missing)</error>'); |
43
|
|
|
|
44
|
|
|
return 1; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$composerJson = json_decode(file_get_contents($workDir . '/composer.json'), true); |
48
|
|
|
|
49
|
|
|
[$vendor, $name] = explode('/', $composerJson['name']); |
50
|
|
|
$organisation = $input->getOption('organisation'); |
51
|
|
|
|
52
|
|
|
$output->write('<info>Creating GitHub Repository: </info>'); |
53
|
|
|
$output->writeln('<comment>' . $organisation . '/' . $name . '</comment>'); |
54
|
|
|
|
55
|
|
|
$options = [ |
56
|
|
|
'hub', |
57
|
|
|
'create', |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
if ($input->getOption('private')) { |
61
|
|
|
$options[] = '-p'; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$options[] = '-d ' . json_encode($composerJson['description']); |
65
|
|
|
$options[] = $organisation . '/' . $name; |
66
|
|
|
|
67
|
|
|
$process = new Process($options); |
68
|
|
|
$process->start(); |
69
|
|
|
|
70
|
|
|
$process->wait(function ($type, $buffer) { |
71
|
|
|
echo $buffer; |
72
|
|
|
}); |
73
|
|
|
|
74
|
|
|
return $process->getExitCode(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
} |
78
|
|
|
|