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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 045be3f2ccc39c4e17be95cc0521de0dcff26357ea178904a4c7d52546b8bf16
4
- data.tar.gz: 9693eab36c48f610da08d53497e024528ba636a394ac31fe4a73604d85f391b1
3
+ metadata.gz: 5e7fe03a821fac9f9d30b4cc8e1ff65625d45202553fcbf9b32434debfc21872
4
+ data.tar.gz: 04acd1fa3f3ad6853e8bb89148b1670ca9f49b58369b922d5ee3c8aeb2afd657
5
5
  SHA512:
6
- metadata.gz: 3be4afc1904963bbb5eb5a20576ece90661dfc0c4b2e335101b12a2cf5b71f46cd0dcd43cdcaf78ba244cf1e472d161d5422f4ebc9648942505ff64c3571a2e4
7
- data.tar.gz: 5d93b129e4e95f794ef3a197456afff8d60923729b9fb078acd3da179c4837563e88a3dbdbe58255273c93cf80699fc22ee8fbbee00e17ad9f84544d8525c1d3
6
+ metadata.gz: d9184b838b5c6908f3b468cb32e5e914c532861fdc10406902af750b6dbfd8bc8f3dc92b56621a9898b6e1e1acc9a549f73060a11a5fc8576841da82e5ce3e79
7
+ data.tar.gz: a0237065ac0b3dfcd1cd827fd20b9413c16bf5a675ce6ad73b1167fa9648cdec6506025ae6ad9cfe699ef66ea6d5ee52a9459d873ee8060c9465785805ad57bc
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  [Wiki](https://github.com/vongrippen/bitbucket/wiki) | [RDocs](http://rubydoc.info/github/vongrippen/bitbucket/master/frames)
6
6
 
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)
8
+
7
9
  A Ruby wrapper for the BitBucket REST API.
8
10
 
9
11
  ## Installation
@@ -25,19 +27,19 @@ gem "bitbucket_rest_api"
25
27
  Create a new client instance
26
28
 
27
29
  ```ruby
28
- bitbucket = BitBucket.new
30
+ bitbucket = BitBucket::Client.new
29
31
  ```
30
32
 
31
33
  At this stage you can also supply various configuration parameters, such as `:user`,`:repo`, `:oauth_token`, `:oauth_secret`, `:basic_auth` which are used throughout the API. These can be passed directly as hash options:
32
34
 
33
35
  ```ruby
34
- bitbucket = BitBucket.new oauth_token: 'request_token', oauth_secret: 'request_secret'
36
+ bitbucket = BitBucket::Client.new oauth_token: 'request_token', oauth_secret: 'request_secret'
35
37
  ```
36
38
 
37
39
  Alternatively, you can configure the BitBucket settings by passing a block:
38
40
 
39
41
  ```ruby
40
- bitbucket = BitBucket.new do |config|
42
+ bitbucket = BitBucket::Client.new do |config|
41
43
  config.oauth_token = 'request_token'
42
44
  config.oauth_secret = 'request_secret'
43
45
  config.client_id = 'consumer_key'
@@ -49,16 +51,16 @@ end
49
51
  You can authenticate either using OAuth authentication or through basic authentication by passing your login and password credentials
50
52
 
51
53
  ```ruby
52
- bitbucket = BitBucket.new login:'vongrippen', password:'...'
54
+ bitbucket = BitBucket::Client.new login:'vongrippen', password:'...'
53
55
  ```
54
56
 
55
57
  or use convenience method:
56
58
 
57
59
  ```ruby
58
- bitbucket = BitBucket.new basic_auth: 'login:password'
60
+ bitbucket = BitBucket::Client.new basic_auth: 'login:password'
59
61
  ```
60
62
 
61
- You can interact with BitBucket interface, for example repositories, by issuing following calls that correspond directly to the BitBucket API hierarchy
63
+ You can interact with BitBucket interface, for example repositories, by issuing the following calls that correspond directly to the BitBucket API hierarchy
62
64
 
63
65
  ```ruby
64
66
  bitbucket.repos.changesets.all 'user-name', 'repo-name'
