1
|
|
|
<?php |
2
|
|
|
namespace FlexyProject\GitHub\Receiver; |
3
|
|
|
|
4
|
|
|
use DateTime; |
5
|
|
|
use FlexyProject\GitHub\AbstractApi; |
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* This class provides access to Issues API. |
10
|
|
|
* |
11
|
|
|
* @link https://developer.github.com/v3/issues/ |
12
|
|
|
* @package FlexyProject\GitHub\Receiver |
13
|
|
|
*/ |
14
|
|
|
class Issues extends AbstractReceiver |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** Available sub-Receiver */ |
18
|
|
|
const ASSIGNEES = 'Assignees'; |
19
|
|
|
const COMMENTS = 'Comments'; |
20
|
|
|
const EVENTS = 'Events'; |
21
|
|
|
const LABELS = 'Labels'; |
22
|
|
|
const MILESTONES = 'Milestones'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* List issues |
26
|
|
|
* |
27
|
|
|
* @link https://developer.github.com/v3/issues/#list-issues |
28
|
|
|
* |
29
|
|
|
* @param string $filter |
30
|
|
|
* @param string $state |
31
|
|
|
* @param string $labels |
32
|
|
|
* @param string $sort |
33
|
|
|
* @param string $direction |
34
|
|
|
* @param string $since |
35
|
|
|
* |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function listIssues(string $filter = AbstractApi::FILTER_ASSIGNED, string $state = AbstractApi::STATE_OPEN, |
|
|
|
|
39
|
|
|
string $labels = '', string $sort = AbstractApi::SORT_CREATED, |
40
|
|
|
string $direction = AbstractApi::DIRECTION_DESC, string $since = '1970-01-01'): array |
41
|
|
|
{ |
42
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/issues?:args', http_build_query([ |
43
|
|
|
'filter' => $filter, |
44
|
|
|
'state' => $state, |
45
|
|
|
'labels' => $labels, |
46
|
|
|
'sort' => $sort, |
47
|
|
|
'direction' => $direction, |
48
|
|
|
'since' => (new DateTime($since))->format(DateTime::ATOM) |
49
|
|
|
]))); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* List all issues across owned and member repositories for the authenticated user |
54
|
|
|
* |
55
|
|
|
* @link https://developer.github.com/v3/issues/#list-issues |
56
|
|
|
* |
57
|
|
|
* @param string $filter |
58
|
|
|
* @param string $state |
59
|
|
|
* @param string $labels |
60
|
|
|
* @param string $sort |
61
|
|
|
* @param string $direction |
62
|
|
|
* @param string $since |
63
|
|
|
* |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
View Code Duplication |
public function listUserIssues(string $filter = AbstractApi::FILTER_ASSIGNED, |
|
|
|
|
67
|
|
|
string $state = AbstractApi::STATE_OPEN, string $labels = '', |
68
|
|
|
string $sort = AbstractApi::SORT_CREATED, |
69
|
|
|
string $direction = AbstractApi::DIRECTION_DESC, string $since = '1970-01-01'): array |
70
|
|
|
{ |
71
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/user/issues?:args', http_build_query([ |
72
|
|
|
'filter' => $filter, |
73
|
|
|
'state' => $state, |
74
|
|
|
'labels' => $labels, |
75
|
|
|
'sort' => $sort, |
76
|
|
|
'direction' => $direction, |
77
|
|
|
'since' => (new DateTime($since))->format(DateTime::ATOM) |
78
|
|
|
]))); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* List all issues for a given organization for the authenticated user |
83
|
|
|
* |
84
|
|
|
* @link https://developer.github.com/v3/issues/#list-issues |
85
|
|
|
* |
86
|
|
|
* @param string $organization |
87
|
|
|
* @param string $filter |
88
|
|
|
* @param string $state |
89
|
|
|
* @param string $labels |
90
|
|
|
* @param string $sort |
91
|
|
|
* @param string $direction |
92
|
|
|
* @param string $since |
93
|
|
|
* |
94
|
|
|
* @return array |
95
|
|
|
*/ |
96
|
|
View Code Duplication |
public function listOrganizationIssues(string $organization, string $filter = AbstractApi::FILTER_ASSIGNED, |
|
|
|
|
97
|
|
|
string $state = AbstractApi::STATE_OPEN, string $labels = '', |
98
|
|
|
string $sort = AbstractApi::SORT_CREATED, |
99
|
|
|
string $direction = AbstractApi::DIRECTION_DESC, |
100
|
|
|
string $since = '1970-01-01'): array |
101
|
|
|
{ |
102
|
|
|
return $this->getApi()->request($this->getApi() |
103
|
|
|
->sprintf('/orgs/:org/issues?:args', $organization, http_build_query([ |
104
|
|
|
'filter' => $filter, |
105
|
|
|
'state' => $state, |
106
|
|
|
'labels' => $labels, |
107
|
|
|
'sort' => $sort, |
108
|
|
|
'direction' => $direction, |
109
|
|
|
'since' => (new DateTime($since))->format(DateTime::ATOM) |
110
|
|
|
]))); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* List issues for a repository |
115
|
|
|
* |
116
|
|
|
* @link https://developer.github.com/v3/issues/#list-issues-for-a-repository |
117
|
|
|
* |
118
|
|
|
* @param string $milestone |
119
|
|
|
* @param string $state |
120
|
|
|
* @param string $assignee |
121
|
|
|
* @param string $creator |
122
|
|
|
* @param string $mentioned |
123
|
|
|
* @param string $labels |
124
|
|
|
* @param string $sort |
125
|
|
|
* @param string $direction |
126
|
|
|
* @param string $since |
127
|
|
|
* |
128
|
|
|
* @return array |
129
|
|
|
*/ |
130
|
|
|
public function listRepositoryIssues(string $milestone = '*', string $state = AbstractApi::STATE_OPEN, |
131
|
|
|
string $assignee = '*', string $creator = '', string $mentioned = '', |
132
|
|
|
string $labels = '', string $sort = AbstractApi::SORT_CREATED, |
133
|
|
|
string $direction = AbstractApi::DIRECTION_DESC, |
134
|
|
|
string $since = '1970-01-01'): array |
135
|
|
|
{ |
136
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/issues?:args', $this->getOwner(), |
137
|
|
|
$this->getRepo(), http_build_query([ |
138
|
|
|
'milestone' => $milestone, |
139
|
|
|
'state' => $state, |
140
|
|
|
'assignee' => $assignee, |
141
|
|
|
'creator' => $creator, |
142
|
|
|
'mentioned' => $mentioned, |
143
|
|
|
'labels' => $labels, |
144
|
|
|
'sort' => $sort, |
145
|
|
|
'direction' => $direction, |
146
|
|
|
'since' => (new DateTime($since))->format(DateTime::ATOM) |
147
|
|
|
]))); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Get a single issue |
152
|
|
|
* |
153
|
|
|
* @link https://developer.github.com/v3/issues/#get-a-single-issue |
154
|
|
|
* |
155
|
|
|
* @param int $number |
156
|
|
|
* |
157
|
|
|
* @return array |
158
|
|
|
*/ |
159
|
|
|
public function getIssue(int $number): array |
160
|
|
|
{ |
161
|
|
|
return $this->getApi()->request($this->getApi() |
162
|
|
|
->sprintf('/repos/:owner/:repo/issues/:number', $this->getOwner(), |
163
|
|
|
$this->getRepo(), $number)); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Create an issue |
168
|
|
|
* |
169
|
|
|
* @link https://developer.github.com/v3/issues/#create-an-issue |
170
|
|
|
* |
171
|
|
|
* @param string $title |
172
|
|
|
* @param string $body |
173
|
|
|
* @param string $assignee |
174
|
|
|
* @param int $milestone |
175
|
|
|
* @param array $labels |
176
|
|
|
* |
177
|
|
|
* @return array |
178
|
|
|
*/ |
179
|
|
View Code Duplication |
public function createIssue(string $title, string $body = '', string $assignee = '', int $milestone = 0, |
|
|
|
|
180
|
|
|
array $labels = []): array |
181
|
|
|
{ |
182
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/issues', $this->getOwner(), |
183
|
|
|
$this->getRepo()), Request::METHOD_POST, [ |
184
|
|
|
'title' => $title, |
185
|
|
|
'body' => $body, |
186
|
|
|
'assignee' => $assignee, |
187
|
|
|
'milestone' => $milestone, |
188
|
|
|
'labels' => $labels |
189
|
|
|
]); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Edit an issue |
194
|
|
|
* |
195
|
|
|
* @link https://developer.github.com/v3/issues/#edit-an-issue |
196
|
|
|
* |
197
|
|
|
* @param int $number |
198
|
|
|
* @param string $title |
199
|
|
|
* @param string $body |
200
|
|
|
* @param string $assignee |
201
|
|
|
* @param int $milestone |
202
|
|
|
* @param array $labels |
203
|
|
|
* |
204
|
|
|
* @return array |
205
|
|
|
*/ |
206
|
|
View Code Duplication |
public function editIssue(int $number, string $title = '', string $body = '', string $assignee = '', |
|
|
|
|
207
|
|
|
int $milestone = 0, array $labels = []): array |
208
|
|
|
{ |
209
|
|
|
return $this->getApi()->request($this->getApi() |
210
|
|
|
->sprintf('/repos/:owner/:repo/issues/:number', $this->getOwner(), |
211
|
|
|
$this->getRepo(), $number), Request::METHOD_PATCH, [ |
212
|
|
|
'title' => $title, |
213
|
|
|
'body' => $body, |
214
|
|
|
'assignee' => $assignee, |
215
|
|
|
'milestone' => $milestone, |
216
|
|
|
'labels' => $labels |
217
|
|
|
]); |
218
|
|
|
} |
219
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.