Skip to content

Commit ebc4f25

Browse files
authored
Merge pull request #18 from codeship/SHIP-988-use-2.0-endpoints
Use 2.0 endpoints
2 parents 189dca8 + a16e96e commit ebc4f25

File tree

9 files changed

+30
-125
lines changed

9 files changed

+30
-125
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[Wiki](https://github.com/vongrippen/bitbucket/wiki) | [RDocs](http://rubydoc.info/github/vongrippen/bitbucket/master/frames)
66

7-
[ ![Codeship Status for codeship/bitbucket](https://www.codeship.io/projects/88f3e870-c528-0130-f653-22e3e5b4ad67/status?branch=master)](https://www.codeship.io/projects/4690)
7+
**Warning: not every endpoint in this project is maintained. Use at your own risk.**
88

99
A Ruby wrapper for the BitBucket REST API.
1010

bitbucket_rest_api.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ Gem::Specification.new do |gem|
3030
gem.add_development_dependency 'rake'
3131
gem.add_development_dependency 'bundler'
3232
gem.add_development_dependency 'pry-byebug'
33-
gem.add_development_dependency 'mocha'
33+
gem.add_development_dependency 'mocha', '~> 1.4.0'
3434
end

lib/bitbucket_rest_api/repos.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def get(user_name, repo_name, params={ })
204204
url = if BitBucket.options[:bitbucket_server]
205205
"/1.0/projects/#{user}/repos/#{repo.downcase}"
206206
else
207-
"/1.0/repositories/#{user}/#{repo.downcase}"
207+
"/2.0/repositories/#{user}/#{repo.downcase}"
208208
end
209209

210210
get_request(url, params)
@@ -252,7 +252,7 @@ def list(*args)
252252
'/1.0/repos'
253253
end
254254
else
255-
'/1.0/user/repositories'
255+
'/2.0/repositories'
256256
end
257257
response = get_request(url, params)
258258

lib/bitbucket_rest_api/repos/keys.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ def list(user_name_or_project_key, repo_name, params={})
1818
normalize! params
1919

2020
url = if BitBucket.options[:bitbucket_server]
21+
# Endpoint is not referenced in the docs
22+
# https://docs.atlassian.com/bitbucket-server/rest/6.0.0/bitbucket-rest.html
23+
# but has been tested
2124
"/1.0/projects/#{user_name_or_project_key}/repos/#{repo_name.downcase}/ssh"
2225
else
23-
"/1.0/repositories/#{user_name_or_project_key}/#{repo.downcase}/deploy-keys/"
26+
"/2.0/repositories/#{user_name_or_project_key}/#{repo.downcase}/deploy-keys"
2427
end
2528

2629
response = get_request(url, params)
@@ -51,9 +54,12 @@ def create(user_name_or_project_key, repo_name, params={})
5154
options = { headers: { "Content-Type" => "application/json" } }
5255

5356
url = if BitBucket.options[:bitbucket_server]
57+
# Endpoint is not referenced in the docs
58+
# https://docs.atlassian.com/bitbucket-server/rest/6.0.0/bitbucket-rest.html
59+
# but has been tested
5460
"/1.0/projects/#{user_name_or_project_key}/repos/#{repo_name.downcase}/ssh"
5561
else
56-
"/1.0/repositories/#{user_name_or_project_key}/#{repo.downcase}/deploy-keys/"
62+
"/2.0/repositories/#{user_name_or_project_key}/#{repo.downcase}/deploy-keys"
5763
end
5864

5965
post_request(url, params, options)
@@ -95,9 +101,12 @@ def delete(user_name_or_project_key, repo_name, key_id, params={})
95101
normalize! params
96102

97103
url = if BitBucket.options[:bitbucket_server]
104+
# Endpoint is not referenced in the docs
105+
# https://docs.atlassian.com/bitbucket-server/rest/6.0.0/bitbucket-rest.html
106+
# but has been tested
98107
"/1.0/projects/#{user_name_or_project_key}/repos/#{repo_name.downcase}/ssh/#{key_id}"
99108
else
100-
"/1.0/repositories/#{user_name_or_project_key}/#{repo.downcase}/deploy-keys/#{key_id}"
109+
"/2.0/repositories/#{user_name_or_project_key}/#{repo.downcase}/deploy-keys/#{key_id}"
101110
end
102111

103112
delete_request(url, params)

lib/bitbucket_rest_api/repos/services.rb

Lines changed: 0 additions & 110 deletions
This file was deleted.

lib/bitbucket_rest_api/repos/statuses.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def create(user_name, repo_name, sha, state, key, url, options = {})
3939
})
4040

4141
url = if BitBucket.options[:bitbucket_server]
42+
# Endpoint is not referenced in the docs
43+
# https://docs.atlassian.com/bitbucket-server/rest/6.0.0/bitbucket-rest.html
44+
# but has been tested
4245
"/rest/build-status/1.0/commits/#{sha}"
4346
else
4447
"/2.0/repositories/#{user}/#{sanitize_repository_name(repo)}/commit/#{sha}/statuses/build"

lib/bitbucket_rest_api/response/mashify.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
require 'faraday'
44

55
module BitBucket
6-
class Response::Mashify < Response
7-
dependency 'hashie/mash'
6+
require 'hashie/mash'
7+
class Mash < ::Hashie::Mash
8+
disable_warnings
9+
end
810

11+
class Response::Mashify < Response
912
define_parser do |body|
10-
::Hashie::Mash.new body
13+
Mash.new body
1114
end
1215

1316
def parse(body)

spec/bitbucket_rest_api/repos/keys_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
before do
77
expect(deploy_keys).to receive(:request).with(
88
:get,
9-
'/1.0/repositories/mock_username/mock_repo/deploy-keys/',
9+
'/2.0/repositories/mock_username/mock_repo/deploy-keys',
1010
{},
1111
{}
1212
).and_return(['key1', 'key2', 'key3'])
@@ -29,7 +29,7 @@
2929
before do
3030
expect(deploy_keys).to receive(:request).with(
3131
:post,
32-
'/1.0/repositories/mock_username/mock_repo/deploy-keys/',
32+
'/2.0/repositories/mock_username/mock_repo/deploy-keys',
3333
{ 'key' => 'mock_ssh_key', 'label' => 'mock_label' },
3434
{ headers: { "Content-Type" => "application/json" } }
3535
)
@@ -59,7 +59,7 @@
5959
before do
6060
expect(deploy_keys).to receive(:request).with(
6161
:delete,
62-
'/1.0/repositories/mock_username/mock_repo/deploy-keys/mock_id',
62+
'/2.0/repositories/mock_username/mock_repo/deploy-keys/mock_id',
6363
{ 'key' => 'mock_ssh_key', 'label' => 'mock_label' },
6464
{}
6565
)

spec/bitbucket_rest_api/repos_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
before do
8686
expect(repo).to receive(:request).with(
8787
:get,
88-
'/1.0/repositories/mock_username/mock_repo',
88+
'/2.0/repositories/mock_username/mock_repo',
8989
{},
9090
{}
9191
)
@@ -100,7 +100,7 @@
100100
before do
101101
expect(repo).to receive(:request).with(
102102
:get,
103-
'/1.0/user/repositories',
103+
'/2.0/repositories',
104104
{},
105105
{}
106106
).and_return(['repo1', 'repo2' ,'repo3'])

0 commit comments

Comments
 (0)