From dba7da61203595cc6d3161dcc9e1b918310b5106 Mon Sep 17 00:00:00 2001 From: cizel Date: Fri, 28 Apr 2017 15:58:13 +0800 Subject: [PATCH 1/2] Add tags API --- lib/Gitlab/Api/Tags.php | 43 +++++++++++++++ lib/Gitlab/Client.php | 5 ++ test/Gitlab/Tests/Api/TagsTest.php | 87 ++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 lib/Gitlab/Api/Tags.php create mode 100644 test/Gitlab/Tests/Api/TagsTest.php diff --git a/lib/Gitlab/Api/Tags.php b/lib/Gitlab/Api/Tags.php new file mode 100644 index 000000000..16aa64a67 --- /dev/null +++ b/lib/Gitlab/Api/Tags.php @@ -0,0 +1,43 @@ +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)); + } +} diff --git a/lib/Gitlab/Client.php b/lib/Gitlab/Client.php index 8f135f68b..5f0fd3950 100644 --- a/lib/Gitlab/Client.php +++ b/lib/Gitlab/Client.php @@ -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 { @@ -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.'"'); diff --git a/test/Gitlab/Tests/Api/TagsTest.php b/test/Gitlab/Tests/Api/TagsTest.php new file mode 100644 index 000000000..b6aaafa6f --- /dev/null +++ b/test/Gitlab/Tests/Api/TagsTest.php @@ -0,0 +1,87 @@ + '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'; + } +} From e493c4074a6a4a980ff9ca2693e4361fd289fc92 Mon Sep 17 00:00:00 2001 From: cizel Date: Sat, 29 Apr 2017 09:02:12 +0800 Subject: [PATCH 2/2] fix shouldGetOwnedProjects test --- test/Gitlab/Tests/Api/ProjectsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Gitlab/Tests/Api/ProjectsTest.php b/test/Gitlab/Tests/Api/ProjectsTest.php index 66a120ded..2d57da141 100644 --- a/test/Gitlab/Tests/Api/ProjectsTest.php +++ b/test/Gitlab/Tests/Api/ProjectsTest.php @@ -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)); }