@@ -84,19 +86,18 @@ end
84
86
  The `bitbucket_rest_api` gem will use the default middleware stack which is exposed by calling `stack` on client instance. However, this stack can be freely modified with methods such as `insert`, `insert_after`, `delete` and `swap`. For instance to add your `CustomMiddleware` do
85
87
 
86
88
  ```ruby
87
- bitbucket = BitBucket.new do |config|
88
- config.stack.insert_after BitBucket::Response::Helpers, CustomMiddleware
89
+ bitbucket = BitBucket::Client.new do |config|
90
+ config.stack.insert_after CustomMiddleware
89
91
  end
90
92
  ```
91
93
 
92
94
  Furthermore, you can build your entire custom stack and specify other connection options such as `adapter`
93
95
 
94
96
  ```ruby
95
- bitbucket = BitBucket.new do |config|
97
+ bitbucket = BitBucket::Client.new do |config|
96
98
  config.adapter :excon
97
99
 
98
100
  config.stack do |builder|
99
- builder.use BitBucket::Response::Helpers
100
101
  builder.use BitBucket::Response::Jsonize
101
102
  end
102
103
  end
@@ -155,8 +156,8 @@ end
155
156
 
156
157
  or
157
158
 
158
- BitBucket.new(:oauth_token => YOUR_OAUTH_REQUEST_TOKEN, :oauth_secret => YOUR_OAUTH_REQUEST_TOKEN_SECRET)
159
- BitBucket.new(:basic_auth => 'login:password')
159
+ BitBucket::Client.new(:oauth_token => YOUR_OAUTH_REQUEST_TOKEN, :oauth_secret => YOUR_OAUTH_REQUEST_TOKEN_SECRET)
160
+ BitBucket::Client.new(:basic_auth => 'login:password')
160
161
  ```
161
162
 
162
163
  ## Development
@@ -19,6 +19,7 @@ module BitBucket
19
19
  include Validations
20
20
  include ParameterFilter
21
21
  include Normalizer
22
+ include Helpers::RepositoryHelper
22
23
 
23
24
  attr_reader *Configuration::VALID_OPTIONS_KEYS
24
25
 
@@ -38,7 +39,6 @@ module BitBucket
38
39
  def initialize(options={}, &block)
39
40
  super()
40
41
  setup options
41
- set_api_client
42
42
 
43
43
  self.instance_eval(&block) if block_given?
44
44
  end
@@ -62,11 +62,6 @@ module BitBucket
62
62
  end
63
63
  end
64
64
 
65
- # Assigns current api class
66
- def set_api_client
67
- BitBucket.api_client = self
68
- end
69
-
70
65
  # Responds to attribute query or attribute clear
71
66
  def method_missing(method, *args, &block) # :nodoc:
72
67
  case method.to_s
@@ -15,7 +15,6 @@ module BitBucket
15
15
  def self.create_instance(klass, options)
16
16
  options.symbolize_keys!
17
17
  instance = convert_to_constant(klass.to_s).new options
18
- BitBucket.api_client = instance
19
18
  instance
20
19
  end
21
20
 
@@ -18,9 +18,13 @@ module BitBucket
18
18
  :user,
19
19
  :login,
20
20
  :password,
21
- :basic_auth
21
+ :basic_auth,
22
+ :bitbucket_server
22
23
  ].freeze
23
24
 
25
+ # the URI schema is dependent on whether we are talking about BitBucket Cloud or Server
26
+ DEFAULT_BITBUCKET_SERVER = false
27
+
24
28
  # Other adapters are :typhoeus, :patron, :em_synchrony, :excon, :test
25
29
  DEFAULT_ADAPTER = :net_http
26
30
 
@@ -99,6 +103,8 @@ module BitBucket
99
103
  self.login = DEFAULT_LOGIN
100
104
  self.password = DEFAULT_PASSWORD
101
105
  self.basic_auth = DEFAULT_BASIC_AUTH
106
+ self.bitbucket_server = DEFAULT_BITBUCKET_SERVER
107
+
102
108
  self
103
109
  end
104
110
 
