Skip to content

Commit 1b75a94

Browse files
committed
Merge pull request #291 from lucasmichot/feature/issues
Work on issues
2 parents 313d7ed + 26b738c commit 1b75a94

File tree

4 files changed

+250
-24
lines changed

4 files changed

+250
-24
lines changed

lib/Github/Api/Issue/Comments.php

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,68 @@
1111
*/
1212
class Comments extends AbstractApi
1313
{
14+
/**
15+
* Configure the body type.
16+
*
17+
* @link https://developer.github.com/v3/issues/comments/#custom-media-types
18+
* @param string|null $bodyType
19+
*/
1420
public function configure($bodyType = null)
1521
{
16-
switch ($bodyType) {
17-
case 'raw':
18-
$header = sprintf('Accept: application/vnd.github.%s.raw+json', $this->client->getOption('api_version'));
19-
break;
20-
21-
case 'text':
22-
$header = sprintf('Accept: application/vnd.github.%s.text+json', $this->client->getOption('api_version'));
23-
break;
24-
25-
case 'html':
26-
$header = sprintf('Accept: application/vnd.github.%s.html+json', $this->client->getOption('api_version'));
27-
break;
28-
29-
default:
30-
$header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getOption('api_version'));
22+
if (!in_array($bodyType, array('raw', 'text', 'html'))) {
23+
$bodyType = 'full';
3124
}
3225

33-
$this->client->setHeaders(array($header));
26+
$this->client->setHeaders(array(
27+
sprintf('Accept: application/vnd.github.%s.%s+json', $this->client->getOption('api_version'), $bodyType)
28+
));
3429
}
3530

31+
/**
32+
* Get all comments for an issue.
33+
*
34+
* @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
35+
* @param string $username
36+
* @param string $repository
37+
* @param int $issue
38+
* @param int $page
39+
*
40+
* @return array
41+
*/
3642
public function all($username, $repository, $issue, $page = 1)
3743
{
3844
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', array(
3945
'page' => $page
4046
));
4147
}
4248

49+
/**
50+
* Get a comment for an issue.
51+
*
52+
* @link https://developer.github.com/v3/issues/comments/#get-a-single-comment
53+
* @param string $username
54+
* @param string $repository
55+
* @param int $comment
56+
*
57+
* @return array
58+
*/
4359
public function show($username, $repository, $comment)
4460
{
4561
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment));
4662
}
4763

64+
/**
65+
* Create a comment for an issue.
66+
*
67+
* @link https://developer.github.com/v3/issues/comments/#create-a-comment
68+
* @param string $username
69+
* @param string $repository
70+
* @param int $issue
71+
* @param array $params
72+
*
73+
* @throws \Github\Exception\MissingArgumentException
74+
* @return array
75+
*/
4876
public function create($username, $repository, $issue, array $params)
4977
{
5078
if (!isset($params['body'])) {
@@ -54,6 +82,18 @@ public function create($username, $repository, $issue, array $params)
5482
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $params);
5583
}
5684

85+
/**
86+
* Update a comment for an issue.
87+
*
88+
* @link https://developer.github.com/v3/issues/comments/#edit-a-comment
89+
* @param string $username
90+
* @param string $repository
91+
* @param int $comment
92+
* @param array $params
93+
*
94+
* @throws \Github\Exception\MissingArgumentException
95+
* @return array
96+
*/
5797
public function update($username, $repository, $comment, array $params)
5898
{
5999
if (!isset($params['body'])) {
@@ -63,6 +103,16 @@ public function update($username, $repository, $comment, array $params)
63103
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment), $params);
64104
}
65105

106+
/**
107+
* Delete a comment for an issue.
108+
*
109+
* @link https://developer.github.com/v3/issues/comments/#delete-a-comment
110+
* @param string $username
111+
* @param string $repository
112+
* @param int $comment
113+
*
114+
* @return array
115+
*/
66116
public function remove($username, $repository, $comment)
67117
{
68118
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment));

lib/Github/Api/Issue/Events.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,38 @@
1010
*/
1111
class Events extends AbstractApi
1212
{
13+
/**
14+
* Get all events for an issue.
15+
*
16+
* @link https://developer.github.com/v3/issues/events/#list-events-for-an-issue
17+
* @param string $username
18+
* @param string $repository
19+
* @param int|null $issue
20+
* @param int $page
21+
* @return array
22+
*/
1323
public function all($username, $repository, $issue = null, $page = 1)
1424
{
1525
if (null !== $issue) {
16-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events', array(
17-
'page' => $page
18-
));
26+
$path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events';
27+
} else {
28+
$path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events';
1929
}
2030

