Skip to content

Commit 7a8417b

Browse files
committed
Work on milestones
1 parent 313d7ed commit 7a8417b

File tree

4 files changed

+225
-13
lines changed

4 files changed

+225
-13
lines changed

lib/Github/Api/Issue/Comments.php

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,72 @@
1111
*/
1212
class Comments extends AbstractApi
1313
{
14+
/**
15+
* Configure the body type.
16+
*
17+
* @param string $bodyType
18+
*/
1419
public function configure($bodyType = null)
1520
{
1621
switch ($bodyType) {
1722
case 'raw':
18-
$header = sprintf('Accept: application/vnd.github.%s.raw+json', $this->client->getOption('api_version'));
23+
$header = 'Accept: application/vnd.github.%s.raw+json';;
1924
break;
2025

2126
case 'text':
22-
$header = sprintf('Accept: application/vnd.github.%s.text+json', $this->client->getOption('api_version'));
27+
$header = 'Accept: application/vnd.github.%s.text+json';
2328
break;
2429

2530
case 'html':
26-
$header = sprintf('Accept: application/vnd.github.%s.html+json', $this->client->getOption('api_version'));
31+
$header = 'Accept: application/vnd.github.%s.html+json';
2732
break;
2833

2934
default:
30-
$header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getOption('api_version'));
35+
$header = 'Accept: application/vnd.github.%s.full+json';
3136
}
3237

33-
$this->client->setHeaders(array($header));
38+
$this->client->setHeaders(array(sprintf($header, $this->client->getOption('api_version'))));
3439
}
3540

41+
/**
42+
* Get all comments for an issue.
43+
*
44+
* @param string g$username
45+
* @param string $repository
46+
* @param int $issue
47+
* @param int $page
48+
* @return array
49+
*/
3650
public function all($username, $repository, $issue, $page = 1)
3751
{
3852
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', array(
3953
'page' => $page
4054
));
4155
}
4256

57+
/**
58+
* Get a comment for an issue.
59+
*
60+
* @param string $username
61+
* @param string $repository
62+
* @param int $comment
63+
* @return array
64+
*/
4365
public function show($username, $repository, $comment)
4466
{
4567
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment));
4668
}
4769

70+
/**
71+
* Create a comment for an issue.
72+
*
73+
* @param string $username
74+
* @param string $repository
75+
* @param int $issue
76+
* @param array $params
77+
* @return array
78+
* @throws \Github\Exception\MissingArgumentException
79+
*/
4880
public function create($username, $repository, $issue, array $params)
4981
{
5082
if (!isset($params['body'])) {
@@ -54,6 +86,16 @@ public function create($username, $repository, $issue, array $params)
5486
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $params);
5587
}
5688

89+
/**
90+
* Update a comment for an issue.
91+
*
92+
* @param string $username
93+
* @param string $repository
94+
* @param int $comment
95+
* @param array $params
96+
* @return array
97+
* @throws \Github\Exception\MissingArgumentException
98+
*/
5799
public function update($username, $repository, $comment, array $params)
58100
{
59101
if (!isset($params['body'])) {
@@ -63,6 +105,14 @@ public function update($username, $repository, $comment, array $params)
63105
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment), $params);
64106
}
65107

108+
/**
109+
* Delete a comment for an issue.
110+
*
111+
* @param string $username
112+
* @param string $repository
113+
* @param int $comment
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: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,36 @@
1010
*/
1111
class Events extends AbstractApi
1212
{
13+
/**
14+
* Get all events for an issue.
15+
*
16+
* @param string $username
17+
* @param string $repository
18+
* @param int|null $issue
19+
* @param int $page
20+
* @return array
21+
*/
1322
public function all($username, $repository, $issue = null, $page = 1)
1423
{
1524
if (null !== $issue) {
16-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events', array(
17-
'page' => $page
18-
));
25+
$path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events';
26+
} else {
27+
$path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events';
1928
}
2029

21-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events', array(
30+
return $this->get($path, array(
2231
'page' => $page
2332
));
2433
}
2534