@@ -5,7 +5,6 @@ require 'faraday_middleware'
5
5
  require 'bitbucket_rest_api/response'
6
6
  require 'bitbucket_rest_api/response/mashify'
7
7
  require 'bitbucket_rest_api/response/jsonize'
8
- require 'bitbucket_rest_api/response/helpers'
9
8
  require 'bitbucket_rest_api/response/raise_error'
10
9
  require 'bitbucket_rest_api/request/oauth'
11
10
  require 'bitbucket_rest_api/request/basic_auth'
@@ -31,7 +30,8 @@ module BitBucket
31
30
  },
32
31
  :ssl => { :verify => false },
33
32
  :url => options.fetch(:endpoint) { BitBucket.endpoint }
34
- }.merge(options)
33
+ }.merge(BitBucket.connection_options)
34
+ .merge(options)
35
35
  end
36
36
 
37
37
  # Default middleware stack that uses default adapter as specified at
@@ -42,12 +42,15 @@ module BitBucket
42
42
  #builder.use BitBucket::Request::Jsonize
43
43
  builder.use Faraday::Request::Multipart
44
44
  builder.use Faraday::Request::UrlEncoded
45
- builder.use FaradayMiddleware::OAuth, {:consumer_key => client_id, :consumer_secret => client_secret, :token => oauth_token, :token_secret => oauth_secret} if client_id? and client_secret?
45
+
46
+ if client_id? && client_secret?
47
+ builder.use FaradayMiddleware::OAuth, {consumer_key: client_id, consumer_secret: client_secret, token: oauth_token, token_secret: oauth_secret}
48
+ end
49
+
46
50
  builder.use BitBucket::Request::BasicAuth, authentication if basic_authed?
47
51
  builder.use FaradayMiddleware::EncodeJson
48
52
 
49
53
  builder.use Faraday::Response::Logger if ENV['DEBUG']
50
- builder.use BitBucket::Response::Helpers
51
54
  unless options[:raw]
52
55
  builder.use BitBucket::Response::Mashify
53
56
  builder.use BitBucket::Response::Jsonize
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket #:nodoc
4
+ # Raised when BitBucket receives a RefreshToken error
5
+ module Error
6
+ class RefreshToken < BitBucketError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end # Error
12
+ end # BitBucket
@@ -33,6 +33,7 @@ end # BitBucket
33
33
  bad_events
34
34
  no_events
35
35
  blank_value
36
+ refresh_token
36
37
  ].each do |error|
37
38
  require "bitbucket_rest_api/error/#{error}"
38
39
  end
@@ -0,0 +1,13 @@
1
+ module BitBucket
2
+ module Helpers
3
+ module RepositoryHelper
4
+ def sanitize_repository_name(repository_name)
5
+ return nil if repository_name.nil?
6
+ repository_name.downcase
7
+ .gsub(/[^a-z0-9\_\-\.\/ ]/, '') # strip special characters
8
+ .gsub(/[ \/]/, '-') # convert characters to dashes
9
+ .gsub(/-+/, '-') # only allow one dash in a row
10
+ end
11
+ end
12
+ end
13
+ end
@@ -8,7 +8,7 @@ module BitBucket
8
8
  _validate_presence_of emailaddress
9
9
  perm ||= "write"
10
10
 
