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