1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ChangelogGenerator; |
6
|
|
|
|
7
|
|
|
use function array_values; |
8
|
|
|
use function sprintf; |
9
|
|
|
|
10
|
|
|
class Issue |
11
|
|
|
{ |
12
|
|
|
private const SINGLE_CONTRIBUTOR_ISSUE_LINE_FORMAT = ' - [%d: %s](%s) thanks to @%s'; |
13
|
|
|
private const MULTI_CONTRIBUTOR_ISSUE_LINE_FORMAT = ' - [%d: %s](%s) thanks to @%s and @%s'; |
14
|
|
|
|
15
|
|
|
private int $number; |
16
|
|
|
|
17
|
|
|
private string $title; |
18
|
|
|
|
19
|
|
|
private ?string $body = null; |
20
|
|
|
|
21
|
|
|
private string $url; |
22
|
|
|
|
23
|
|
|
private string $user; |
24
|
|
|
|
25
|
|
|
/** @var string[] */ |
26
|
|
|
private array $labels = []; |
27
|
|
|
|
28
|
|
|
private bool $isPullRequest; |
29
|
|
|
|
30
|
|
|
private ?Issue $linkedPullRequest = null; |
31
|
|
|
|
32
|
|
|
private ?Issue $linkedIssue = null; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string[] $labels |
36
|
|
|
*/ |
37
|
18 |
|
public function __construct( |
38
|
|
|
int $number, |
39
|
|
|
string $title, |
40
|
|
|
?string $body, |
41
|
|
|
string $url, |
42
|
|
|
string $user, |
43
|
|
|
array $labels, |
44
|
|
|
bool $isPullRequest |
45
|
|
|
) { |
46
|
18 |
|
$this->number = $number; |
47
|
18 |
|
$this->title = $title; |
48
|
18 |
|
$this->body = $body; |
49
|
18 |
|
$this->url = $url; |
50
|
18 |
|
$this->user = $user; |
51
|
18 |
|
$this->labels = $labels; |
52
|
18 |
|
$this->isPullRequest = $isPullRequest; |
53
|
18 |
|
} |
54
|
|
|
|
55
|
4 |
|
public function getNumber(): int |
56
|
|
|
{ |
57
|
4 |
|
return $this->number; |
58
|
|
|
} |
59
|
|
|
|
60
|
2 |
|
public function getTitle(): string |
61
|
|
|
{ |
62
|
2 |
|
return $this->title; |
63
|
|
|
} |
64
|
|
|
|
65
|
4 |
|
public function getBody(): ?string |
66
|
|
|
{ |
67
|
4 |
|
return $this->body; |
68
|
|
|
} |
69
|
|
|
|
70
|
2 |
|
public function getUrl(): string |
71
|
|
|
{ |
72
|
2 |
|
return $this->url; |
73
|
|
|
} |
74
|
|
|
|
75
|
7 |
|
public function getUser(): string |
76
|
|
|
{ |
77
|
7 |
|
return $this->user; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string[] |
82
|
|
|
*/ |
83
|
4 |
|
public function getLabels(): array |
84
|
|
|
{ |
85
|
4 |
|
return $this->labels; |
86
|
|
|
} |
87
|
|
|
|
88
|
6 |
|
public function isPullRequest(): bool |
89
|
|
|
{ |
90
|
6 |
|
return $this->isPullRequest; |
91
|
|
|
} |
92
|
|
|
|
93
|
3 |
|
public function getLinkedPullRequest(): ?Issue |
94
|
|
|
{ |
95
|
3 |
|
return $this->linkedPullRequest; |
96
|
|
|
} |
97
|
|
|
|
98
|
6 |
|
public function setLinkedPullRequest(Issue $linkedPullRequest): void |
99
|
|
|
{ |
100
|
6 |
|
$this->linkedPullRequest = $linkedPullRequest; |
101
|
6 |
|
} |
102
|
|
|
|
103
|
2 |
|
public function getLinkedIssue(): ?Issue |
104
|
|
|
{ |
105
|
2 |
|
return $this->linkedIssue; |
106
|
|
|
} |
107
|
|
|
|
108
|
8 |
|
public function setLinkedIssue(Issue $linkedIssue): void |
109
|
|
|
{ |
110
|
8 |
|
$this->linkedIssue = $linkedIssue; |
111
|
8 |
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return string[] |
115
|
|
|
*/ |
116
|
3 |
|
public function getContributors(): array |
117
|
|
|
{ |
118
|
3 |
|
$contributors = []; |
119
|
|
|
|
120
|
3 |
|
$contributors[$this->user] = $this->user; |
121
|
|
|
|
122
|
3 |
|
if ($this->linkedPullRequest !== null) { |
123
|
3 |
|
$contributors[$this->linkedPullRequest->getUser()] = $this->linkedPullRequest->getUser(); |
124
|
|
|
} |
125
|
|
|
|
126
|
3 |
|
if ($this->linkedIssue !== null) { |
127
|
3 |
|
$contributors[$this->linkedIssue->getUser()] = $this->linkedIssue->getUser(); |
128
|
|
|
} |
129
|
|
|
|
130
|
3 |
|
return array_values($contributors); |
131
|
|
|
} |
132
|
|
|
|
133
|
6 |
|
public function render(): string |
134
|
|
|
{ |
135
|
6 |
|
if ($this->linkedIssue instanceof self && $this->linkedIssue->getUser() !== $this->user) { |
136
|
4 |
|
return sprintf( |
137
|
4 |
|
self::MULTI_CONTRIBUTOR_ISSUE_LINE_FORMAT, |
138
|
4 |
|
$this->number, |
139
|
4 |
|
$this->title, |
140
|
4 |
|
$this->url, |
141
|
4 |
|
$this->user, |
142
|
4 |
|
$this->linkedIssue->getUser() |
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
|
146
|
2 |
|
return sprintf( |
147
|
2 |
|
self::SINGLE_CONTRIBUTOR_ISSUE_LINE_FORMAT, |
148
|
2 |
|
$this->number, |
149
|
2 |
|
$this->title, |
150
|
2 |
|
$this->url, |
151
|
2 |
|
$this->user |
152
|
|
|
); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|