11
- post_request("/2.0/invitations/#{user}/#{repo.downcase}/#{emailaddress}",
11
+ post_request("/1.0/invitations/#{user}/#{repo.downcase}/#{emailaddress}",
12
12
  permission: perm)
13
13
  end
14
14
  end
@@ -27,7 +27,7 @@ module BitBucket
27
27
  normalize! params
28
28
  # _merge_mime_type(:issue_comment, params)
29
29
 
30
- response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/comments/", params)
30
+ response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/comments/", params)
31
31
  return response unless block_given?
32
32
  response.each { |el| yield el }
33
33
  end
@@ -47,7 +47,7 @@ module BitBucket
47
47
  normalize! params
48
48
  # _merge_mime_type(:issue_comment, params)
49
49
 
50
- get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
50
+ get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
51
51
  end
52
52
  alias :find :get
53
53
 
@@ -71,7 +71,7 @@ module BitBucket
71
71
  filter! VALID_ISSUE_COMMENT_PARAM_NAME, params
72
72
  assert_required_keys(%w[ content ], params)
73
73
 
74
- post_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/comments/", params)
74
+ post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/comments/", params)
75
75
  end
76
76
 
77
77
  # Edit a comment
@@ -94,7 +94,7 @@ module BitBucket
94
94
  filter! VALID_ISSUE_COMMENT_PARAM_NAME, params
95
95
  assert_required_keys(%w[ content ], params)
96
96
 
97
- put_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
97
+ put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
98
98
  end
99
99
 
100
100
  # Delete a comment
@@ -111,7 +111,7 @@ module BitBucket
111
111
  normalize! params
112
112
  # _merge_mime_type(:issue_comment, params)
113
113
 
114
- delete_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
114
+ delete_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
115
115
  end
116
116
 
117
117
  end # Issues::Comments
@@ -21,7 +21,7 @@ module BitBucket
21
21
  _validate_user_repo_params(user, repo) unless user? && repo?
22
22
  normalize! params
23
23
 
24
- response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/components", params)
24
+ response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components", params)
25
25
  return response unless block_given?
26
26
  response.each { |el| yield el }
27
27
  end
@@ -39,7 +39,7 @@ module BitBucket
39
39
  _validate_presence_of component_id
40
40
  normalize! params
41
41
 
42
- get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
42
+ get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
43
43
  end
44
44
  alias :find :get
45
45
 
@@ -60,7 +60,7 @@ module BitBucket
60
60
  filter! VALID_COMPONENT_INPUTS, params
61
61
  assert_required_keys(VALID_COMPONENT_INPUTS, params)
62
62
 
63
- post_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/components", params)
63
+ post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components", params)
64
64
  end
65
65
 
66
66
  # Update a component
@@ -82,7 +82,7 @@ module BitBucket
82
82
  filter! VALID_COMPONENT_INPUTS, params
83
83
  assert_required_keys(VALID_COMPONENT_INPUTS, params)
84
84
 
85
- put_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
85
+ put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
86
86
  end
87
87
  alias :edit :update
88
88
 
@@ -99,7 +99,7 @@ module BitBucket
99
99
  _validate_presence_of component_id
100
100
  normalize! params
101
101
 
102
- delete_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
102
+ delete_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
103
103
  end
104
104
 
105
105
  end # Issues::Components
@@ -24,7 +24,7 @@ module BitBucket
24
24
 
25
25
  normalize! params
26
26
 
27
- response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/milestones", params)
27
+ response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/milestones", params)
28
28
  return response unless block_given?
29
29
  response.each { |el| yield el }
30
30
  end
@@ -42,7 +42,7 @@ module BitBucket
42
42
  _validate_presence_of milestone_id
43
43
  normalize! params
44
44
 
45
- get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/milestones/#{milestone_id}", params)
45
+ get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/milestones/#{milestone_id}", params)
46
46
  end
47
47
  alias :find :get
48
48
 
@@ -63,7 +63,7 @@ module BitBucket
63
63
  filter! VALID_MILESTONE_INPUTS, params
64
64
  assert_required_keys(%w[ name ], params)
65
65
 
66
- post_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/milestones", params)
66
+ post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/milestones", params)
67
67
  end
68
68
 
69
69
  # Update a milestone
@@ -85,7 +85,7 @@ module BitBucket
85
85
  filter! VALID_MILESTONE_INPUTS, params
86
86
  assert_required_keys(%w[ name ], params)
87
87
 
88
- put_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/milestones/#{milestone_id}", params)
88
+ put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/milestones/#{milestone_id}", params)
89
89
  end
90
90
 
91
91
  # Delete a milestone
@@ -100,7 +100,7 @@ module BitBucket
100
100
  _validate_presence_of milestone_id
101
101
  normalize! params
102
102
 
103
- delete_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/milestones/#{milestone_id}", params)
103
+ delete_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/milestones/#{milestone_id}", params)
104
104
  end
105
105
 
106
106
  end # Issues::Milestones
@@ -82,7 +82,7 @@ module BitBucket
82
82
  # _merge_mime_type(:issue, params)
83
83
  assert_valid_values(VALID_ISSUE_PARAM_VALUES, params)
84
84
 
85
- response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues", params)
85
+ response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues", params)
86
86
  return response.issues unless block_given?
87
87
  response.issues.each { |el| yield el }
88
88
  end
@@ -103,7 +103,7 @@ module BitBucket
103
103
  normalize! params
104
104
  # _merge_mime_type(:issue, params)
105
105
 
106
- get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}", params)
106
+ get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}", params)
107
107
  end
