Skip to content

Commit 9a0ff6e

Browse files
Bertrand Jaminm1guelpf
Bertrand Jamin
authored andcommitted
Add routes to manage group boards
1 parent 04251cf commit 9a0ff6e

File tree

3 files changed

+365
-0
lines changed

3 files changed

+365
-0
lines changed

lib/Gitlab/Api/GroupsBoards.php

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php namespace Gitlab\Api;
2+
3+
class GroupsBoards extends AbstractApi
4+
{
5+
/**
6+
* @param int $group_id
7+
* @param array $parameters
8+
*
9+
* @return mixed
10+
*/
11+
public function all($group_id = null, array $parameters = [])
12+
{
13+
$resolver = $this->createOptionsResolver();
14+
15+
$path = $group_id === null ? 'boards' : $this->getGroupPath($group_id, 'boards');
16+
17+
return $this->get($path, $resolver->resolve($parameters));
18+
}
19+
20+
/**
21+
* @param int $group_id
22+
* @param int $board_id
23+
* @return mixed
24+
*/
25+
public function show($group_id, $board_id)
26+
{
27+
return $this->get($this->getGroupPath($group_id, 'boards/'.$this->encodePath($board_id)));
28+
}
29+
30+
/**
31+
* @param int $group_id
32+
* @param array $params
33+
* @return mixed
34+
*/
35+
public function create($group_id, array $params)
36+
{
37+
return $this->post($this->getGroupPath($group_id, 'boards'), $params);
38+
}
39+
40+
/**
41+
* @param int $group_id
42+
* @param int $board_id
43+
* @param array $params
44+
* @return mixed
45+
*/
46+
public function update($group_id, $board_id, array $params)
47+
{
48+
return $this->put($this->getGroupPath($group_id, 'boards/'.$this->encodePath($board_id)), $params);
49+
}
50+
51+
/**
52+
* @param int $group_id
53+
* @param int $board_id
54+
* @return mixed
55+
*/
56+
public function remove($group_id, $board_id)
57+
{
58+
return $this->delete($this->getGroupPath($group_id, 'boards/'.$this->encodePath($board_id)));
59+
}
60+
61+
/**
62+
* @param int $group_id
63+
* @param int $board_id
64+
* @return mixed
65+
*/
66+
public function allLists($group_id, $board_id)
67+
{
68+
return $this->get($this->getGroupPath($group_id, 'boards/'.$this->encodePath($board_id).'/lists'));
69+
}
70+
71+
/**
72+
* @param int $group_id
73+
* @param int $board_id
74+
* @param int $list_id
75+
* @return mixed
76+
*/
77+
public function showList($group_id, $board_id, $list_id)
78+
{
79+
return $this->get($this->getGroupPath($group_id, 'boards/'.$this->encodePath($board_id).'/lists/'.$this->encodePath($list_id)));
80+
}
81+
82+
/**
83+
* @param int $group_id
84+
* @param int $board_id
85+
* @param int $label_id
86+
* @return mixed
87+
*/
88+
public function createList($group_id, $board_id, $label_id)
89+
{
90+
$params = array(
91+
'label_id' => $label_id
92+
);
93+
94+
return $this->post($this->getGroupPath($group_id, 'boards/'.$this->encodePath($board_id).'/lists'), $params);
95+
}
96+
97+
/**
98+
* @param int $group_id
99+
* @param int $board_id
100+
* @param int $list_id
101+
* @param int $position
102+
* @return mixed
103+
*/
104+
public function updateList($group_id, $board_id, $list_id, $position)
105+
{
106+
$params = array(
107+
'position' => $position
108+
);
109+
110+
return $this->put($this->getGroupPath($group_id, 'boards/'.$this->encodePath($board_id).'/lists/'.$this->encodePath($list_id)), $params);
111+
}
112+
113+
/**
114+
* @param int $group_id
115+
* @param int $board_id
116+
* @param int $list_id
117+
* @return mixed
118+
*/
119+
public function deleteList($group_id, $board_id, $list_id)
120+
{
121+
return $this->delete($this->getGroupPath($group_id, 'boards/'.$this->encodePath($board_id).'/lists/'.$this->encodePath($list_id)));
122+
}
123+
}

lib/Gitlab/Client.php

+12
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ public function issueBoards()
158158
return new Api\IssueBoards($this);
159159
}
160160

161+
/**
162+
* @return Api\GroupsBoards
163+
*/
164+
public function groupsBoards()
165+
{
166+
return new Api\GroupsBoards($this);
167+
}
168+
169+
161170
/**
162171
* @return Api\IssueLinks
163172
*/
@@ -312,6 +321,9 @@ public function api($name)
312321
case 'issue_boards':
313322
return $this->issueBoards();
314323

324+
case 'group_boards':
325+
return $this->groupsBoards();
326+
315327
case 'issue_links':
316328
return $this->issueLinks();
317329

