bitbucket_rest_api2 0.9.1 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -12
  3. data/lib/bitbucket_rest_api/api.rb +1 -6
  4. data/lib/bitbucket_rest_api/api_factory.rb +0 -1
  5. data/lib/bitbucket_rest_api/configuration.rb +7 -1
  6. data/lib/bitbucket_rest_api/connection.rb +7 -4
  7. data/lib/bitbucket_rest_api/error/refresh_token.rb +12 -0
  8. data/lib/bitbucket_rest_api/error.rb +1 -0
  9. data/lib/bitbucket_rest_api/helpers/repository_helper.rb +13 -0
  10. data/lib/bitbucket_rest_api/invitations.rb +1 -1
  11. data/lib/bitbucket_rest_api/issues/comments.rb +5 -5
  12. data/lib/bitbucket_rest_api/issues/components.rb +5 -5
  13. data/lib/bitbucket_rest_api/issues/milestones.rb +5 -5
  14. data/lib/bitbucket_rest_api/issues.rb +5 -5
  15. data/lib/bitbucket_rest_api/repos/changesets.rb +2 -2
  16. data/lib/bitbucket_rest_api/repos/commits.rb +8 -2
  17. data/lib/bitbucket_rest_api/repos/following.rb +2 -2
  18. data/lib/bitbucket_rest_api/repos/forks.rb +1 -1
  19. data/lib/bitbucket_rest_api/repos/keys.rb +32 -12
  20. data/lib/bitbucket_rest_api/repos/pull_request.rb +1 -1
  21. data/lib/bitbucket_rest_api/repos/services.rb +14 -7
  22. data/lib/bitbucket_rest_api/repos/sources.rb +2 -2
  23. data/lib/bitbucket_rest_api/repos/statuses.rb +51 -0
  24. data/lib/bitbucket_rest_api/repos/webhooks.rb +35 -16
  25. data/lib/bitbucket_rest_api/repos.rb +35 -12
  26. data/lib/bitbucket_rest_api/request.rb +43 -15
  27. data/lib/bitbucket_rest_api/response/raise_error.rb +5 -0
  28. data/lib/bitbucket_rest_api/user.rb +7 -7
  29. data/lib/bitbucket_rest_api/users/account.rb +8 -8
  30. data/lib/bitbucket_rest_api/version.rb +1 -1
  31. data/lib/bitbucket_rest_api.rb +1 -25
  32. data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +1 -1
  33. data/spec/bitbucket_rest_api/helpers/repository_helper_spec.rb +30 -0
  34. data/spec/bitbucket_rest_api/invitations_spec.rb +1 -1
  35. data/spec/bitbucket_rest_api/issues/comments_spec.rb +5 -5
  36. data/spec/bitbucket_rest_api/issues/components_spec.rb +5 -5
  37. data/spec/bitbucket_rest_api/issues/milestones_spec.rb +5 -5
  38. data/spec/bitbucket_rest_api/issues_spec.rb +5 -5
  39. data/spec/bitbucket_rest_api/repos/changesets_spec.rb +2 -2
  40. data/spec/bitbucket_rest_api/repos/following_spec.rb +2 -2
  41. data/spec/bitbucket_rest_api/repos/forks_spec.rb +1 -1
  42. data/spec/bitbucket_rest_api/repos/keys_spec.rb +5 -5
  43. data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +1 -1
  44. data/spec/bitbucket_rest_api/repos/sources_spec.rb +3 -3
  45. data/spec/bitbucket_rest_api/repos/statuses_spec.rb +48 -0
  46. data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +3 -3
  47. data/spec/bitbucket_rest_api/repos_spec.rb +7 -7
  48. data/spec/bitbucket_rest_api/request_spec.rb +11 -11
  49. data/spec/bitbucket_rest_api/user_spec.rb +8 -8
  50. metadata +11 -8
  51. data/lib/bitbucket_rest_api/response/helpers.rb +0 -21
  52. data/lib/bitbucket_rest_api/result.rb +0 -140
@@ -14,7 +14,7 @@ module BitBucket
14
14
  _validate_user_repo_params(user, repo) unless user? && repo?
15
15
  _validate_presence_of(sha, path)
16
16
 
17
- get_request("/2.0/repositories/#{user}/#{repo.downcase}/src/#{sha}/#{path}")
17
+ get_request("/1.0/repositories/#{user}/#{repo.downcase}/src/#{sha}/#{path}")
18
18
  end