108
108
 
109
109
  alias :find :get
@@ -122,7 +122,7 @@ module BitBucket
122
122
  normalize! params
123
123
  # _merge_mime_type(:issue, params)
124
124
 
125
- delete_request("/2.0/repositories/#{user}/#{repo}/issues/#{issue_id}", params)
125
+ delete_request("/1.0/repositories/#{user}/#{repo}/issues/#{issue_id}", params)
126
126
  end
127
127
 
128
128
  # Create an issue
@@ -173,7 +173,7 @@ module BitBucket
173
173
  filter! VALID_ISSUE_PARAM_NAMES, params
174
174
  assert_required_keys(%w[ title ], params)
175
175
 
176
- post_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/", params)
176
+ post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/", params)
177
177
  end
178
178
 
179
179
  # Edit an issue
@@ -223,7 +223,7 @@ module BitBucket
223
223
  # _merge_mime_type(:issue, params)
224
224
  filter! VALID_ISSUE_PARAM_NAMES, params
225
225
 
226
- put_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/", params)
226
+ put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/", params)
227
227
  end
228
228
 
229
229
  end # Issues
@@ -28,7 +28,7 @@ module BitBucket
28
28
  normalize! params
29
29
  filter! %w[ limit start], params
30
30
 
31
- response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/changesets", params)
31
+ response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/changesets", params)
32
32
  return response unless block_given?
33
33
  response.each { |el| yield el }
34
34
  end
@@ -46,7 +46,7 @@ module BitBucket
46
46
  _validate_presence_of sha
47
47
  normalize! params
48
48
 
49
- get_request("/2.0/repositories/#{user}/#{repo.downcase}/changesets/#{sha}", params)
49
+ get_request("/1.0/repositories/#{user}/#{repo.downcase}/changesets/#{sha}", params)
50
50
  end
51
51
  alias :find :get
52
52
 
@@ -3,7 +3,7 @@
3
3
  module BitBucket
4
4
  class Repos::Commits < API
5
5
 
6
- VALID_KEY_PARAM_NAMES = %w(include exclude).freeze
6
+ VALID_KEY_PARAM_NAMES = %w(include exclude pagelen).freeze
7
7
 
8
8
  # Gets the commit information associated with a repository. By default, this
9
9
  # call returns all the commits across all branches, bookmarks, and tags. The
@@ -28,9 +28,15 @@ module BitBucket
28
28
  normalize! params
29
29
  filter! VALID_KEY_PARAM_NAMES, params
30
30
 
31
- path = "/2.0/repositories/#{user}/#{repo.downcase}/commits"
31
+ path = if BitBucket.options[:bitbucket_server]
32
+ "/1.0/projects/#{user_name}/repos/#{repo_name}/commits"
33
+ else
34
+ "/2.0/repositories/#{user}/#{repo.downcase}/commits"
35
+ end
36
+
32
37
  path << "/#{branchortag}" if branchortag
33
38
  response = get_request(path, params)
39
+
34
40
  return response unless block_given?
35
41
  response.each { |el| yield el }
36
42
  end
@@ -15,7 +15,7 @@ module BitBucket
15
15
  _validate_user_repo_params(user, repo) unless user? && repo?
16
16
  normalize! params
17
17
 
18
- response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/followers/", params)
18
+ response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/followers/", params)
19
19
  return response unless block_given?
20
20
  response.each { |el| yield el }
21
21
  end
