Skip to content

Commit ee88dd0

Browse files
authored
Merge pull request #184 from cizel/master
Add tags API
2 parents 2709de9 + e493c40 commit ee88dd0

File tree

4 files changed

+136
-1
lines changed

4 files changed

+136
-1
lines changed

lib/Gitlab/Api/Tags.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php namespace Gitlab\Api;
2+
3+
class Tags extends AbstractApi
4+
{
5+
/**
6+
* @param int $project_id
7+
* @return mixed
8+
*/
9+
public function all($project_id)
10+
{
11+
return $this->get($this->getProjectPath($project_id, 'repository/tags'));
12+
}
13+
14+
/**
15+
* @param int $project_id
16+
* @param string $tag_name
17+
* @return mixed
18+
*/
19+
public function show($project_id, $tag_name)
20+
{
21+
return $this->get($this->getProjectPath($project_id, 'repository/tags/'.$tag_name));
22+
}
23+
24+
/**
25+
* @param int $project_id
26+
* @param array $params
27+
* @return mixed
28+
*/
29+
public function create($project_id, array $params = array())
30+
{
31+
return $this->post($this->getProjectPath($project_id, "repository/tags"), $params);
32+
}
33+
34+
/**
35+
* @param int $project_id
36+
* @param string $tag_name
37+
* @return mixed
38+
*/
39+
public function remove($project_id, $tag_name)
40+
{
41+
return $this->delete($this->getProjectPath($project_id, 'repository/tags/'.$tag_name));
42+
}
43+
}

lib/Gitlab/Client.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* @property-read \Gitlab\Api\SystemHooks $system_hooks
3232
* @property-read \Gitlab\Api\Users $users
3333
* @property-read \Gitlab\Api\Keys $keys
34+
* @property-read \Gitlab\Api\Tags $tags
3435
*/
3536
class Client
3637
{
@@ -160,6 +161,10 @@ public function api($name)
160161
$api = new Api\Keys($this);
161162
break;
162163

164+
case 'tags':
165+
$api = new Api\Tags($this);
166+
break;
167+
163168
default:
164169
throw new InvalidArgumentException('Invalid endpoint: "'.$name.'"');
165170

test/Gitlab/Tests/Api/ProjectsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function shouldGetOwnedProjects()
6565
{
6666
$expectedArray = $this->getMultipleProjectsData();
6767

68-
$api = $this->getMultipleProjectsRequestMock('projects/owned', $expectedArray, 3, 50);
68+
$api = $this->getMultipleProjectsRequestMock('projects?owned=1', $expectedArray, 3, 50);
6969

7070
$this->assertEquals($expectedArray, $api->owned(3, 50));
7171
}

test/Gitlab/Tests/Api/TagsTest.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php namespace Gitlab\Tests\Api;
2+
3+
use Gitlab\Api\AbstractApi;
4+
5+
class TagsTest extends ApiTestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function shouldGetAllTags()
11+
{
12+
$expectedArray = array(
13+
array('name' => 'v1.0.0'),
14+
array('name' => 'v1.1.0'),
15+
);
16+
17+
$api = $this->getApiMock();
18+
$api->expects($this->once())
19+
->method('get')
20+
->with('projects/1/repository/tags')
21+
->will($this->returnValue($expectedArray));
22+
$this->assertEquals($expectedArray, $api->all(1));
23+
}
24+
25+
/**
26+
* @test
27+
*/
28+
public function shouldShowTag()
29+
{
30+
$expectedArray = array(
31+
array('name' => 'v1.0.0'),
32+
);
33+
34+
$api = $this->getApiMock();
35+
$api->expects($this->once())
36+
->method('get')
37+
->with('projects/1/repository/tags/v1.0.0')
38+
->will($this->returnValue($expectedArray));
39+
$this->assertEquals($expectedArray, $api->show(1, 'v1.0.0'));
40+
}
41+
42+
/**
43+
* @test
44+
*/
45+
public function shouldCreateTag()
46+
{
47+
$expectedArray = array(
48+
array('name' => 'v1.1.0'),
49+
);
50+
51+
$params = array(
52+
'id' => 1,
53+
'tag_name' => 'v1.1.0',
54+
'ref' => 'ref/heads/master'
55+
);
56+
57+
$api = $this->getApiMock();
58+
$api->expects($this->once())
59+
->method('post')
60+
->with('projects/1/repository/tags', $params)
61+
->will($this->returnValue($expectedArray));
62+
63+
$this->assertEquals($expectedArray, $api->create(1, $params));
64+
}
65+
66+
/**
67+
* @test
68+
*/
69+
public function shouldRemoveTag()
70+
{
71+
$expectedArray = array(
72+
array('name' => 'v1.1.0'),
73+
);
74+
75+
$api = $this->getApiMock();
76+
$api->expects($this->once())
77+
->method('delete')
78+
->with('projects/1/repository/tags/v1.1.0')
79+
->will($this->returnValue($expectedArray));
80+
$this->assertEquals($expectedArray, $api->remove(1, 'v1.1.0'));
81+
}
82+
83+
protected function getApiClass()
84+
{
85+
return 'Gitlab\Api\Tags';
86+
}
87+
}

0 commit comments

Comments
 (0)