19
19
  alias :all :list
20
20
 
@@ -31,7 +31,7 @@ module BitBucket
31
31
  _validate_user_repo_params(user, repo) unless user? && repo?
32
32
  _validate_presence_of(sha, path)
33
33
 
34
- get_request("/2.0/repositories/#{user}/#{repo.downcase}/raw/#{sha}/#{path}")
34
+ get_request("/1.0/repositories/#{user}/#{repo.downcase}/raw/#{sha}/#{path}")
35
35
  end
36
36
  alias :find :get
37
37
 
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ class Repos::Statuses < API
5
+
6
+ # Add build status to commit
7
+ #
8
+ # = Parameters
9
+ # <tt>:user_name</tt> - Required string. The account of the repository owner.
10
+ # <tt>:repo_name</tt> - Required string. The repository name.
11
+ # <tt>:sha</tt> - Requrired string. The SHA1 value for the commit where you want to add the build status.
12
+ # <tt>:state</tt> - Required String. An indication of the status of the commit: (INPROGRESS, SUCCESSFUL, or FAILED)
13
+ # <tt>:key</tt> - Required String. A key that the vendor or build system supplies to identify the submitted build status.
14
+ # <tt>:url</tt> - Required String. The URL for the vendor or system that produces the build.
15
+ # <tt>:options</tt> Optional hash. Containing the following optional parameters:
16
+ # * <tt>description</tt> - A user-defined description of the build. For example, 4 out of 128 tests passed.
17
+ # * <tt>name<tt> - The name of the build. Your build system may provide the name, which will also appear in Bitbucket. For example, Unit Tests.
18
+ #
19
+ # = Examples
20
+ # bitbucket = BitBucket.new
21
+ # bitbucket.repos.create_status(client.repos.statuses.create('homer',
22
+ # 'monorail',
23
+ # 'e14caad7c501e0ae52daef24b26aa2625b7534e6',
24
+ # 'SUCCESSFUL',
25
+ # 'BAMBOO-PROJECT-X',
26
+ # 'https://example.com/path/to/build/info',
27
+ # 'name' => 'this is covered by build_concurrency_spec',
28
+ # 'description' => 'Changes by John Doe')
29
+ #
30
+ def create(user_name, repo_name, sha, state, key, url, options = {})
31
+ _update_user_repo_params(user_name, repo_name)
32
+ _validate_user_repo_params(user, repo) unless user? && repo?
33
+ _validate_presence_of(sha, state, key, url)
34
+
35
+ build_options = options.merge({
36
+ "state" => state,
37
+ "key" => key,
38
+ "url" => url
39
+ })
40
+
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
+
47
+ faraday_options = { headers: { "Content-Type" => "application/json" } }
48
+ post_request(url, build_options, faraday_options)
49
+ end
50
+ end # Repos::Statuses
51
+ end # BitBucket
@@ -17,11 +17,12 @@ module BitBucket
17
17
  'pullrequest:rejected',
18
18
  'pullrequest:comment_created',
19
19
  'pullrequest:comment_updated',
20
- 'pullrequest:comment_deleted'
20
+ 'pullrequest:comment_deleted',
21
+ 'repo:refs_changed'
21
22
  ]
22
23
 
23
- def create(user_name, repo_name, params = {})
24
- _update_user_repo_params(user_name, repo_name)
24
+ def create(user_name_or_project_key, repo_name, params = {})
25
+ _update_user_repo_params(user_name_or_project_key, repo_name)
25
26
  _validate_user_repo_params(user, repo) unless user? && repo?
26
27
  normalize! params
27
28
  assert_required_keys(%w[description url active events], params)
@@ -33,23 +34,35 @@ module BitBucket
33
34
  'active',
34
35
  'events'
35
36
  )
37
+ options = { headers: { "Content-Type" => "application/json" } }
38
+ url = if BitBucket.options[:bitbucket_server]
39
+ "/1.0/projects/#{user_name_or_project_key}/repos/#{repo_name}/webhooks"
40
+ else
41
+ "/2.0/repositories/#{user_name_or_project_key}/#{repo_name}/hooks"
42
+ end
36
43
 
