Skip to content

Commit 80f4547

Browse files
committed
feat: add reaction support to endpoints
1 parent 8b5c8e1 commit 80f4547

21 files changed

Lines changed: 696 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace Github\Api;
4+
5+
use Github\Exception\MissingArgumentException;
6+
7+
abstract class AbstractReactionsApi extends AbstractApi
8+
{
9+
/**
10+
* List reactions for a resource.
11+
*
12+
* @param string $username
13+
* @param string $repository
14+
* @param string $id
15+
* @param array $params
16+
*
17+
* @return array
18+
*/
19+
public function all($username, $repository, $id, array $params = [])
20+
{
21+
return $this->get($this->getReactionsPath($username, $repository, $id), $params);
22+
}
23+
24+
/**
25+
* Create a reaction for a resource.
26+
*
27+
* @param string $username
28+
* @param string $repository
29+
* @param string $id
30+
* @param array $params
31+
*
32+
* @throws MissingArgumentException
33+
*
34+
* @return array
35+
*/
36+
public function create($username, $repository, $id, array $params)
37+
{
38+
if (!isset($params['content'])) {
39+
throw new MissingArgumentException('content');
40+
}
41+
42+
return $this->post($this->getReactionsPath($username, $repository, $id), $params);
43+
}
44+
45+
/**
46+
* Delete a reaction from a resource.
47+
*
48+
* @param string $username
49+
* @param string $repository
50+
* @param string $id
51+
* @param string $reaction
52+
*
53+
* @return array|string
54+
*/
55+
public function remove($username, $repository, $id, $reaction)
56+
{
57+
return $this->delete($this->getReactionsPath($username, $repository, $id).'/'.rawurlencode($reaction));
58+
}
59+
60+
/**
61+
* @param string $username
62+
* @param string $repository
63+
* @param string $id
64+
*
65+
* @return string
66+
*/
67+
abstract protected function getReactionsPath($username, $repository, $id);
68+
}

lib/Github/Api/Issue.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Github\Api\Issue\Events;
88
use Github\Api\Issue\Labels;
99
use Github\Api\Issue\Milestones;
10+
use Github\Api\Issue\Reactions;
1011
use Github\Api\Issue\Timeline;
1112
use Github\Exception\MissingArgumentException;
1213

@@ -179,6 +180,18 @@ public function comments()
179180
return new Comments($this->getClient());
180181
}
181182

183+
/**
184+
* Manage issue reactions.
185+
*
186+
* @link https://docs.github.com/en/rest/reactions/reactions#list-reactions-for-an-issue
187+
*
188+
* @return Reactions
189+
*/
190+
public function reactions()
191+
{
192+
return new Reactions($this->getClient());
193+
}
194+
182195
/**
183196
* List all project events.
184197
*

lib/Github/Api/Issue/Comments.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Github\Api\AbstractApi;
66
use Github\Api\AcceptHeaderTrait;
7+
use Github\Api\Issue\Comments\Reactions;
78
use Github\Exception\MissingArgumentException;
89

910
/**
@@ -130,4 +131,16 @@ public function remove($username, $repository, $comment)
130131
{
131132
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.$comment);
132133
}
134+
135+
/**
136+
* Manage issue comment reactions.
137+
*
138+
* @link https://docs.github.com/en/rest/reactions/reactions#list-reactions-for-an-issue-comment
139+
*
140+
* @return Reactions
141+
*/
142+
public function reactions()
143+
{
144+
return new Reactions($this->getClient());
145+
}
133146
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Github\Api\Issue\Comments;
4+
5+
use Github\Api\AbstractReactionsApi;
6+
7+
class Reactions extends AbstractReactionsApi
8+
{
9+
/**
10+
* @param string $username
11+
* @param string $repository
12+
* @param string $id
13+
*
14+
* @return string
15+
*/
16+
protected function getReactionsPath($username, $repository, $id)
17+
{
18+
return '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($id).'/reactions';
19+
}
20+
}

lib/Github/Api/Issue/Reactions.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Github\Api\Issue;
4+
5+
use Github\Api\AbstractReactionsApi;
6+
7+
class Reactions extends AbstractReactionsApi
8+
{
9+
/**
10+
* @param string $username
11+
* @param string $repository
12+
* @param string $id
13+
*
14+
* @return string
15+
*/
16+
protected function getReactionsPath($username, $repository, $id)
17+
{
18+
return '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/reactions';
19+
}
20+
}

lib/Github/Api/PullRequest/Comments.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Github\Api\AbstractApi;
66
use Github\Api\AcceptHeaderTrait;
7+
use Github\Api\PullRequest\Comments\Reactions;
78
use Github\Exception\MissingArgumentException;
89

910
/**
@@ -150,4 +151,16 @@ public function remove($username, $repository, $comment)
150151
{
151152
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.$comment);
152153
}
154+
155+
/**
156+
* Manage pull request review comment reactions.
157+
*
158+
* @link https://docs.github.com/en/rest/reactions/reactions#list-reactions-for-a-pull-request-review-comment
159+
*
160+
* @return Reactions
161+
*/
162+
public function reactions()
163+
{
164+
return new Reactions($this->getClient());
165+
}
153166
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Github\Api\PullRequest\Comments;
4+
5+
use Github\Api\AbstractReactionsApi;
6+
7+
class Reactions extends AbstractReactionsApi
8+
{
9+
/**
10+
* @param string $username
11+
* @param string $repository
12+
* @param string $id
13+
*
14+
* @return string
15+
*/
16+
protected function getReactionsPath($username, $repository, $id)
17+
{
18+
return '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($id).'/reactions';
19+
}
20+
}

lib/Github/Api/Repository/Comments.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Github\Api\AbstractApi;
66
use Github\Api\AcceptHeaderTrait;
7+
use Github\Api\Repository\Comments\Reactions;
78
use Github\Exception\MissingArgumentException;
89

910
/**
@@ -72,4 +73,16 @@ public function remove($username, $repository, $comment)
7273
{
7374
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment));
7475
}
76+
77+
/**
78+
* Manage commit comment reactions.
79+
*
80+
* @link https://docs.github.com/en/rest/reactions/reactions#list-reactions-for-a-commit-comment
81+
*
82+
* @return Reactions
83+
*/
84+
public function reactions()
85+
{
86+
return new Reactions($this->getClient());
87+
}
7588
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Github\Api\Repository\Comments;
4+
5+
use Github\Api\AbstractReactionsApi;
6+
7+
class Reactions extends AbstractReactionsApi
8+
{
9+
/**
10+
* @param string $username
11+
* @param string $repository
12+
* @param string $id
13+
*
14+
* @return string
15+
*/
16+
protected function getReactionsPath($username, $repository, $id)
17+
{
18+
return '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($id).'/reactions';
19+
}
20+
}

lib/Github/Api/Repository/Releases.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Github\Api\Repository;
44

55
use Github\Api\AbstractApi;
6+
use Github\Api\Repository\Releases\Reactions;
67
use Github\Exception\MissingArgumentException;
78

89
/**
@@ -138,4 +139,16 @@ public function assets()
138139
{
139140
return new Assets($this->getClient());
140141
}
142+
143+
/**
144+
* Manage release reactions.
145+
*
146+
* @link https://docs.github.com/en/rest/reactions/reactions#list-reactions-for-a-release
147+
*
148+
* @return Reactions
149+
*/
150+
public function reactions()
151+
{
152+
return new Reactions($this->getClient());
153+
}
141154
}

0 commit comments

Comments
 (0)