|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ChangelogGenerator; |
|
6
|
|
|
|
|
7
|
|
|
use function array_merge; |
|
8
|
|
|
use function sprintf; |
|
9
|
|
|
use function str_replace; |
|
10
|
|
|
use function urlencode; |
|
11
|
|
|
|
|
12
|
|
|
class ChangelogConfig |
|
13
|
|
|
{ |
|
14
|
|
|
private const DEFAULT_ROOT_GITHUB_URL = 'https://api.github.com'; |
|
15
|
|
|
|
|
16
|
|
|
private string $user; |
|
17
|
|
|
|
|
18
|
|
|
private string $repository; |
|
19
|
|
|
|
|
20
|
|
|
private string $milestone; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string[] */ |
|
23
|
|
|
private array $labels; |
|
24
|
|
|
|
|
25
|
|
|
private ?string $nonGroupedLabel = null; |
|
26
|
|
|
|
|
27
|
|
|
private bool $includeOpen; |
|
28
|
|
|
|
|
29
|
|
|
private bool $showContributors = false; |
|
30
|
|
|
|
|
31
|
|
|
private ?GitHubCredentials $gitHubCredentials = null; |
|
32
|
|
|
|
|
33
|
|
|
/** @var mixed[] */ |
|
34
|
|
|
private array $options = ['rootGitHubUrl' => self::DEFAULT_ROOT_GITHUB_URL]; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string[] $labels |
|
38
|
|
|
* @param mixed[] $options |
|
39
|
|
|
*/ |
|
40
|
44 |
|
public function __construct( |
|
41
|
|
|
string $user = '', |
|
42
|
|
|
string $repository = '', |
|
43
|
|
|
string $milestone = '', |
|
44
|
|
|
array $labels = [], |
|
45
|
|
|
bool $includeOpen = false, |
|
46
|
|
|
array $options = [] |
|
47
|
|
|
) { |
|
48
|
44 |
|
$this->user = $user; |
|
49
|
44 |
|
$this->repository = $repository; |
|
50
|
44 |
|
$this->milestone = $milestone; |
|
51
|
44 |
|
$this->labels = $labels; |
|
52
|
44 |
|
$this->includeOpen = $includeOpen; |
|
53
|
44 |
|
$this->options = array_merge($this->options, $options); |
|
54
|
44 |
|
} |
|
55
|
|
|
|
|
56
|
1 |
|
public function getUser(): string |
|
57
|
|
|
{ |
|
58
|
1 |
|
return $this->user; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
17 |
|
public function setUser(string $user): self |
|
62
|
|
|
{ |
|
63
|
17 |
|
$this->user = $user; |
|
64
|
|
|
|
|
65
|
17 |
|
return $this; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
1 |
|
public function getRepository(): string |
|
69
|
|
|
{ |
|
70
|
1 |
|
return $this->repository; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
17 |
|
public function setRepository(string $repository): self |
|
74
|
|
|
{ |
|
75
|
17 |
|
$this->repository = $repository; |
|
76
|
|
|
|
|
77
|
17 |
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
4 |
|
public function getMilestone(): string |
|
81
|
|
|
{ |
|
82
|
4 |
|
return $this->milestone; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
17 |
|
public function setMilestone(string $milestone): self |
|
86
|
|
|
{ |
|
87
|
17 |
|
$this->milestone = $milestone; |
|
88
|
|
|
|
|
89
|
17 |
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return string[] |
|
94
|
|
|
*/ |
|
95
|
6 |
|
public function getLabels(): array |
|
96
|
|
|
{ |
|
97
|
6 |
|
return $this->labels; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param string[] $labels |
|
102
|
|
|
*/ |
|
103
|
10 |
|
public function setLabels(array $labels): self |
|
104
|
|
|
{ |
|
105
|
10 |
|
$this->labels = $labels; |
|
106
|
|
|
|
|
107
|
10 |
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
4 |
|
public function getNonGroupedLabel(): ?string |
|
111
|
|
|
{ |
|
112
|
4 |
|
return $this->nonGroupedLabel; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
3 |
|
public function setNonGroupedLabel(string $nonGroupedLabel): self |
|
116
|
|
|
{ |
|
117
|
3 |
|
$this->nonGroupedLabel = $nonGroupedLabel; |
|
118
|
|
|
|
|
119
|
3 |
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
1 |
|
public function shouldIncludeOpen(): bool |
|
123
|
|
|
{ |
|
124
|
1 |
|
return $this->includeOpen; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
6 |
|
public function setIncludeOpen(bool $includeOpen): self |
|
128
|
|
|
{ |
|
129
|
6 |
|
$this->includeOpen = $includeOpen; |
|
130
|
|
|
|
|
131
|
6 |
|
return $this; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
3 |
|
public function showContributors(): bool |
|
135
|
|
|
{ |
|
136
|
3 |
|
return $this->showContributors; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
4 |
|
public function setShowContributors(bool $showContributors): self |
|
140
|
|
|
{ |
|
141
|
4 |
|
$this->showContributors = $showContributors; |
|
142
|
|
|
|
|
143
|
4 |
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
2 |
|
public function getGitHubCredentials(): ?GitHubCredentials |
|
147
|
|
|
{ |
|
148
|
2 |
|
return $this->gitHubCredentials; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
1 |
|
public function setGitHubCredentials(GitHubCredentials $gitHubCredentials): self |
|
152
|
|
|
{ |
|
153
|
1 |
|
$this->gitHubCredentials = $gitHubCredentials; |
|
154
|
|
|
|
|
155
|
1 |
|
return $this; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return mixed[] |
|
160
|
|
|
*/ |
|
161
|
1 |
|
public function getOptions(): array |
|
162
|
|
|
{ |
|
163
|
1 |
|
return $this->options; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @param mixed[] $options |
|
168
|
|
|
*/ |
|
169
|
3 |
|
public function setOptions(array $options): self |
|
170
|
|
|
{ |
|
171
|
3 |
|
$this->options = $options; |
|
172
|
|
|
|
|
173
|
3 |
|
return $this; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @return mixed |
|
178
|
|
|
*/ |
|
179
|
1 |
|
public function getOption(string $name) |
|
180
|
|
|
{ |
|
181
|
1 |
|
return $this->options[$name] ?? null; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @param mixed $value |
|
186
|
|
|
*/ |
|
187
|
1 |
|
public function setOption(string $name, $value): self |
|
188
|
|
|
{ |
|
189
|
1 |
|
$this->options[$name] = $value; |
|
190
|
|
|
|
|
191
|
1 |
|
return $this; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
7 |
|
public function getMilestoneIssuesUrl(string $label): string |
|
195
|
|
|
{ |
|
196
|
7 |
|
$query = urlencode(sprintf( |
|
197
|
7 |
|
'milestone:"%s" repo:%s/%s%s%s', |
|
198
|
7 |
|
str_replace('"', '\"', $this->milestone), |
|
199
|
7 |
|
$this->user, |
|
200
|
7 |
|
$this->repository, |
|
201
|
7 |
|
$this->includeOpen ? '' : ' state:closed', |
|
202
|
7 |
|
$label !== '' ? ' label:"' . $label . '"' : '' |
|
203
|
|
|
)); |
|
204
|
|
|
|
|
205
|
7 |
|
return sprintf('%s/search/issues?q=%s', $this->getRootGitHubUrl(), $query); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
18 |
|
public function isValid(): bool |
|
209
|
|
|
{ |
|
210
|
18 |
|
return $this->user !== '' && $this->repository !== '' && $this->milestone !== ''; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
7 |
|
private function getRootGitHubUrl(): string |
|
214
|
|
|
{ |
|
215
|
7 |
|
return $this->options['rootGitHubUrl'] ?? self::DEFAULT_ROOT_GITHUB_URL; |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|