diff --git a/lib/Gitlab/Api/Repositories.php b/lib/Gitlab/Api/Repositories.php index 85ddd2b24..3a5092634 100644 --- a/lib/Gitlab/Api/Repositories.php +++ b/lib/Gitlab/Api/Repositories.php @@ -22,7 +22,7 @@ public function branches($project_id, array $parameters = []) */ public function branch($project_id, $branch_id) { - return $this->get($this->getProjectPath($project_id, 'repository/branches/'.$this->encodeBranch($branch_id))); + return $this->get($this->getProjectPath($project_id, 'repository/branches/'.$this->encodePath($branch_id))); } /** @@ -46,7 +46,7 @@ public function createBranch($project_id, $branch, $ref) */ public function deleteBranch($project_id, $branch) { - return $this->delete($this->getProjectPath($project_id, 'repository/branches/'.$this->encodeBranch($branch))); + return $this->delete($this->getProjectPath($project_id, 'repository/branches/'.$this->encodePath($branch))); } /** @@ -58,7 +58,7 @@ public function deleteBranch($project_id, $branch) */ public function protectBranch($project_id, $branch_name, $devPush = false, $devMerge = false) { - return $this->put($this->getProjectPath($project_id, 'repository/branches/'.$this->encodeBranch($branch_name).'/protect'), array( + return $this->put($this->getProjectPath($project_id, 'repository/branches/'.$this->encodePath($branch_name).'/protect'), array( 'developers_can_push' => $devPush, 'developers_can_merge' => $devMerge )); @@ -71,7 +71,7 @@ public function protectBranch($project_id, $branch_name, $devPush = false, $devM */ public function unprotectBranch($project_id, $branch_name) { - return $this->put($this->getProjectPath($project_id, 'repository/branches/'.$this->encodeBranch($branch_name).'/unprotect')); + return $this->put($this->getProjectPath($project_id, 'repository/branches/'.$this->encodePath($branch_name).'/unprotect')); } /** @@ -111,7 +111,7 @@ public function createTag($project_id, $name, $ref, $message = null) */ public function createRelease($project_id, $tag_name, $description) { - return $this->post($this->getProjectPath($project_id, 'repository/tags/' . $this->encodeBranch($tag_name) . '/release'), array( + return $this->post($this->getProjectPath($project_id, 'repository/tags/' . $this->encodePath($tag_name) . '/release'), array( 'id' => $project_id, 'tag_name' => $tag_name, 'description' => $description @@ -127,7 +127,7 @@ public function createRelease($project_id, $tag_name, $description) */ public function updateRelease($project_id, $tag_name, $description) { - return $this->put($this->getProjectPath($project_id, 'repository/tags/' . $this->encodeBranch($tag_name) . '/release'), array( + return $this->put($this->getProjectPath($project_id, 'repository/tags/' . $this->encodePath($tag_name) . '/release'), array( 'id' => $project_id, 'tag_name' => $tag_name, 'description' => $description @@ -279,7 +279,7 @@ public function compare($project_id, $fromShaOrMaster, $toShaOrMaster) { return $this->get($this->getProjectPath( $project_id, - 'repository/compare?from='.$this->encodeBranch($fromShaOrMaster).'&to='.$this->encodeBranch($toShaOrMaster) + 'repository/compare?from='.$this->encodePath($fromShaOrMaster).'&to='.$this->encodePath($toShaOrMaster) )); } @@ -422,15 +422,4 @@ public function archive($project_id, $params = array(), $format = 'tar.gz') { return $this->get($this->getProjectPath($project_id, 'repository/archive.'.$format), $params); } - - /** - * @param string $path - * @return string - */ - protected function encodeBranch($path) - { - $path = $this->encodePath($path); - - return str_replace('%2F', '/', $path); - } } diff --git a/test/Gitlab/Tests/Api/RepositoriesTest.php b/test/Gitlab/Tests/Api/RepositoriesTest.php index a041cc59b..7020d98d0 100644 --- a/test/Gitlab/Tests/Api/RepositoriesTest.php +++ b/test/Gitlab/Tests/Api/RepositoriesTest.php @@ -68,11 +68,11 @@ public function shouldDeleteBranch() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('projects/1/repository/branches/master') + ->with('projects/1/repository/branches/feature%2FTEST-15') ->will($this->returnValue($expectedBool)) ; - $this->assertEquals($expectedBool, $api->deleteBranch(1, 'master')); + $this->assertEquals($expectedBool, $api->deleteBranch(1, 'feature/TEST-15')); } /**