diff options
author | Stan Hu <stanhu@gmail.com> | 2018-07-14 01:39:24 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-07-14 01:39:24 +0300 |
commit | c793252e8b33a1b7d071aca90c9c05e54ad973b5 (patch) | |
tree | 238d0c479817abd68c23212e44d6484d27f9bb04 /lib | |
parent | ec4109d413f6161b43ad4cc1a6251af30d3bcf03 (diff) |
Add support for deleting branches via the Bitbucket Server API
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bitbucket_server/client.rb | 9 | ||||
-rw-r--r-- | lib/bitbucket_server/connection.rb | 27 |
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/bitbucket_server/client.rb b/lib/bitbucket_server/client.rb index 802fe7953ce..bfa8301f643 100644 --- a/lib/bitbucket_server/client.rb +++ b/lib/bitbucket_server/client.rb @@ -36,6 +36,15 @@ module BitbucketServer connection.post("/projects/#{project_key}/repos/#{repo}/branches", payload.to_json) end + def delete_branch(project_key, repo, branch_name, sha) + payload = { + name: Gitlab::Git::BRANCH_REF_PREFIX + branch_name, + dryRun: false + } + + connection.delete(:branches, "/projects/#{project_key}/repos/#{repo}/branches", payload.to_json) + end + private def get_collection(path, type) diff --git a/lib/bitbucket_server/connection.rb b/lib/bitbucket_server/connection.rb index 853d09b776a..0b65203a824 100644 --- a/lib/bitbucket_server/connection.rb +++ b/lib/bitbucket_server/connection.rb @@ -36,10 +36,27 @@ module BitbucketServer response.parsed_response end + # We need to support two different APIs for deletion: + # + # /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/branches/default + # /rest/branch-utils/1.0/projects/{projectKey}/repos/{repositorySlug}/branches + def delete(resource, path, body) + url = delete_url(resource, path) + + response = Gitlab::HTTP.delete(url, + basic_auth: auth, + headers: post_headers, + body: body) + + check_errors!(response) + + response.parsed_response + end + private def check_errors!(response) - return if response.code == 200 + return if response.code >= 200 && response.code < 300 details = if response.parsed_response && response.parsed_response.is_a?(Hash) @@ -68,5 +85,13 @@ module BitbucketServer def root_url "#{base_uri}/rest/api/#{api_version}" end + + def delete_url(resource, path) + if resource == :branches + "#{base_uri}/branch-utils/#{api_version}#{path}" + else + build_url(path) + end + end end end |