gitlab 4.9.0 → 4.13.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -95,6 +95,9 @@ module Gitlab
95
95
  # Raised when API endpoint returns the HTTP status code 405.
96
96
  class MethodNotAllowed < ResponseError; end
97
97
 
98
+ # Raised when API endpoint returns the HTTP status code 406.
99
+ class NotAcceptable < ResponseError; end
100
+
98
101
  # Raised when API endpoint returns the HTTP status code 409.
99
102
  class Conflict < ResponseError; end
100
103
 
@@ -112,5 +115,21 @@ module Gitlab
112
115
 
113
116
  # Raised when API endpoint returns the HTTP status code 503.
114
117
  class ServiceUnavailable < ResponseError; end
118
+
119
+ # HTTP status codes mapped to error classes.
120
+ STATUS_MAPPINGS = {
121
+ 400 => BadRequest,
122
+ 401 => Unauthorized,
123
+ 403 => Forbidden,
124
+ 404 => NotFound,
125
+ 405 => MethodNotAllowed,
126
+ 406 => NotAcceptable,
127
+ 409 => Conflict,
128
+ 422 => Unprocessable,
129
+ 429 => TooManyRequests,
130
+ 500 => InternalServerError,
131
+ 502 => BadGateway,
132
+ 503 => ServiceUnavailable
133
+ }.freeze
115
134
  end
116
135
  end
@@ -56,6 +56,25 @@ module Gitlab
56
56
  response
57
57
  end
58
58
 
59
+ def paginate_with_limit(limit)
60
+ response = block_given? ? nil : []
61
+ count = 0
62
+ each_page do |page|
63
+ if block_given?
64
+ page.each do |item|
65
+ yield item
66
+ count += 1
67
+ break if count >= limit
68
+ end
69
+ else
70
+ response += page[0, limit - count]
71
+ count = response.length
72
+ end
73
+ break if count >= limit
74
+ end
75
+ response
76
+ end
77
+
59
78
  def last_page?
60
79
  !(@links.nil? || @links.last.nil?)
61
80
  end
@@ -42,7 +42,12 @@ module Gitlab
42
42
  %w[get post put delete].each do |method|
43
43
  define_method method do |path, options = {}|
44
44
  httparty_config(options)
45
- authorization_header(options)
45
+
46
+ unless options[:unauthenticated]
47
+ options[:headers] ||= {}
48
+ options[:headers].merge!(authorization_header)
49
+ end
50
+
46
51
  validate self.class.send(method, @endpoint + path, options)
47
52
  end
48
53
  end
@@ -50,20 +55,7 @@ module Gitlab
50
55
  # Checks the response code for common errors.
51
56
  # Returns parsed response for successful requests.
52
57
  def validate(response)
53
- error_klass = case response.code
54
- when 400 then Error::BadRequest
55
- when 401 then Error::Unauthorized
56
- when 403 then Error::Forbidden
57
- when 404 then Error::NotFound
58
- when 405 then Error::MethodNotAllowed
59
- when 409 then Error::Conflict
60
- when 422 then Error::Unprocessable
61
- when 429 then Error::TooManyRequests
62
- when 500 then Error::InternalServerError
63
- when 502 then Error::BadGateway
64
- when 503 then Error::ServiceUnavailable
65
- end
66
-
58
+ error_klass = Error::STATUS_MAPPINGS[response.code]
67
59
  raise error_klass, response if error_klass
68
60
 
69
61
  parsed = response.parsed_response
@@ -75,28 +67,25 @@ module Gitlab
75
67
  # Sets a base_uri and default_params for requests.
76
68
  # @raise [Error::MissingCredentials] if endpoint not set.
77
69
  def request_defaults(sudo = nil)
78
- self.class.default_params sudo: sudo
79
70
  raise Error::MissingCredentials, 'Please set an endpoint to API' unless @endpoint
80
71
 
72
+ self.class.default_params sudo: sudo
81
73
  self.class.default_params.delete(:sudo) if sudo.nil?
82
74
  end
83
75
 
84
76
  private
85
77
 
86
- # Sets a PRIVATE-TOKEN or Authorization header for requests.
78
+ # Returns an Authorization header hash
87
79
  #
88
- # @param [Hash] options A customizable set of options.
89
- # @option options [Boolean] :unauthenticated true if the API call does not require user authentication.
90
80
  # @raise [Error::MissingCredentials] if private_token and auth_token are not set.
