Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions lib/Gitlab/Api/Tags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php namespace Gitlab\Api;

class Tags extends AbstractApi
{
/**
* @param int $project_id
* @return mixed
*/
public function all($project_id)
{
return $this->get($this->getProjectPath($project_id, 'repository/tags'));
}

/**
* @param int $project_id
* @param string $tag_name
* @return mixed
*/
public function show($project_id, $tag_name)
{
return $this->get($this->getProjectPath($project_id, 'repository/tags/'.$tag_name));
}

/**
* @param int $project_id
* @param array $params
* @return mixed
*/
public function create($project_id, array $params = array())
{
return $this->post($this->getProjectPath($project_id, "repository/tags"), $params);
}

/**
* @param int $project_id
* @param string $tag_name
* @return mixed
*/
public function remove($project_id, $tag_name)
{
return $this->delete($this->getProjectPath($project_id, 'repository/tags/'.$tag_name));
}
}
5 changes: 5 additions & 0 deletions lib/Gitlab/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @property-read \Gitlab\Api\SystemHooks $system_hooks
* @property-read \Gitlab\Api\Users $users
* @property-read \Gitlab\Api\Keys $keys
* @property-read \Gitlab\Api\Tags $tags
*/
class Client
{
Expand Down Expand Up @@ -160,6 +161,10 @@ public function api($name)
$api = new Api\Keys($this);
break;

case 'tags':
$api = new Api\Tags($this);
break;

default:
throw new InvalidArgumentException('Invalid endpoint: "'.$name.'"');

Expand Down
2 changes: 1 addition & 1 deletion test/Gitlab/Tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function shouldGetOwnedProjects()
{
$expectedArray = $this->getMultipleProjectsData();

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

$this->assertEquals($expectedArray, $api->owned(3, 50));
}
Expand Down
87 changes: 87 additions & 0 deletions test/Gitlab/Tests/Api/TagsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php namespace Gitlab\Tests\Api;

use Gitlab\Api\AbstractApi;

class TagsTest extends ApiTestCase
{
/**
* @test
*/
public function shouldGetAllTags()
{
$expectedArray = array(
array('name' => 'v1.0.0'),
array('name' => 'v1.1.0'),
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/repository/tags')
->will($this->returnValue($expectedArray));
$this->assertEquals($expectedArray, $api->all(1));
}

/**
* @test
*/
public function shouldShowTag()
{
$expectedArray = array(
array('name' => 'v1.0.0'),
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/repository/tags/v1.0.0')
->will($this->returnValue($expectedArray));
$this->assertEquals($expectedArray, $api->show(1, 'v1.0.0'));
}

/**
* @test
*/
public function shouldCreateTag()
{
$expectedArray = array(
array('name' => 'v1.1.0'),
);

$params = array(
'id' => 1,
'tag_name' => 'v1.1.0',
'ref' => 'ref/heads/master'
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('projects/1/repository/tags', $params)
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->create(1, $params));
}

/**
* @test
*/
public function shouldRemoveTag()
{
$expectedArray = array(
array('name' => 'v1.1.0'),
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('projects/1/repository/tags/v1.1.0')
->will($this->returnValue($expectedArray));
$this->assertEquals($expectedArray, $api->remove(1, 'v1.1.0'));
}

protected function getApiClass()
{
return 'Gitlab\Api\Tags';
}
}