@@ -30,7 +30,7 @@ module BitBucket
30
30
  params = args.extract_options!
31
31
  normalize! params
32
32
 
33
- response = get_request("/2.0/user/follows", params)
33
+ response = get_request("/1.0/user/follows", params)
34
34
  return response unless block_given?
35
35
  response.each { |el| yield el }
36
36
  end
@@ -61,7 +61,7 @@ module BitBucket
61
61
  assert_required_keys(REQUIRED_KEY_PARAM_NAMES, params)
62
62
  filter! VALID_REPO_OPTIONS, params
63
63
 
64
- post_request("/2.0/repositories/#{user}/#{repo.downcase}/fork", params)
64
+ post_request("/1.0/repositories/#{user}/#{repo.downcase}/fork", params)
65
65
  end
66
66
 
67
67
 
@@ -3,7 +3,7 @@
3
3
  module BitBucket
4
4
  class Repos::Keys < API
5
5
 
6
- VALID_KEY_PARAM_NAMES = %w[ label key ].freeze
6
+ VALID_KEY_PARAM_NAMES = %w[ label key text ].freeze
7
7
 
8
8
  # List deploy keys
9
9
  #
@@ -12,12 +12,19 @@ module BitBucket
12
12
  # bitbucket.repos.keys.list 'user-name', 'repo-name'
13
13
  # bitbucket.repos.keys.list 'user-name', 'repo-name' { |key| ... }
14
14
  #
15
- def list(user_name, repo_name, params={})
16
- _update_user_repo_params(user_name, repo_name)
15
+ def list(user_name_or_project_key, repo_name, params={})
16
+ _update_user_repo_params(user_name_or_project_key, repo_name)
17
17
  _validate_user_repo_params(user, repo) unless user? && repo?
18
18
  normalize! params
19
19
 
20
- response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/deploy-keys/", params)
20
+ url = if BitBucket.options[:bitbucket_server]
21
+ "/1.0/projects/#{user_name_or_project_key}/repos/#{repo_name.downcase}/ssh"
22
+ else
23
+ "/1.0/repositories/#{user_name_or_project_key}/#{repo.downcase}/deploy-keys/"
24
+ end
25
+
26
+ response = get_request(url, params)
27
+
21
28
  return response unless block_given?
22
29
  response.each { |el| yield el }
23
30
  end
@@ -35,14 +42,21 @@ module BitBucket
35
42
  # "label" => "octocat@octomac",
36
43
  # "key" => "ssh-rsa AAA..."
37
44
  #
38
- def create(user_name, repo_name, params={})
39
- _update_user_repo_params(user_name, repo_name)
45
+ def create(user_name_or_project_key, repo_name, params={})
46
+ _update_user_repo_params(user_name_or_project_key, repo_name)
40
47
  _validate_user_repo_params(user, repo) unless user? && repo?
41
48
  normalize! params
42
49
  filter! VALID_KEY_PARAM_NAMES, params
43
- assert_required_keys(VALID_KEY_PARAM_NAMES, params)
44
50
 
45
- post_request("/2.0/repositories/#{user}/#{repo.downcase}/deploy-keys/", params)
51
+ options = { headers: { "Content-Type" => "application/json" } }
52
+
53
+ url = if BitBucket.options[:bitbucket_server]
54
+ "/1.0/projects/#{user_name_or_project_key}/repos/#{repo_name.downcase}/ssh"
55
+ else
56
+ "/1.0/repositories/#{user_name_or_project_key}/#{repo.downcase}/deploy-keys/"
57
+ end
58
+
59
+ post_request(url, params, options)
46
60
  end
47
61
 
48
62
  # Edit a key
@@ -65,7 +79,7 @@ module BitBucket
65
79
  normalize! params
66
80
  filter! VALID_KEY_PARAM_NAMES, params
67
81
 
68
- put_request("/2.0/repositories/#{user}/#{repo.downcase}/deploy-keys/#{key_id}", params)
82
+ put_request("/1.0/repositories/#{user}/#{sanitize_repository_name(repo)}/deploy-keys/#{key_id}", params)
69
83
  end
70
84
 