37
- post_request("/2.0/repositories/#{user_name}/#{repo_name}/hooks", params)
44
+ post_request(url, params, options)
38
45
  end
39
46
 
40
- def list(user_name, repo_name)
41
- _update_user_repo_params(user_name, repo_name)
47
+ def list(user_name_or_project_key, repo_name)
48
+ _update_user_repo_params(user_name_or_project_key, repo_name)
42
49
  _validate_user_repo_params(user, repo) unless user? && repo?
43
50
 
44
- get_request("/2.0/repositories/#{user_name}/#{repo_name}/hooks")
51
+ url = if BitBucket.options[:bitbucket_server]
52
+ "/1.0/projects/#{user_name_or_project_key}/repos/#{repo_name}/webhooks"
53
+ else
54
+ "/2.0/repositories/#{user_name_or_project_key}/#{repo_name}/hooks?pagelen=100"
55
+ end
56
+
57
+ get_request(url)
45
58
  end
46
59
 
47
- def get(user_name, repo_name, hook_uuid)
48
- _update_user_repo_params(user_name, repo_name)
60
+ def get(user_name_or_project_key, repo_name, hook_uuid)
61
+ _update_user_repo_params(user_name_or_project_key, repo_name)
49
62
  _validate_user_repo_params(user, repo) unless user? && repo?
50
63
 
51
64
  get_request(
52
- "/2.0/repositories/#{user_name}/#{repo_name}/hooks/#{hook_uuid}"
65
+ "/2.0/repositories/#{user_name_or_project_key}/#{repo_name}/hooks/#{hook_uuid}"
53
66
  )
54
67
  end
55
68
 
@@ -67,19 +80,25 @@ module BitBucket
67
80
  'events'
68
81
  )
69
82
 
83
+ options = { headers: { "Content-Type" => "application/json" } }
70
84
  put_request(
71
85
  "/2.0/repositories/#{user_name}/#{repo_name}/hooks/#{hook_uuid}",
72
- params
86
+ params,
87
+ options
73
88
  )
74
89
  end
75
90
 
76
- def delete(user_name, repo_name, hook_uuid)
77
- _update_user_repo_params(user_name, repo_name)
91
+ def delete(user_name_or_project_key, repo_name, hook_uuid)
92
+ _update_user_repo_params(user_name_or_project_key, repo_name)
78
93
  _validate_user_repo_params(user, repo) unless user? && repo?
79
94
 
80
- delete_request(
81
- "/2.0/repositories/#{user_name}/#{repo_name}/hooks/#{hook_uuid}"
82
- )
95
+ url = if BitBucket.options[:bitbucket_server]
96
+ "/1.0/projects/#{user_name_or_project_key}/repos/#{repo_name}/webhooks/#{hook_uuid}"
97
+ else
98
+ "/2.0/repositories/#{user_name_or_project_key}/#{repo_name}/hooks/#{hook_uuid}"
99
+ end
100
+
101
+ delete_request(url)
83
102
  end
84
103
 
85
104
  private
@@ -11,6 +11,7 @@ module BitBucket
11
11
  :Services => 'services',
12
12
  :Following => 'following',
13
13
  :Sources => 'sources',
14
+ :Statuses => 'statuses',
14
15
  :Forks => 'forks',
15
16
  :Commits => 'commits',
16
17
  :Download => 'download',
@@ -69,16 +70,27 @@ module BitBucket
69
70
  def services
70
71
  @services ||= ApiFactory.new 'Repos::Services'
71
72
  end
73
+
74
+ def statuses
75
+ @statuses ||= ApiFactory.new 'Repos::Statuses'
76
+ end
77
+
72
78
  def forks
73
79
  @forks ||= ApiFactory.new 'Repos::Forks'
74
80
  end
81
+
75
82
  def commits
76
83
  @commits ||=ApiFactory.new 'Repos::Commits'
77
84
  end
85
+
78
86
  def download
79
87
  @download ||=ApiFactory.new "Repos::Download"
80
88
  end
81
89
 
90
+ def webhooks
91
+ @webhooks ||= ApiFactory.new 'Repos::Webhooks'
92
+ end
93
+
82
94
  # Access to Repos::PullRequests API
83
95
  def pull_request
84
96
  @pull_request ||= ApiFactory.new 'Repos::PullRequest'
@@ -103,7 +115,7 @@ module BitBucket
103
115
  _validate_user_repo_params(user, repo) unless (user? && repo?)
