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