71
85
  # Delete key
@@ -74,13 +88,19 @@ module BitBucket
74
88
  # @bitbucket = BitBucket.new
75
89
  # @bitbucket.repos.keys.delete 'user-name', 'repo-name', 'key-id'
76
90
  #
77
- def delete(user_name, repo_name, key_id, params={})
78
- _update_user_repo_params(user_name, repo_name)
91
+ def delete(user_name_or_project_key, repo_name, key_id, params={})
92
+ _update_user_repo_params(user_name_or_project_key, repo_name)
79
93
  _validate_user_repo_params(user, repo) unless user? && repo?
80
94
  _validate_presence_of key_id
81
95
  normalize! params
82
96
 
83
- delete_request("/2.0/repositories/#{user}/#{repo.downcase}/deploy-keys/#{key_id}", params)
97
+ url = if BitBucket.options[:bitbucket_server]
98
+ "/1.0/projects/#{user_name_or_project_key}/repos/#{repo_name.downcase}/ssh/#{key_id}"
99
+ else
100
+ "/1.0/repositories/#{user_name_or_project_key}/#{repo.downcase}/deploy-keys/#{key_id}"
101
+ end
102
+
103
+ delete_request(url, params)
84
104
  end
85
105
 
86
106
  end # Repos::Keys
@@ -33,7 +33,7 @@ module BitBucket
33
33
  _validate_user_repo_params(user, repo) unless user? && repo?
34
34
  normalize! params
35
35
 
36
- response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/pullrequests/#{pull_request_id}/participants", params)
36
+ response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/pullrequests/#{pull_request_id}/participants", params)
37
37
  return response unless block_given?
38
38
  response.each { |el| yield el }
39
39
  end
@@ -12,12 +12,19 @@ module BitBucket
12
12
  # bitbucket.repos.services.list 'user-name', 'repo-name'
13
13
  # bitbucket.repos.services.list 'user-name', 'repo-name' { |service| ... }
14
14
  #
15
- def list(user_name, repo_name, params={})
16
- _update_user_repo_params(user_name, repo_name)
15
+ def list(user_name_or_project_key, repo_name, params={})
16
+ _update_user_repo_params(user_name_or_project_key, repo_name)
17
17
  _validate_user_repo_params(user, repo) unless user? && repo?
18
18
  normalize! params
19
19
 
20
- response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/services", params)
20
+ url = if BitBucket.options[:bitbucket_server]
21
+ "/1.0/projects/#{user_name_or_project_key}/repos/#{repo.downcase}/settings/hooks"
22
+ else
23
+ "/1.0/repositories/#{user}/#{repo.downcase}/services"
24
+ end
25
+
26
+ response = get_request(url, params)
27
+
21
28
  return response unless block_given?
22
29
  response.each { |el| yield el }
23
30
  end
@@ -35,7 +42,7 @@ module BitBucket
35
42
  _validate_presence_of(service_id)
36
43
  normalize! params
37
44
 
38
- get_request("/2.0/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params)
45
+ get_request("/1.0/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params)
39
46
  end
40
47
  alias :find :get
41
48
 
@@ -58,7 +65,7 @@ module BitBucket
58
65
  normalize! params
59
66
  assert_required_keys(REQUIRED_KEY_PARAM_NAMES, params)
60
67
 
61
- post_request("/2.0/repositories/#{user}/#{repo.downcase}/services", params)
68
+ post_request("/1.0/repositories/#{user}/#{repo.downcase}/services", params)
62
69
  end
63
70
 
64
71
  # Edit a service
@@ -81,7 +88,7 @@ module BitBucket
81
88
 
82
89
  normalize! params
83
90
 
84
- put_request("/2.0/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params)
91
+ put_request("/1.0/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params)
85
92
  end
86
93
 
87
94
  # Delete service
@@ -96,7 +103,7 @@ module BitBucket
96
103
  _validate_presence_of(service_id)
97
104
  normalize! params
98
105
 
99
- delete_request("/2.0/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params)
106
+ delete_request("/1.0/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params)
100
107
  end
101
108
 
102
109
  end # Repos::Keys