1
|
|
|
<?php |
2
|
|
|
namespace FlexyProject\GitHub\Receiver\Issues; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\HttpFoundation\Request; |
5
|
|
|
use FlexyProject\GitHub\AbstractApi; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* The Trees API class provides access to Issues's comments. |
9
|
|
|
* |
10
|
|
|
* @link https://developer.github.com/v3/issues/comments/ |
11
|
|
|
* @package FlexyProject\GitHub\Receiver\Issues |
12
|
|
|
*/ |
13
|
|
|
class Comments extends AbstractIssues |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* List comments on an issue |
18
|
|
|
* |
19
|
|
|
* @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue |
20
|
|
|
* |
21
|
|
|
* @param int $number |
22
|
|
|
* |
23
|
|
|
* @return array |
24
|
|
|
*/ |
25
|
|
|
public function listIssueComments(int $number): array |
26
|
|
|
{ |
27
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/issues/:number/comments', |
28
|
|
|
$this->getIssues()->getOwner(), $this->getIssues()->getRepo(), $number)); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* List comments in a repository |
33
|
|
|
* |
34
|
|
|
* @link https://developer.github.com/v3/issues/comments/#list-comments-in-a-repository |
35
|
|
|
* |
36
|
|
|
* @param string $sort |
37
|
|
|
* @param string $direction |
38
|
|
|
* @param string $since |
39
|
|
|
* |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
public function listRepositoryComments(string $sort = AbstractApi::SORT_CREATED, |
43
|
|
|
string $direction = AbstractApi::DIRECTION_DESC, |
44
|
|
|
string $since = 'now'): array |
45
|
|
|
{ |
46
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/issues/comments?:args', |
47
|
|
|
$this->getIssues()->getOwner(), $this->getIssues()->getRepo(), http_build_query([ |
48
|
|
|
'sort' => $sort, |
49
|
|
|
'direction' => $direction, |
50
|
|
|
'since' => $since |
51
|
|
|
]))); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get a single comment |
56
|
|
|
* |
57
|
|
|
* @link https://developer.github.com/v3/issues/comments/#get-a-single-comment |
58
|
|
|
* |
59
|
|
|
* @param int $id |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function getComment(int $id): array |
64
|
|
|
{ |
65
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/issues/comments/:id', |
66
|
|
|
$this->getIssues()->getOwner(), $this->getIssues()->getRepo(), $id)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Create a comment |
71
|
|
|
* |
72
|
|
|
* @link https://developer.github.com/v3/issues/comments/#create-a-comment |
73
|
|
|
* |
74
|
|
|
* @param int $number |
75
|
|
|
* @param string $body |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public function createComment(int $number, string $body): array |
80
|
|
|
{ |
81
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/issues/:number/comments', |
82
|
|
|
$this->getIssues()->getOwner(), $this->getIssues()->getRepo(), $number), Request::METHOD_POST, [ |
83
|
|
|
'body' => $body |
84
|
|
|
]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Edit a comment |
89
|
|
|
* |
90
|
|
|
* @link https://developer.github.com/v3/issues/comments/#edit-a-comment |
91
|
|
|
* |
92
|
|
|
* @param int $id |
93
|
|
|
* @param string $body |
94
|
|
|
* |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
|
|
public function editComment(int $id, string $body): array |
98
|
|
|
{ |
99
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/issues/comments/:id', |
100
|
|
|
$this->getIssues()->getOwner(), $this->getIssues()->getRepo(), $id), Request::METHOD_PATCH, [ |
101
|
|
|
'body' => $body |
102
|
|
|
]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Delete a comment |
107
|
|
|
* |
108
|
|
|
* @link https://developer.github.com/v3/issues/comments/#delete-a-comment |
109
|
|
|
* |
110
|
|
|
* @param int $id |
111
|
|
|
* |
112
|
|
|
* @return bool |
113
|
|
|
*/ |
114
|
|
|
public function deleteComment(int $id): bool |
115
|
|
|
{ |
116
|
|
|
$this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/issues/comments/:id', |
117
|
|
|
$this->getIssues()->getOwner(), $this->getIssues()->getRepo(), $id), Request::METHOD_DELETE); |
118
|
|
|
|
119
|
|
|
if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
120
|
|
|
return true; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return false; |
124
|
|
|
} |
125
|
|
|
} |