Skip to content

Commit 4d99286

Browse files
authored
Merge pull request #16 from codeship/feature/support-commit-status-for-server
Add suport for commit status updates on the server version
2 parents c18d45b + 5ea6370 commit 4d99286

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

lib/bitbucket_rest_api/repos/statuses.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ def create(user_name, repo_name, sha, state, key, url, options = {})
3838
"url" => url
3939
})
4040

41+
url = if BitBucket.options[:bitbucket_server]
42+
"/rest/build-status/1.0/commits/#{sha}"
43+
else
44+
"/2.0/repositories/#{user}/#{sanitize_repository_name(repo)}/commit/#{sha}/statuses/build"
45+
end
46+
4147
faraday_options = { headers: { "Content-Type" => "application/json" } }
42-
post_request("/2.0/repositories/#{user}/#{sanitize_repository_name(repo)}/commit/#{sha}/statuses/build",
43-
build_options,
44-
faraday_options)
48+
post_request(url, build_options, faraday_options)
4549
end
4650
end # Repos::Statuses
4751
end # BitBucket

lib/bitbucket_rest_api/request.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def request(method, path, params, options={})
5252

5353
response = retry_token_refresh_errors do
5454
conn = connection(options)
55-
path_prefix = (path.include?('/ssh') && BitBucket.options[:bitbucket_server]) ? '/rest/keys' : conn.path_prefix
56-
path = (path_prefix + path).gsub(/\/\//,'/') if conn.path_prefix != '/'
55+
prefix = path_prefix(path, conn)
56+
path = (prefix + path).gsub(/\/\//,'/') if conn.path_prefix != '/'
5757

5858
response = conn.send(method) do |request|
5959
request['Authorization'] = "Bearer #{new_access_token}" unless new_access_token.nil?
@@ -77,6 +77,16 @@ def request(method, path, params, options={})
7777

7878
private
7979

80+
def path_prefix(path, conn)
81+
if path.include?('/ssh') && BitBucket.options[:bitbucket_server]
82+
'/rest/keys'
83+
elsif path.include?('/build-status') && BitBucket.options[:bitbucket_server]
84+
''
85+
else
86+
conn.path_prefix
87+
end
88+
end
89+
8090
# def extract_data_from_params(params) # :nodoc:
8191
# if params.has_key?('data') and !params['data'].nil?
8292
# params['data']

0 commit comments

Comments
 (0)