Skip to content

Commit dbaaa90

Browse files
Add epics endpoint (#633)
Closes #512, #293
1 parent 5119c59 commit dbaaa90

File tree

3 files changed

+223
-0
lines changed

3 files changed

+223
-0
lines changed

src/Api/GroupsEpics.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Gitlab API library.
7+
*
8+
* (c) Matt Humphrey <[email protected]>
9+
* (c) Graham Campbell <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Gitlab\Api;
16+
17+
class GroupsEpics extends AbstractApi
18+
{
19+
/**
20+
* @var string
21+
*/
22+
public const STATE_ACTIVE = 'active';
23+
24+
/**
25+
* @var string
26+
*/
27+
public const STATE_CLOSED = 'closed';
28+
29+
/**
30+
* @param int|string $group_id
31+
* @param array $parameters {
32+
*
33+
* @var int[] $iids return only the epics having the given iids
34+
* @var string $state return only active or closed epics
35+
* @var string $search Return only epics with a title or description matching the provided string.
36+
* }
37+
*
38+
* @return mixed
39+
*/
40+
public function all($group_id, array $parameters = [])
41+
{
42+
$resolver = $this->createOptionsResolver();
43+
$resolver->setDefined('iids')
44+
->setAllowedTypes('iids', 'array')
45+
->setAllowedValues('iids', function (array $value) {
46+
return \count($value) === \count(\array_filter($value, 'is_int'));
47+
})
48+
;
49+
$resolver->setDefined('state')
50+
->setAllowedValues('state', [self::STATE_ACTIVE, self::STATE_CLOSED])
51+
;
52+
$resolver->setDefined('search');
53+
54+
return $this->get('groups/'.self::encodePath($group_id).'/epics', $resolver->resolve($parameters));
55+
}
56+
57+
/**
58+
* @param int|string $group_id
59+
* @param int $epic_id
60+
*
61+
* @return mixed
62+
*/
63+
public function show($group_id, int $epic_id)
64+
{
65+
return $this->get('groups/'.self::encodePath($group_id).'/epics/'.self::encodePath($epic_id));
66+
}
67+
68+
/**
69+
* @param int|string $group_id
70+
* @param array $params
71+
*
72+
* @return mixed
73+
*/
74+
public function create($group_id, array $params)
75+
{
76+
return $this->post('groups/'.self::encodePath($group_id).'/epics', $params);
77+
}
78+
79+
/**
80+
* @param int|string $group_id
81+
* @param int $epic_id
82+
* @param array $params
83+
*
84+
* @return mixed
85+
*/
86+
public function update($group_id, int $epic_id, array $params)
87+
{
88+
return $this->put('groups/'.self::encodePath($group_id).'/epics/'.self::encodePath($epic_id), $params);
89+
}
90+
91+
/**
92+
* @param int|string $group_id
93+
* @param int $epic_id
94+
*
95+
* @return mixed
96+
*/
97+
public function remove($group_id, int $epic_id)
98+
{
99+
return $this->delete('groups/'.self::encodePath($group_id).'/epics/'.self::encodePath($epic_id));
100+
}
101+
}

src/Client.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Gitlab\Api\Environments;
2020
use Gitlab\Api\Groups;
2121
use Gitlab\Api\GroupsBoards;
22+
use Gitlab\Api\GroupsEpics;
2223
use Gitlab\Api\GroupsMilestones;
2324
use Gitlab\Api\IssueBoards;
2425
use Gitlab\Api\IssueLinks;
@@ -177,6 +178,14 @@ public function groupsBoards(): GroupsBoards
177178
return new GroupsBoards($this);
178179
}
179180

181+
/**
182+
* @return GroupsEpics
183+
*/
184+
public function groupsEpics(): GroupsEpics
185+
{
186+
return new GroupsEpics($this);
187+
}
188+
180189
/**
181190
* @return GroupsMilestones
182191
*/

tests/Api/GroupsEpicsTest.php

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Gitlab API library.
7+
*
8+
* (c) Matt Humphrey <[email protected]>
9+
* (c) Graham Campbell <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Gitlab\Tests\Api;
16+
17+
use Gitlab\Api\GroupsEpics;
18+
19+
class GroupsEpicsTest extends TestCase
20+
{
21+
/**
22+
* @test
23+
*/
24+
public function shouldGetAllEpics(): void
25+
{
26+
$expectedArray = [
27+
['id' => 1, 'title' => 'A epic'],
28+
['id' => 2, 'title' => 'Another epic'],
29+
];
30+
31+
$api = $this->getApiMock();
32+
$api->expects($this->once())
33+
->method('get')
34+
->with('groups/1/epics')
35+
->will($this->returnValue($expectedArray))
36+
;
37+
38+
$this->assertEquals($expectedArray, $api->all(1));
39+
}
40+
41+
/**
42+
* @test
43+
*/
44+
public function shouldShowEpic(): void
45+
{
46+
$expectedArray = ['id' => 1, 'name' => 'A epic'];
47+
48+
$api = $this->getApiMock();
49+
$api->expects($this->once())
50+
->method('get')
51+
->with('groups/1/epics/2')
52+
->will($this->returnValue($expectedArray))
53+
;
54+
55+
$this->assertEquals($expectedArray, $api->show(1, 2));
56+
}
57+
58+
/**
59+
* @test
60+
*/
61+
public function shouldCreateEpic(): void
62+
{
63+
$expectedArray = ['id' => 3, 'title' => 'A new epic'];
64+
65+
$api = $this->getApiMock();
66+
$api->expects($this->once())
67+
->method('post')
68+
->with('groups/1/epics', ['description' => 'Some text', 'title' => 'A new epic'])
69+
->will($this->returnValue($expectedArray))
70+
;
71+
72+
$this->assertEquals($expectedArray, $api->create(1, ['description' => 'Some text', 'title' => 'A new epic']));
73+
}
74+
75+
/**
76+
* @test
77+
*/
78+
public function shouldUpdateEpic(): void
79+
{
80+
$expectedArray = ['id' => 3, 'title' => 'Updated epic'];
81+
82+
$api = $this->getApiMock();
83+
$api->expects($this->once())
84+
->method('put')
85+
->with('groups/1/epics/3', ['title' => 'Updated epic', 'description' => 'Updated description', 'state_event' => 'close'])
86+
->will($this->returnValue($expectedArray))
87+
;
88+
89+
$this->assertEquals($expectedArray, $api->update(1, 3, ['title' => 'Updated epic', 'description' => 'Updated description', 'state_event' => 'close']));
90+
}
91+
92+
/**
93+
* @test
94+
*/
95+
public function shouldRemoveEpic(): void
96+
{
97+
$expectedBool = true;
98+
99+
$api = $this->getApiMock();
100+
$api->expects($this->once())
101+
->method('delete')
102+
->with('groups/1/epics/2')
103+
->will($this->returnValue($expectedBool))
104+
;
105+
106+
$this->assertEquals($expectedBool, $api->remove(1, 2));
107+
}
108+
109+
protected function getApiClass()
110+
{
111+
return GroupsEpics::class;
112+
}
113+
}

0 commit comments

Comments
 (0)