21-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events', array(
31+
return $this->get($path, array(
2232
'page' => $page
2333
));
2434
}
2535

36+
/**
37+
* Display an event for an issue.
38+
*
39+
* @link https://developer.github.com/v3/issues/events/#get-a-single-event
40+
* @param $username
41+
* @param $repository
42+
* @param $event
43+
* @return array
44+
*/
2645
public function show($username, $repository, $event)
2746
{
2847
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events/'.rawurlencode($event));

lib/Github/Api/Issue/Labels.php

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,38 @@
1212
*/
1313
class Labels extends AbstractApi
1414
{
15+
/**
16+
* Get all labels for a repository or the labels for a specific issue.
17+
*
18+
* @link https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue
19+
* @param string $username
20+
* @param string $repository
21+
* @param int|null $issue
22+
*
23+
* @return array
24+
*/
1525
public function all($username, $repository, $issue = null)
1626
{
1727
if ($issue === null) {
18-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels');
28+
$path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels';
29+
} else {
30+
$path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels';
1931
}
2032

21-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels');
33+
return $this->get($path);
2234
}
2335

36+
/**
37+
* Create a label for a repository.
38+
*
39+
* @param string $username
40+
* @param string $repository
41+
* @param array $params
42+
*
43+
* @return array
44+
*
45+
* @throws \Github\Exception\MissingArgumentException
46+
*/
2447
public function create($username, $repository, array $params)
2548
{
2649
if (!isset($params['name'])) {
@@ -33,21 +56,55 @@ public function create($username, $repository, array $params)
3356
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params);
3457
}
3558

59+
/**
60+
* Delete a label for a repository.
61+
*
62+
* @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
63+
* @param string $username
64+
* @param string $repository
65+
* @param string $label
66+
*
67+
* @return array
68+
*/
3669
public function deleteLabel($username, $repository, $label)
3770
{
3871
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
3972
}
4073

74+
/**
75+
* Edit a label for a repository
76+
*
77+
* @param string $username
78+
* @param string $repository
79+
* @param string $label
80+
* @param string $newName
81+
* @param string $color
82+
*
83+
* @return array
84+
*/
4185
public function update($username, $repository, $label, $newName, $color)
4286
{
4387
$params = array(
44-
'name' => $newName,
88+
'name' => $newName,
4589
'color' => $color,
4690
);
4791

4892
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params);
4993
}
5094

95+
/**
96+
* Add a label to an issue.
97+
*
98+
* @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
99+
* @param string $username
100+
* @param string $repository
101+
* @param int $issue
102+
* @param string $labels
103+
*
104+
* @return array
105+
*
106+
* @thorws \Github\Exception\InvalidArgumentException
107+
*/
51108
public function add($username, $repository, $issue, $labels)
52109
{
53110
if (is_string($labels)) {
@@ -59,16 +116,48 @@ public function add($username, $repository, $issue, $labels)
59116
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $labels);
60117
}
61118

119+
/**
120+
* Replace labels for an issue.
121+
*
122+
* @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
123+
* @param string $username
124+
* @param string $repository
125+
* @param int $issue
126+
* @param array $params
127+
*
128+
* @return array
129+
*/
62130
public function replace($username, $repository, $issue, array $params)
63131
{
64132
return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $params);
65133
}
66134

135+
/**
136+
* Remove a label for an issue
137+
*
138+
* @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
139+
* @param string $username
140+
* @param string $repository
141+
* @param string $issue
142+
* @param string $label
143+
*
144+
* @return null
145+
*/
67146
public function remove($username, $repository, $issue, $label)
68147
{
69148
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels/'.rawurlencode($label));
70149
}
71150

151+
/**
152+
* Remove all labels from an issue.
153+
*
154+
* @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
155+
* @param string $username
156+
* @param string $repository
157+
* @param string $issue
158+
*
159+
* @return null
160+
*/
72161
public function clear($username, $repository, $issue)
73162
{
74163
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels');

0 commit comments

Comments
 (0)