104
116
  normalize! params
105
117
 
106
- response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/branches/", params)
118
+ response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/branches/", params)
107
119
  return response unless block_given?
108
120
  response.each { |el| yield el }
109
121
  end
@@ -145,7 +157,7 @@ module BitBucket
145
157
  assert_required_keys(%w[ name ], params)
146
158
 
147
159
  # Requires authenticated user
148
- post_request("/2.0/repositories/", DEFAULT_REPO_OPTIONS.merge(params))
160
+ post_request("/1.0/repositories/", DEFAULT_REPO_OPTIONS.merge(params))
149
161
  end
150
162
 
151
163
  # Edit a repository
@@ -175,7 +187,7 @@ module BitBucket
175
187
  normalize! params
176
188
  filter! VALID_REPO_OPTIONS, params
177
189
 
178
- put_request("/2.0/repositories/#{user}/#{repo.downcase}/", DEFAULT_REPO_OPTIONS.merge(params))
190
+ put_request("/1.0/repositories/#{user}/#{repo.downcase}/", DEFAULT_REPO_OPTIONS.merge(params))
179
191
  end
180
192
 
181
193
  # Get a repository
@@ -189,7 +201,13 @@ module BitBucket
189
201
  _validate_user_repo_params(user, repo) unless user? && repo?
190
202
  normalize! params
191
203
 
192
- get_request("/2.0/repositories/#{user}/#{repo.downcase}", params)
204
+ url = if BitBucket.options[:bitbucket_server]
205
+ "/1.0/projects/#{user}/repos/#{repo.downcase}"
206
+ else
207
+ "/1.0/repositories/#{user}/#{repo.downcase}"
208
+ end
209
+
210
+ get_request(url, params)
193
211
  end
194
212
 
195
213
  alias :find :get
@@ -205,7 +223,7 @@ module BitBucket
205
223
  _update_user_repo_params(user_name, repo_name)
206
224
  _validate_user_repo_params(user, repo) unless user? && repo?
207
225
 
208
- delete_request("/2.0/repositories/#{user}/#{repo.downcase}")
226
+ delete_request("/1.0/repositories/#{user}/#{repo.downcase}")
209
227
  end
210
228
 
211
229
  # List repositories for the authenticated user
@@ -227,12 +245,17 @@ module BitBucket
227
245
  _merge_user_into_params!(params) unless params.has_key?('user')
228
246
  filter! %w[ user type ], params
229
247
 
230
- response = #if (user_name = params.delete("user"))
231
- # get_request("/2.0/users/#{user_name}", params)
232
- #else
233
- # For authenticated user
234
- get_request("/2.0/repositories", params)
235
- #end
248
+ url = if BitBucket.options[:bitbucket_server]
249
+ if params.has_key?('user')
250
+ "/1.0/users/#{params['user']}/repos"
251
+ else
252
+ '/1.0/repos'
253
+ end
254
+ else
255
+ '/1.0/user/repositories'
256
+ end
257
+ response = get_request(url, params)
258
+
236
259
  return response unless block_given?
237
260
  response.each { |el| yield el }
238
261
  end
@@ -251,7 +274,7 @@ module BitBucket
251
274
  _validate_user_repo_params(user, repo) unless user? && repo?
252
275
  normalize! params
253
276
 
254
- response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/tags/", params)
277
+ response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/tags/", params)
255
278
  return response unless block_given?
256
279
  response.each { |el| yield el }
257
280
  end
@@ -28,6 +28,20 @@ module BitBucket
28
28
  request(:delete, path, params, options)
29
29
  end
30
30
 
31
+ def retry_token_refresh_errors
32
+ count = 0
33
+ begin
34
+ yield
35
+ rescue BitBucket::Error::RefreshToken
36
+ count += 1
37
+ if count <= 3
38
+ sleep 0.3 * count
39
+ retry
40
+ end
41
+ raise
42
+ end
43
+ end
44
+
31
45
  def request(method, path, params, options={})
32
46
  if !METHODS.include?(method)
33
47
  raise ArgumentError, "unkown http method: #{method}"
@@ -36,29 +50,43 @@ module BitBucket
36
50
 
37
51
  puts "EXECUTED: #{method} - #{path} with #{params} and #{options}" if ENV['DEBUG']
