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
|
20 |
|
public function __construct( |
31
|
|
|
string $user, |
32
|
|
|
string $repository, |
33
|
|
|
string $milestone, |
34
|
|
|
array $labels |
35
|
|
|
) { |
36
|
20 |
|
$this->user = $user; |
37
|
20 |
|
$this->repository = $repository; |
38
|
20 |
|
$this->milestone = $milestone; |
39
|
20 |
|
$this->labels = $labels; |
40
|
20 |
|
} |
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
|
|
|
|