Skip to content

Commit 1eba4cd

Browse files
Bertrand Jaminm1guelpf
authored andcommitted
Add GroupsMilestones routes
1 parent a020488 commit 1eba4cd

File tree

4 files changed

+249
-0
lines changed

4 files changed

+249
-0
lines changed

lib/Gitlab/Api/AbstractApi.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ protected function getProjectPath($id, $path)
163163
return 'projects/'.$this->encodePath($id).'/'.$path;
164164
}
165165

166+
/**
167+
* @param int $id
168+
* @param string $path
169+
* @return string
170+
*/
171+
protected function getGroupPath($id, $path)
172+
{
173+
return 'groups/'.$this->encodePath($id).'/'.$path;
174+
}
175+
166176
/**
167177
* @param string $path
168178
* @return string

lib/Gitlab/Api/GroupsMilestones.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php namespace Gitlab\Api;
2+
3+
class GroupsMilestones extends AbstractApi
4+
{
5+
/**
6+
* @param int $group_id
7+
* @param array $parameters (
8+
*
9+
* @var int[] $iids Return only the milestones having the given iids.
10+
* @var string $state Return only active or closed milestones.
11+
* @var string $search Return only milestones with a title or description matching the provided string.
12+
* )
13+
*
14+
* @return mixed
15+
*/
16+
public function all($group_id, array $parameters = [])
17+
{
18+
$resolver = $this->createOptionsResolver();
19+
$resolver->setDefined('iids')
20+
->setAllowedTypes('iids', 'array')
21+
->setAllowedValues('iids', function (array $value) {
22+
return count($value) == count(array_filter($value, 'is_int'));
23+
})
24+
;
25+
$resolver->setDefined('state')
26+
->setAllowedValues('state', ['active', 'closed'])
27+
;
28+
$resolver->setDefined('search');
29+
30+
return $this->get($this->getGroupPath($group_id, 'milestones'), $resolver->resolve($parameters));
31+
}
32+
33+
/**
34+
* @param int $group_id
35+
* @param int $milestone_id
36+
* @return mixed
37+
*/
38+
public function show($group_id, $milestone_id)
39+
{
40+
return $this->get($this->getGroupPath($group_id, 'milestones/'.$this->encodePath($milestone_id)));
41+
}
42+
43+
/**
44+
* @param int $group_id
45+
* @param array $params
46+
* @return mixed
47+
*/
48+
public function create($group_id, array $params)
49+
{
50+
return $this->post($this->getGroupPath($group_id, 'milestones'), $params);
51+
}
52+
53+
/**
54+
* @param int $group_id
55+
* @param int $milestone_id
56+
* @param array $params
57+
* @return mixed
58+
*/
59+
public function update($group_id, $milestone_id, array $params)
60+
{
61+
return $this->put($this->getGroupPath($group_id, 'milestones/'.$this->encodePath($milestone_id)), $params);
62+
}
63+
64+
/**
65+
* @param int $project_id
66+
* @param int $milestone_id
67+
* @return mixed
68+
*/
69+
public function remove($group_id, $milestone_id)
70+
{
71+
return $this->delete($this->getGroupPath($group_id, 'milestones/'.$this->encodePath($milestone_id)));
72+
}
73+
74+
75+
/**
76+
* @param int $group_id
77+
* @param int $milestone_id
78+
* @return mixed
79+
*/
80+
public function issues($group_id, $milestone_id)
81+
{
82+
return $this->get($this->getGroupPath($group_id, 'milestones/'.$this->encodePath($milestone_id).'/issues'));
83+
}
84+
85+
/**
86+
* @param int $group_id
87+
* @param int $milestone_id
88+
* @return mixed
89+
*/
90+
public function mergeRequests($group_id, $milestone_id)
91+
{
92+
return $this->get($this->getGroupPath($group_id, 'milestones/'.$this->encodePath($milestone_id).'/merge_requests'));
93+
}
94+
}

lib/Gitlab/Client.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ public function groups()
134134
return new Api\Groups($this);
135135
}
136136