38
52
 
39
- conn = connection(options)
40
- path = (conn.path_prefix + path).gsub(/\/\//,'/') if conn.path_prefix != '/'
41
-
42
- response = conn.send(method) do |request|
43
- request['Authorization'] = "Bearer #{new_access_token}" unless new_access_token.nil?
44
- case method.to_sym
45
- when *(METHODS - METHODS_WITH_BODIES)
46
- request.body = params.delete('data') if params.has_key?('data')
47
- request.url(path, params)
48
- when *METHODS_WITH_BODIES
49
- request.path = path
50
- unless params.empty?
51
- # data = extract_data_from_params(params)
52
- # request.body = MultiJson.dump(data)
53
- request.body = MultiJson.dump(params)
53
+ response = retry_token_refresh_errors do
54
+ conn = connection(options)
55
+ prefix = path_prefix(path, conn)
56
+ path = (prefix + path).gsub(/\/\//,'/') if conn.path_prefix != '/'
57
+
58
+ response = conn.send(method) do |request|
59
+ request['Authorization'] = "Bearer #{new_access_token}" unless new_access_token.nil?
60
+ case method.to_sym
61
+ when *(METHODS - METHODS_WITH_BODIES)
62
+ request.body = params.delete('data') if params.has_key?('data')
63
+ request.url(path, params)
64
+ when *METHODS_WITH_BODIES
65
+ request.path = path
66
+ unless params.empty?
67
+ # data = extract_data_from_params(params)
68
+ # request.body = MultiJson.dump(data)
69
+ request.body = MultiJson.dump(params)
70
+ end
54
71
  end
55
72
  end
56
73
  end
74
+
57
75
  response.body
58
76
  end
59
77
 
60
78
  private
61
79
 
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
+
62
90
  # def extract_data_from_params(params) # :nodoc:
63
91
  # if params.has_key?('data') and !params['data'].nil?
64
92
  # params['data']
@@ -3,6 +3,8 @@
3
3
  require 'faraday'
4
4
  require 'bitbucket_rest_api/error'
5
5
 
6
+ REFRESH_TOKEN = %r{Access token expired. Use your refresh token to obtain a new access token.}
7
+
6
8
  module BitBucket
7
9
  class Response::RaiseError < Faraday::Response::Middleware
8
10
 
@@ -11,6 +13,9 @@ module BitBucket
11
13
  when 400
12
14
  raise BitBucket::Error::BadRequest.new(env)
13
15
  when 401
16
+ if env[:body] =~ REFRESH_TOKEN
17
+ raise BitBucket::Error::RefreshToken.new(env)
18
+ end
14
19
  raise BitBucket::Error::Unauthorized.new(env)
15
20
  when 403
16
21
  raise BitBucket::Error::Forbidden.new(env)
@@ -26,7 +26,7 @@ module BitBucket
26
26
  # bitbucket.user_api.profile
27
27
  #
28
28
  def profile
29
- get_request("/2.0/user")
29
+ get_request("/1.0/user")
30
30
  end
31
31
 
32
32
 
@@ -48,14 +48,14 @@ module BitBucket
48
48
  normalize! params
49
49
  filter! DEFAULT_USER_OPTIONS, params
50
50
 
51
- put_request("/2.0/user", DEFAULT_USER_OPTIONS.merge(params))
51
+ put_request("/1.0/user", DEFAULT_USER_OPTIONS.merge(params))
52
52
 
53
53
  end
54
54
 
55
55
 
56
56
  # GET a list of user privileges
57
57
  def privileges
58
- get_request("/2.0/user/privileges")
58
+ get_request("/1.0/user/privileges")
59
59
  end
60
60
 
61
61
 
@@ -66,7 +66,7 @@ module BitBucket
66
66
  # if the repository is a fork of another repository.
67
67
  # An account always "follows" its own repositories.
68
68
  def follows
69
- get_request("/2.0/user/follows")
69
+ get_request("/1.0/user/follows")
70
70
  end
71
71
 
72
72
 
@@ -75,7 +75,7 @@ module BitBucket
75
75
  # or has at least read access to.
76
76
  # Use this if you're looking for a full list of all of the repositories associated with a user.
77
77
  def repositories
78
- get_request("/2.0/repositories/#{self.user}")
78
+ get_request("/1.0/user/repositories")
79
79
  end
80
80
 
81
81
  alias :repos :repositories
@@ -86,7 +86,7 @@ module BitBucket
86
86
  # Gets a list of the repositories the account follows.
87
87
  # This is the same list that appears on the Following tab on your account dashboard.
88
88
  def overview
89
- get_request("/2.0/repositories/overview")
89
+ get_request("/1.0/user/repositories/overview")
90
90
  end
91
91
 
92
92
 
@@ -94,7 +94,7 @@ module BitBucket
94
94
  # GET the list of repositories on the dashboard
95
95
  # Gets the repositories list from the account's dashboard.
96
96
  def dashboard
97
- get_request("/2.0/repositories/dashboard")
97
+ get_request("/1.0/user/repositories/dashboard")
98
98
  end
99
99
 
100
100
  end # User
@@ -11,43 +11,43 @@ module BitBucket
11
11
  # GET the account profile
12
12
  #
13
13
  def profile(accountname)
14
- response = get_request("/2.0/users/#{accountname}")
14
+ response = get_request("/1.0/users/#{accountname}")
15
15
  end
16
16
 
17
17
  # GET the account plan
18
18
  def plan(accountname)
19
- response = get_request("/2.0/users/#{accountname}/plan")
19
+ response = get_request("/1.0/users/#{accountname}/plan")
20
20
  end
21
21
 
22
22
  # GET the emails
23
23
  def emails(accountname)
24
- response = get_request("/2.0/users/#{accountname}/emails")
24
+ response = get_request("/1.0/users/#{accountname}/emails")
25
25
  end
26
26
 
27
27
  # GET the followers
28
28
  def followers(accountname)
29
- response = get_request("/2.0/users/#{accountname}/followers")
29
+ response = get_request("/1.0/users/#{accountname}/followers")
30
30
  end
31
31
 
32
32
  # GET the events
33
33
  def events(accountname)
34
- response = get_request("/2.0/users/#{accountname}/events")
34
+ response = get_request("/1.0/users/#{accountname}/events")
35
35
  end
36
36
 
37
37
  #GET the keys
38
38
  def keys(accountname)
39
- response = get_request("/2.0/users/#{accountname}/ssh-keys")
39
+ response = get_request("/1.0/users/#{accountname}/ssh-keys")
40
40
  end
41
41
 
42
42
  #POST a new key
43
43
  # params should be in format {key: "", label:""}
44
44
  def new_key(accountname, params)
45
- response = post_request("/2.0/users/#{accountname}/ssh-keys/", params)
45
+ response = post_request("/1.0/users/#{accountname}/ssh-keys/", params)
46
46
  end
47
47
 
48
48
  #DELETE a key
49
49
  def delete_key(accountname, key_id)
50
- response = delete_request("/2.0/users/#{accountname}/ssh-keys/#{key_id}")
50
+ response = delete_request("/1.0/users/#{accountname}/ssh-keys/#{key_id}")
51
51
  end
52
52
  end # Users::Account
53
53
  end # BitBucket
@@ -4,7 +4,7 @@ module BitBucket
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 9
7
- PATCH = 1
7
+ PATCH = 5
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
10
10
  end
@@ -6,35 +6,11 @@ require 'bitbucket_rest_api/constants'
6
6
  require 'bitbucket_rest_api/utils/url'
7
7
  require 'bitbucket_rest_api/connection'
8
8
  require 'bitbucket_rest_api/deprecation'
9
+ require 'bitbucket_rest_api/helpers/repository_helper'
9
10
 
10
11
  module BitBucket
11
12
  extend Configuration
12
13
 
13
- class << self
14
-
15
- # Handle for the client instance
16
- attr_accessor :api_client
17
-
18
- # Alias for BitBucket::Client.new
19
- #
20
- # @return [BitBucket::Client]
21
- def new(options = { }, &block)
22
- @api_client = BitBucket::Client.new(options, &block)
23
- end
24
-
25
- # Delegate to BitBucket::Client
26
- #
27
- def method_missing(method, *args, &block)
28
- return super unless new.respond_to?(method)
29
- new.send(method, *args, &block)
30
- end
31
-
32
- def respond_to?(method, include_private = false)
33
- new.respond_to?(method, include_private) || super(method, include_private)
34
- end
35
-
36
- end
37
-
38
14
  module AutoloadHelper
39
15
 
40
16
  def autoload_all(prefix, options)
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  describe Hash do
6
6
 
7
7
  before do
8
- BitBucket.new
8
+ BitBucket::Client.new
9
9
  @hash = { :a => 1, :b => 2, :c => 'e'}
10
10
  @serialized = "a=1&b=2&c=e"
11
11
  @nested_hash = { 'a' => { 'b' => {'c' => 1 } } }
@@ -0,0 +1,30 @@
1
+ # encoding: UTF-8
2
+ require 'bitbucket_rest_api'
3
+
4
+ describe "RepositoryHelper" do
5
+ context "#sanitize_repository_name" do
6
+ include BitBucket::Helpers::RepositoryHelper
7
+
8
+ it "filters special characters" do
9
+ expect(sanitize_repository_name("Funnü ChAraxt%")).to eq("funn-charaxt")
10
+ end
11
+
12
+ it "filters special characters" do
13
+ expect(sanitize_repository_name(nil)).to eq(nil)
14
+ end
15
+
16
+ it "replaces slashes by dashes" do
17
+ expect(sanitize_repository_name("my/repo")).to eq("my-repo")
18
+ end
19
+
20
+ it "doesn't put more than one dash in a row" do
21
+ expect(sanitize_repository_name("my - repo")).to eq("my-repo")
22
+ end
23
+
24
+ it "does not change a valid repo name" do
25
+ ["bit.bucket", "bitbucket", "bit-bucket", "bit_bucket"].each do |repo_name|
26
+ expect(sanitize_repository_name(repo_name)).to eq(repo_name)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -7,7 +7,7 @@ describe BitBucket::Invitations do
7
7
  before do
8
8
  expect(subject).to receive(:request).with(
9
9
  :post,
10
- "/2.0/invitations/mock_username/mock_repo/mock_email_address",
10
+ "/1.0/invitations/mock_username/mock_repo/mock_email_address",
11
11
  { :permission => 'read' },
12
12
  {}
13
13
  )
@@ -7,7 +7,7 @@ describe BitBucket::Issues::Comments do
7
7
  before do
8
8
  expect(comments).to receive(:request).with(
9
9
  :get,
10
- '/2.0/repositories/mock_username/mock_repo/issues/mock_issue_id/comments/',
10
+ '/1.0/repositories/mock_username/mock_repo/issues/mock_issue_id/comments/',
11
11
  {},
12
12
  {}
13
13
  ).and_return(['comment1', 'comment2', 'comment3'])
@@ -30,7 +30,7 @@ describe BitBucket::Issues::Comments do
30
30
  before do
31
31
  expect(comments).to receive(:request).with(
32
32
  :get,
33
- '/2.0/repositories/mock_username/mock_repo/issues/comments/mock_comment_id',
33
+ '/1.0/repositories/mock_username/mock_repo/issues/comments/mock_comment_id',
34
34
  {},
35
35
  {}
36
36
  )
@@ -45,7 +45,7 @@ describe BitBucket::Issues::Comments do
45
45
  before do
46
46
  expect(comments).to receive(:request).with(
47
47
  :post,
48
- '/2.0/repositories/mock_username/mock_repo/issues/mock_issue_id/comments/',
48
+ '/1.0/repositories/mock_username/mock_repo/issues/mock_issue_id/comments/',
49
49
  {'content' => 'mock_comment'},
50
50
  {}
51
51
  )
@@ -60,7 +60,7 @@ describe BitBucket::Issues::Comments do
60
60
  before do
61
61
  expect(comments).to receive(:request).with(
62
62
  :put,
63
- '/2.0/repositories/mock_username/mock_repo/issues/comments/mock_comment_id',
63
+ '/1.0/repositories/mock_username/mock_repo/issues/comments/mock_comment_id',
64
64
  {'content' => 'new_mock_comment'},
65
65
  {}
66
66
  )
@@ -75,7 +75,7 @@ describe BitBucket::Issues::Comments do
75
75
  before do
76
76
  expect(comments).to receive(:request).with(
77
77
  :delete,
78
- '/2.0/repositories/mock_username/mock_repo/issues/comments/mock_comment_id',
78
+ '/1.0/repositories/mock_username/mock_repo/issues/comments/mock_comment_id',
79
79
  {},
80
80
  {}
81
81
  )