1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acacha\ForgePublish\Commands; |
4
|
|
|
|
5
|
|
|
use Acacha\ForgePublish\Commands\Traits\ChecksEnv; |
6
|
|
|
use Acacha\ForgePublish\Commands\Traits\ChecksServer; |
7
|
|
|
use Acacha\ForgePublish\Commands\Traits\ChecksSite; |
8
|
|
|
use Acacha\ForgePublish\Commands\Traits\DiesIfEnvVariableIsnotInstalled; |
9
|
|
|
use GuzzleHttp\Client; |
10
|
|
|
use Illuminate\Console\Command; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class PublishInstallRepo. |
14
|
|
|
* |
15
|
|
|
* @package Acacha\ForgePublish\Commands |
16
|
|
|
*/ |
17
|
|
|
class PublishRepository extends Command |
18
|
|
|
{ |
19
|
|
|
use ChecksEnv, DiesIfEnvVariableIsnotInstalled, ChecksServer, ChecksSite; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Github Repository. |
23
|
|
|
* |
24
|
|
|
* @var String |
25
|
|
|
*/ |
26
|
|
|
protected $repository; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Server name |
30
|
|
|
* |
31
|
|
|
* @var String |
32
|
|
|
*/ |
33
|
|
|
protected $server; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Servers. |
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $servers; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Forge site id. |
44
|
|
|
* |
45
|
|
|
* @var String |
46
|
|
|
*/ |
47
|
|
|
protected $site; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The name and signature of the console command. |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $signature = 'publish:repository {repository?} {--server=} {--site=}'; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The console command description. |
58
|
|
|
* |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
protected $description = 'Install repository on Laravel Forge site'; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Guzzle http client. |
65
|
|
|
* |
66
|
|
|
* @var Client |
67
|
|
|
*/ |
68
|
|
|
protected $http; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Create a new command instance. |
72
|
|
|
* |
73
|
|
|
*/ |
74
|
|
|
public function __construct(Client $http) |
75
|
|
|
{ |
76
|
|
|
parent::__construct(); |
77
|
|
|
$this->http = $http; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Execute the console command. |
82
|
|
|
* |
83
|
|
|
*/ |
84
|
|
|
public function handle() |
85
|
|
|
{ |
86
|
|
|
$this->abortCommandExecution(); |
87
|
|
|
$this->info("Installing Github repository on Laravel Forge Site..."); |
88
|
|
|
|
89
|
|
|
$uri = str_replace('{forgeserver}', $this->server, config('forge-publish.post_git_repository_uri')); |
90
|
|
|
$uri = str_replace('{forgesite}', $this->site, $uri); |
91
|
|
|
$url = config('forge-publish.url') . $uri; |
92
|
|
|
|
93
|
|
|
$this->http->post($url, |
94
|
|
|
[ |
95
|
|
|
'form_params' => [ |
96
|
|
|
'repository' => $this->repository |
97
|
|
|
], |
98
|
|
|
'headers' => [ |
99
|
|
|
'X-Requested-With' => 'XMLHttpRequest', |
100
|
|
|
'Authorization' => 'Bearer ' . fp_env('ACACHA_FORGE_ACCESS_TOKEN') |
101
|
|
|
] |
102
|
|
|
] |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$this->info("Repository " . $this->repository . " installed on Laravel Forge Site..."); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Abort command execution? |
110
|
|
|
*/ |
111
|
|
|
protected function abortCommandExecution() |
112
|
|
|
{ |
113
|
|
|
$this->repository = $this->checkEnv('repository', 'ACACHA_FORGE_GITHUB_REPO', 'argument'); |
114
|
|
|
$this->server = $this->checkEnv('server', 'ACACHA_FORGE_SERVER'); |
115
|
|
|
$this->site = $this->checkEnv('site', 'ACACHA_FORGE_SITE'); |
116
|
|
|
$this->dieIfEnvVarIsNotInstalled('ACACHA_FORGE_ACCESS_TOKEN'); |
117
|
|
|
|
118
|
|
|
$this->checkServerAndAbort($this->server); |
119
|
|
|
$this->checkSiteAndAbort($this->site); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|