|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ChangelogGenerator; |
|
6
|
|
|
|
|
7
|
|
|
use function sprintf; |
|
8
|
|
|
use function str_replace; |
|
9
|
|
|
use function urlencode; |
|
10
|
|
|
|
|
11
|
|
|
class ChangelogConfig |
|
12
|
|
|
{ |
|
13
|
|
|
private const ROOT_URL = 'https://api.github.com'; |
|
14
|
|
|
|
|
15
|
|
|
/** @var string */ |
|
16
|
|
|
private $user; |
|
17
|
|
|
|
|
18
|
|
|
/** @var string */ |
|
19
|
|
|
private $repository; |
|
20
|
|
|
|
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
private $milestone; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string[] */ |
|
25
|
|
|
private $labels; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param string[] $labels |
|
29
|
|
|
*/ |
|
30
|
24 |
|
public function __construct( |
|
31
|
|
|
string $user, |
|
32
|
|
|
string $repository, |
|
33
|
|
|
string $milestone, |
|
34
|
|
|
array $labels = [] |
|
35
|
|
|
) { |
|
36
|
24 |
|
$this->user = $user; |
|
37
|
24 |
|
$this->repository = $repository; |
|
38
|
24 |
|
$this->milestone = $milestone; |
|
39
|
24 |
|
$this->labels = $labels; |
|
40
|
24 |
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
public function getUser() : string |
|
43
|
|
|
{ |
|
44
|
1 |
|
return $this->user; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
4 |
|
public function setUser(string $user) : void |
|
48
|
|
|
{ |
|
49
|
4 |
|
$this->user = $user; |
|
50
|
4 |
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
public function getRepository() : string |
|
53
|
|
|
{ |
|
54
|
1 |
|
return $this->repository; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
4 |
|
public function setRepository(string $repository) : void |
|
58
|
|
|
{ |
|
59
|
4 |
|
$this->repository = $repository; |
|
60
|
4 |
|
} |
|
61
|
|
|
|
|
62
|
2 |
|
public function getMilestone() : string |
|
63
|
|
|
{ |
|
64
|
2 |
|
return $this->milestone; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
4 |
|
public function setMilestone(string $milestone) : void |
|
68
|
|
|
{ |
|
69
|
4 |
|
$this->milestone = $milestone; |
|
70
|
4 |
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return string[] |
|
74
|
|
|
*/ |
|
75
|
2 |
|
public function getLabels() : array |
|
76
|
|
|
{ |
|
77
|
2 |
|
return $this->labels; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param string[] $labels |
|
82
|
|
|
*/ |
|
83
|
3 |
|
public function setLabels(array $labels) : void |
|
84
|
|
|
{ |
|
85
|
3 |
|
$this->labels = $labels; |
|
86
|
3 |
|
} |
|
87
|
|
|
|
|
88
|
3 |
|
public function getMilestoneIssuesUrl(string $label) : string |
|
89
|
|
|
{ |
|
90
|
3 |
|
$query = urlencode(sprintf( |
|
91
|
3 |
|
'milestone:"%s" repo:%s/%s state:closed%s', |
|
92
|
3 |
|
str_replace('"', '\"', $this->milestone), |
|
93
|
3 |
|
$this->user, |
|
94
|
3 |
|
$this->repository, |
|
95
|
3 |
|
$label !== '' ? ' label:' . $label : '' |
|
96
|
|
|
)); |
|
97
|
|
|
|
|
98
|
3 |
|
return sprintf('%s/search/issues?q=%s', self::ROOT_URL, $query); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
12 |
|
public function isValid() : bool |
|
102
|
|
|
{ |
|
103
|
12 |
|
return $this->user !== '' && $this->repository !== '' && $this->milestone !== ''; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|