+230
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
<?php namespace Gitlab\Tests\Api;
2+
3+
class GroupBoardsTest extends TestCase
4+
{
5+
/**
6+
* @test
7+
*/
8+
public function shouldGetAllBoards()
9+
{
10+
$expectedArray = array(
11+
array('id' => 1, 'title' => 'A board'),
12+
array('id' => 2, 'title' => 'Another board'),
13+
);
14+
15+
$api = $this->getApiMock();
16+
$api->expects($this->once())
17+
->method('get')
18+
->with('boards', array())
19+
->will($this->returnValue($expectedArray))
20+
;
21+
22+
$this->assertEquals($expectedArray, $api->all());
23+
}
24+
25+
/**
26+
* @test
27+
*/
28+
public function shouldShowIssueBoard()
29+
{
30+
$expectedArray = array('id' => 2, 'name' => 'Another issue board');
31+
32+
$api = $this->getApiMock();
33+
$api->expects($this->once())
34+
->method('get')
35+
->with('groups/1/boards/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 shouldCreateIssueBoard()
46+
{
47+
$expectedArray = array('id' => 3, 'name' => 'A new issue board');
48+
49+
$api = $this->getApiMock();
50+
$api->expects($this->once())
51+
->method('post')
52+
->with('groups/1/boards', array('name' => 'A new issue board'))
53+
->will($this->returnValue($expectedArray))
54+
;
55+
56+
$this->assertEquals($expectedArray, $api->create(1, array('name' => 'A new issue board')));
57+
}
58+
59+
/**
60+
* @test
61+
*/
62+
public function shouldUpdateIssueBoard()
63+
{
64+
$expectedArray = array('id' => 2, 'name' => 'A renamed issue board');
65+
66+
$api = $this->getApiMock();
67+
$api->expects($this->once())
68+
->method('put')
69+
->with('groups/1/boards/2', array('name' => 'A renamed issue board', 'labels' => 'foo'))
70+
->will($this->returnValue($expectedArray))
71+
;
72+
73+
$this->assertEquals($expectedArray, $api->update(1, 2, array('name' => 'A renamed issue board', 'labels' => 'foo')));
74+
}
75+
76+
/**
77+
* @test
78+
*/
79+
public function shouldRemoveIssueBoard()
80+
{
81+
$expectedBool = true;
82+
83+
$api = $this->getApiMock();
84+
$api->expects($this->once())
85+
->method('delete')
86+
->with('groups/1/boards/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 shouldGetAllLists()
97+
{
98+
$expectedArray = array(
99+
array(
100+
'id' => 1,
101+
'label' => array(
102+
'name' => 'First label',
103+
'color' => '#F0AD4E',
104+
'description' => null
105+
),
106+
'position' => 1
107+
), array(
108+
'id' => 2,
109+
'label' => array(
110+
'name' => 'Second label',
111+
'color' => '#F0AD4E',
112+
'description' => null
113+
),
114+
'position' => 2
115+
)
116+
);
117+
118+
$api = $this->getApiMock();
119+
$api->expects($this->once())
120+
->method('get')
121+
->with('groups/1/boards/2/lists')
122+
->will($this->returnValue($expectedArray))
123+
;
124+
125+
$this->assertEquals($expectedArray, $api->allLists(1, 2));
126+
}
127+
128+
/**
129+
* @test
130+
*/
131+
public function shouldGetList()
132+
{
133+
$expectedArray = array(
134+
array(
135+
'id' => 3,
136+
'label' => array(
137+
'name' => 'Some label',
138+
'color' => '#F0AD4E',
139+
'description' => null
140+
),
141+
'position' => 3
142+
)
143+
);
144+
145+
$api = $this->getApiMock();
146+
$api->expects($this->once())
147+
->method('get')
148+
->with('groups/1/boards/2/lists/3')
149+
->will($this->returnValue($expectedArray))
150+
;
151+
152+
$this->assertEquals($expectedArray, $api->showList(1, 2, 3));
153+
}
154+
155+
/**
156+
* @test
157+
*/
158+
public function shouldCreateList()
159+
{
160+
$expectedArray = array(
161+
array(
162+
'id' => 3,
163+
'label' => array(
164+
'name' => 'Some label',
165+
'color' => '#F0AD4E',
166+
'description' => null
167+
),
168+
'position' => 3
169+
)
170+
);
171+
172+
$api = $this->getApiMock();
173+
$api->expects($this->once())
174+
->method('post')
175+
->with('groups/1/boards/2/lists', array('label_id' => 4))
176+
->will($this->returnValue($expectedArray))
177+
;
178+
179+
$this->assertEquals($expectedArray, $api->createList(1, 2, 4));
180+
}
181+
182+
/**
183+
* @test
184+
*/
185+
public function shouldUpdateList()
186+
{
187+
$expectedArray = array(
188+
array(
189+
'id' => 3,
190+
'label' => array(
191+
'name' => 'Some label',
192+
'color' => '#F0AD4E',
193+
'description' => null
194+
),
195+
'position' => 1
196+
)
197+
);
198+
199+
$api = $this->getApiMock();
200+
$api->expects($this->once())
201+
->method('put')
202+
->with('groups/5/boards/2/lists/3', array('position' => 1))
203+
->will($this->returnValue($expectedArray))
204+
;
205+
206+
$this->assertEquals($expectedArray, $api->updateList(5, 2, 3, 1));
207+
}
208+
209+
/**
210+
* @test
211+
*/
212+
public function shouldDeleteList()
213+
{
214+
$expectedBool = true;
215+
216+
$api = $this->getApiMock();
217+
$api->expects($this->once())
218+
->method('delete')
219+
->with('groups/1/boards/2/lists/3')
220+
->will($this->returnValue($expectedBool))
221+
;
222+
223+
$this->assertEquals($expectedBool, $api->deleteList(1, 2, 3));
224+
}
225+
226+
protected function getApiClass()
227+
{
228+
return 'Gitlab\Api\GroupsBoards';
229+
}
230+
}

0 commit comments

Comments
 (0)