91
- def authorization_header(options)
92
- return if options[:unauthenticated]
81
+ def authorization_header
93
82
  raise Error::MissingCredentials, 'Please provide a private_token or auth_token for user' unless @private_token
94
83
 
95
- options[:headers] = if @private_token.size < 21
96
- { 'PRIVATE-TOKEN' => @private_token }
97
- else
98
- { 'Authorization' => "Bearer #{@private_token}" }
99
- end
84
+ if @private_token.size < 21
85
+ { 'PRIVATE-TOKEN' => @private_token }
86
+ else
87
+ { 'Authorization' => "Bearer #{@private_token}" }
88
+ end
100
89
  end
101
90
 
102
91
  # Set HTTParty configuration
@@ -30,12 +30,8 @@ class Gitlab::Shell
30
30
  private
31
31
 
32
32
  def history_file
33
- if defined?(@history_file)
34
- @history_file
35
- else
36
- @history_file = File.open(history_file_path, 'w', 0o600).tap do |file|
37
- file.sync = true
38
- end
33
+ @history_file ||= File.open(history_file_path, 'w', 0o600).tap do |file|
34
+ file.sync = true
39
35
  end
40
36
  rescue Errno::EACCES
41
37
  warn 'History not saved; unable to open your history file for writing.'
@@ -50,8 +46,8 @@ class Gitlab::Shell
50
46
  path = history_file_path
51
47
 
52
48
  File.foreach(path) { |line| yield(line) } if File.exist?(path)
53
- rescue StandardError => error
54
- warn "History file not loaded: #{error.message}"
49
+ rescue StandardError => e
50
+ warn "History file not loaded: #{e.message}"
55
51
  end
56
52
 
57
53
  def max_lines
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitlab
4
- VERSION = '4.9.0'
4
+ VERSION = '4.13.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.9.0
4
+ version: 4.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nihad Abbasov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-02-04 00:00:00.000000000 Z
12
+ date: 2019-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -140,6 +140,8 @@ files:
140
140
  - lib/gitlab/cli_helpers.rb
141
141
  - lib/gitlab/client.rb
142
142
  - lib/gitlab/client/access_requests.rb
143
+ - lib/gitlab/client/application_settings.rb
144
+ - lib/gitlab/client/avatar.rb
143
145
  - lib/gitlab/client/award_emojis.rb
144
146
  - lib/gitlab/client/boards.rb
145
147
  - lib/gitlab/client/branches.rb
@@ -147,16 +149,23 @@ files:
147
149
  - lib/gitlab/client/build_variables.rb
148
150
  - lib/gitlab/client/builds.rb
149
151
  - lib/gitlab/client/commits.rb
152
+ - lib/gitlab/client/container_registry.rb
150
153
  - lib/gitlab/client/deployments.rb
151
154
  - lib/gitlab/client/environments.rb
155
+ - lib/gitlab/client/epics.rb
152
156
  - lib/gitlab/client/events.rb
153
157
  - lib/gitlab/client/features.rb
158
+ - lib/gitlab/client/group_boards.rb
159
+ - lib/gitlab/client/group_labels.rb
154
160
  - lib/gitlab/client/group_milestones.rb
155
161
  - lib/gitlab/client/groups.rb
162
+ - lib/gitlab/client/issue_links.rb
156
163
  - lib/gitlab/client/issues.rb
157
164
  - lib/gitlab/client/jobs.rb
158
165
  - lib/gitlab/client/keys.rb
159
166
  - lib/gitlab/client/labels.rb
167
+ - lib/gitlab/client/lint.rb
168
+ - lib/gitlab/client/markdown.rb
160
169
  - lib/gitlab/client/merge_request_approvals.rb
161
170
  - lib/gitlab/client/merge_requests.rb
162
171
  - lib/gitlab/client/milestones.rb
@@ -176,6 +185,7 @@ files:
176
185
  - lib/gitlab/client/repository_submodules.rb
177
186
  - lib/gitlab/client/resource_label_events.rb
178
187
  - lib/gitlab/client/runners.rb
188
+ - lib/gitlab/client/search.rb
179
189
  - lib/gitlab/client/services.rb
180
190
  - lib/gitlab/client/sidekiq.rb
181
191
  - lib/gitlab/client/snippets.rb
@@ -216,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
226
  - !ruby/object:Gem::Version
217
227
  version: '0'
218
228
  requirements: []
219
- rubygems_version: 3.0.2
229
+ rubygems_version: 3.0.6
220
230
  signing_key:
221
231
  specification_version: 4
222
232
  summary: A Ruby wrapper and CLI for the GitLab API