35+
/**
36+
* Display an event for an issue.
37+
*
38+
* @param $username
39+
* @param $repository
40+
* @param $event
41+
* @return array
42+
*/
2643
public function show($username, $repository, $event)
2744
{
2845
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events/'.rawurlencode($event));

lib/Github/Api/Issue/Labels.php

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,37 @@
1212
*/
1313
class Labels extends AbstractApi
1414
{
15+
/**
16+
* Get all labels for a repository or the labels for a specific issue.
17+
*
18+
* @param string $username
19+
* @param string $repository
20+
* @param int|null $issue
21+
*
22+
* @return array
23+
*/
1524
public function all($username, $repository, $issue = null)
1625
{
1726
if ($issue === null) {
18-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels');
27+
$path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels';
28+
} else {
29+
$path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels';
1930
}
2031

21-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels');
32+
return $this->get($path);
2233
}
2334

35+
/**
36+
* Create a label for a repository.
37+
*
38+
* @param string $username
39+
* @param string $repository
40+
* @param array $params
41+
*
42+
* @return array
43+
*
44+
* @throws \Github\Exception\MissingArgumentException
45+
*/
2446
public function create($username, $repository, array $params)
2547
{
2648
if (!isset($params['name'])) {
@@ -33,21 +55,53 @@ public function create($username, $repository, array $params)
3355
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params);
3456
}
3557

58+
/**
59+
* Delete a label for a repository.
60+
*
61+
* @param string $username
62+
* @param string $repository
63+
* @param string $label
64+
*
65+
* @return array
66+
*/
3667
public function deleteLabel($username, $repository, $label)
3768
{
3869
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
3970
}
4071

72+
/**
73+
* Edit a label for a repository
74+
*
75+
* @param string $username
76+
* @param string $repository
77+
* @param string $label
78+
* @param string $newName
79+
* @param string $color
80+
*
81+
* @return array
82+
*/
4183
public function update($username, $repository, $label, $newName, $color)
4284
{
4385
$params = array(
44-
'name' => $newName,
86+
'name' => $newName,
4587
'color' => $color,
4688
);
4789

4890
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params);
4991
}
5092

93+
/**
94+
* Add a label to an issue.
95+
*
96+
* @param string $username
97+
* @param string $repository
98+
* @param int $issue
99+
* @param string $labels
100+
*
101+
* @return array
102+
*
103+
* @thorws \Github\Exception\InvalidArgumentException
104+
*/
51105
public function add($username, $repository, $issue, $labels)
52106
{
53107
if (is_string($labels)) {
@@ -59,16 +113,45 @@ public function add($username, $repository, $issue, $labels)
59113
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $labels);
60114
}
61115

116+
/**
117+
* Replace labels for an issue.
118+
*
119+
* @param string $username
120+
* @param string $repository
121+
* @param int $issue
122+
* @param array $params
123+
*
124+
* @return array
125+
*/
62126
public function replace($username, $repository, $issue, array $params)
63127
{
64128
return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $params);
65129
}
66130

131+
/**
132+
* Remove a label for an issue
133+
*
134+
* @param string $username
135+
* @param string $repository
136+
* @param string $issue
137+
* @param string $label
138+
*
139+
* @return null
140+
*/
67141
public function remove($username, $repository, $issue, $label)
68142
{
69143
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels/'.rawurlencode($label));
70144
}
71145

146+
/**
147+
* Remove all labels from an issue.
148+
*
149+
* @param string $username
150+
* @param string $repository
151+
* @param string $issue
152+
*
153+
* @return null
154+
*/
72155
public function clear($username, $repository, $issue)
73156
{
74157
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels');

lib/Github/Api/Issue/Milestones.php

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
*/
1212
class Milestones extends AbstractApi
1313
{
14+
/**
15+
* Get all milestones for a repository.
16+
*
17+
* @param string $username
18+
* @param string $repository
19+
* @param array $params
20+
*
21+
* @return array
22+
*/
1423
public function all($username, $repository, array $params = array())
1524
{
1625
if (isset($params['state']) && !in_array($params['state'], array('open', 'closed', 'all'))) {
@@ -23,14 +32,39 @@ public function all($username, $repository, array $params = array())
2332
$params['direction'] = 'desc';
2433
}
2534

26-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge(array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc'), $params));
35+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge(array(
36+
'page' => 1,
37+
'state' => 'open',
38+
'sort' => 'due_date',
39+
'direction' => 'desc'
40+
), $params));
2741
}
2842

43+
/**
44+
* Get a milestone for a repository.
45+
*
46+
* @param string $username
47+
* @param string $repository
48+
* @param int $id
49+
*
50+
* @return array
51+
*/
2952
public function show($username, $repository, $id)
3053
{
3154
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id));
3255
}
3356

57+
/**
58+
* Create a milestone for a repository.
59+
*
60+
* @param string $username
61+
* @param string $repository
62+
* @param array $params
63+
*
64+
* @return array
65+
*
66+
* @throws \Github\Exception\MissingArgumentException
67+
*/
3468
public function create($username, $repository, array $params)
3569
{
3670
if (!isset($params['title'])) {
@@ -43,6 +77,16 @@ public function create($username, $repository, array $params)
4377
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', $params);
4478
}
4579

80+
/**
81+
* Update a milestone for a repository.
82+
*
83+
* @param string $username
84+
* @param string $repository
85+
* @param int $id
86+
* @param array $params
87+
*
88+
* @return array
89+
*/
4690
public function update($username, $repository, $id, array $params)
4791
{
4892
if (isset($params['state']) && !in_array($params['state'], array('open', 'closed'))) {
@@ -52,11 +96,29 @@ public function update($username, $repository, $id, array $params)
5296
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id), $params);
5397
}
5498

99+
/**
100+
* Delete a milestone for a repository.
101+
*
102+
* @param string $username
103+
* @param string $repository
104+
* @param int $id
105+
*
106+
* @return null
107+
*/
55108
public function remove($username, $repository, $id)
56109
{
57110
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id));
58111
}
59112

113+
/**
114+
* Get the labels of a milestone
115+
*
116+
* @param string $username
117+
* @param string $repository
118+
* @param int $id
119+
*
120+
* @return array
121+
*/
60122
public function labels($username, $repository, $id)
61123
{
62124
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id).'/labels');

0 commit comments

Comments
 (0)