137+
/**
138+
* @return Api\GroupsMilestones
139+
*/
140+
public function groupsMilestones()
141+
{
142+
return new Api\GroupsMilestones($this);
143+
}
144+
137145
/**
138146
* @return Api\Issues
139147
*/
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php namespace Gitlab\Tests\Api;
2+
3+
class GroupsMilestonesTest extends TestCase
4+
{
5+
/**
6+
* @test
7+
*/
8+
public function shouldGetAllMilestones()
9+
{
10+
$expectedArray = array(
11+
array('id' => 1, 'title' => 'A milestone'),
12+
array('id' => 2, 'title' => 'Another milestone'),
13+
);
14+
15+
$api = $this->getApiMock();
16+
$api->expects($this->once())
17+
->method('get')
18+
->with('groups/1/milestones')
19+
->will($this->returnValue($expectedArray))
20+
;
21+
22+
$this->assertEquals($expectedArray, $api->all(1));
23+
}
24+
25+
/**
26+
* @test
27+
*/
28+
public function shouldShowMilestone()
29+
{
30+
$expectedArray = array('id' => 1, 'name' => 'A milestone');
31+
32+
$api = $this->getApiMock();
33+
$api->expects($this->once())
34+
->method('get')
35+
->with('groups/1/milestones/2')
36+
->will($this->returnValue($expectedArray))
37+
;
38+
39+
$this->assertEquals($expectedArray, $api->show(1, 2));
40+
}
41+
42+
/**
43+
* @test
44+
*/
45+
public function shouldCreateMilestone()
46+
{
47+
$expectedArray = array('id' => 3, 'title' => 'A new milestone');
48+
49+
$api = $this->getApiMock();
50+
$api->expects($this->once())
51+
->method('post')
52+
->with('groups/1/milestones', array('description' => 'Some text', 'title' => 'A new milestone'))
53+
->will($this->returnValue($expectedArray))
54+
;
55+
56+
$this->assertEquals($expectedArray, $api->create(1, array('description' => 'Some text', 'title' => 'A new milestone')));
57+
}
58+
59+
/**
60+
* @test
61+
*/
62+
public function shouldUpdateMilestone()
63+
{
64+
$expectedArray = array('id' => 3, 'title' => 'Updated milestone');
65+
66+
$api = $this->getApiMock();
67+
$api->expects($this->once())
68+
->method('put')
69+
->with('groups/1/milestones/3', array('title' => 'Updated milestone', 'due_date' => '2015-04-01', 'state_event' => 'close'))
70+
->will($this->returnValue($expectedArray))
71+
;
72+
73+
$this->assertEquals($expectedArray, $api->update(1, 3, array('title' => 'Updated milestone', 'due_date' => '2015-04-01', 'state_event' => 'close')));
74+
}
75+
76+
/**
77+
* @test
78+
*/
79+
public function shouldRemoveMilestone()
80+
{
81+
$expectedBool = true;
82+
83+
$api = $this->getApiMock();
84+
$api->expects($this->once())
85+
->method('delete')
86+
->with('groups/1/milestones/2')
87+
->will($this->returnValue($expectedBool))
88+
;
89+
90+
$this->assertEquals($expectedBool, $api->remove(1, 2));
91+
}
92+
93+
/**
94+
* @test
95+
*/
96+
public function shouldGetMilestonesIssues()
97+
{
98+
$expectedArray = array(
99+
array('id' => 1, 'title' => 'An issue'),
100+
array('id' => 2, 'title' => 'Another issue'),
101+
);
102+
103+
$api = $this->getApiMock();
104+
$api->expects($this->once())
105+
->method('get')
106+
->with('groups/1/milestones/3/issues')
107+
->will($this->returnValue($expectedArray))
108+
;
109+
110+
$this->assertEquals($expectedArray, $api->issues(1, 3));
111+
}
112+
113+
/**
114+
* @test
115+
*/
116+
public function shouldGetMilestonesMergeRequests()
117+
{
118+
$expectedArray = array(
119+
array('id' => 1, 'title' => 'A merge request'),
120+
array('id' => 2, 'title' => 'Another merge request'),
121+
);
122+
123+
$api = $this->getApiMock();
124+
$api->expects($this->once())
125+
->method('get')
126+
->with('groups/1/milestones/3/merge_requests')
127+
->will($this->returnValue($expectedArray))
128+
;
129+
130+
$this->assertEquals($expectedArray, $api->mergeRequests(1, 3));
131+
}
132+
133+
protected function getApiClass()
134+
{
135+
return 'Gitlab\Api\GroupsMilestones';
136+
}
137+
}

0 commit comments

Comments
 (0)