1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CL\ComposerInit\Prompt; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
6
|
|
|
use CL\ComposerInit\GitConfig; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use Symfony\Component\Console\Helper\DialogHelper; |
9
|
|
|
use RuntimeException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Ivan Kerin <[email protected]> |
13
|
|
|
* @copyright (c) 2014 Clippings Ltd. |
14
|
|
|
* @license http://spdx.org/licenses/BSD-3-Clause |
15
|
|
|
*/ |
16
|
|
|
class BugsPrompt implements PromptInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Github Client |
20
|
|
|
* |
21
|
|
|
* @var Client |
22
|
|
|
*/ |
23
|
|
|
private $github; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var GitConfig |
27
|
|
|
*/ |
28
|
|
|
private $gitConfig; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param GitConfig $gitConfig |
32
|
|
|
* @param Client $github |
33
|
|
|
*/ |
34
|
1 |
|
public function __construct(GitConfig $gitConfig, Client $github) |
35
|
|
|
{ |
36
|
1 |
|
$this->github = $github; |
37
|
1 |
|
$this->gitConfig = $gitConfig; |
38
|
1 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return GitConfig |
42
|
|
|
*/ |
43
|
1 |
|
public function getGitConfig() |
44
|
|
|
{ |
45
|
1 |
|
return $this->gitConfig; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return Client |
50
|
|
|
*/ |
51
|
1 |
|
public function getGithub() |
52
|
|
|
{ |
53
|
1 |
|
return $this->github; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return string|null |
58
|
|
|
*/ |
59
|
2 |
|
public function getDefault() |
60
|
|
|
{ |
61
|
2 |
|
$origin = $this->gitConfig->getOrigin(); |
62
|
|
|
|
63
|
2 |
|
if (null !== $origin) { |
64
|
1 |
|
$response = $this->github->get("/repos/{$origin}"); |
65
|
1 |
|
$repo = json_decode($response->getBody(), true); |
66
|
|
|
|
67
|
1 |
|
return "{$repo['html_url']}/issues/new"; |
68
|
|
|
} |
69
|
1 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param OutputInterface $output |
73
|
|
|
* @param DialogHelper $dialog |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
1 |
|
public function getValues(OutputInterface $output, DialogHelper $dialog) |
77
|
|
|
{ |
78
|
1 |
|
$default = $this->getDefault(); |
79
|
|
|
|
80
|
1 |
|
$value = $dialog->askAndValidate( |
81
|
1 |
|
$output, |
82
|
1 |
|
"<info>Issues url</info> ({$default}): ", |
83
|
1 |
|
function ($email) { |
84
|
1 |
|
if (false === filter_var($email, FILTER_VALIDATE_URL)) { |
85
|
1 |
|
throw new RuntimeException('Not a valid url'); |
86
|
|
|
} |
87
|
|
|
|
88
|
1 |
|
return $email; |
89
|
1 |
|
}, |
90
|
1 |
|
false, |
91
|
|
|
$default |
92
|
1 |
|
); |
93
|
|
|
|
94
|
1 |
|
return ['bugs' => $value]; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|