gitlab 4.10.0 → 4.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +26 -18
  4. data/lib/gitlab/api.rb +2 -0
  5. data/lib/gitlab/cli.rb +6 -8
  6. data/lib/gitlab/cli_helpers.rb +20 -25
  7. data/lib/gitlab/client/application_settings.rb +172 -0
  8. data/lib/gitlab/client/build_variables.rb +17 -12
  9. data/lib/gitlab/client/commits.rb +42 -5
  10. data/lib/gitlab/client/container_registry.rb +85 -0
  11. data/lib/gitlab/client/epic_issues.rb +23 -0
  12. data/lib/gitlab/client/epics.rb +73 -0
  13. data/lib/gitlab/client/group_badges.rb +88 -0
  14. data/lib/gitlab/client/group_labels.rb +1 -1
  15. data/lib/gitlab/client/groups.rb +153 -2
  16. data/lib/gitlab/client/issue_links.rb +48 -0
  17. data/lib/gitlab/client/issues.rb +1 -1
  18. data/lib/gitlab/client/jobs.rb +91 -8
  19. data/lib/gitlab/client/keys.rb +11 -0
  20. data/lib/gitlab/client/labels.rb +1 -1
  21. data/lib/gitlab/client/lint.rb +19 -0
  22. data/lib/gitlab/client/markdown.rb +23 -0
  23. data/lib/gitlab/client/merge_request_approvals.rb +160 -7
  24. data/lib/gitlab/client/merge_requests.rb +64 -4
  25. data/lib/gitlab/client/notes.rb +28 -1
  26. data/lib/gitlab/client/packages.rb +95 -0
  27. data/lib/gitlab/client/pipeline_schedules.rb +16 -4
  28. data/lib/gitlab/client/pipelines.rb +12 -0
  29. data/lib/gitlab/client/projects.rb +142 -8
  30. data/lib/gitlab/client/remote_mirrors.rb +51 -0
  31. data/lib/gitlab/client/repositories.rb +59 -3
  32. data/lib/gitlab/client/repository_files.rb +16 -0
  33. data/lib/gitlab/client/resource_state_events.rb +57 -0
  34. data/lib/gitlab/client/runners.rb +99 -14
  35. data/lib/gitlab/client/search.rb +5 -1
  36. data/lib/gitlab/client/user_snippets.rb +114 -0
  37. data/lib/gitlab/client/users.rb +142 -11
  38. data/lib/gitlab/client.rb +18 -2
  39. data/lib/gitlab/configuration.rb +1 -1
  40. data/lib/gitlab/error.rb +54 -0
  41. data/lib/gitlab/help.rb +8 -8
  42. data/lib/gitlab/objectified_hash.rb +23 -7
  43. data/lib/gitlab/page_links.rb +1 -1
  44. data/lib/gitlab/paginated_response.rb +23 -20
  45. data/lib/gitlab/request.rb +34 -33
  46. data/lib/gitlab/shell_history.rb +6 -10
  47. data/lib/gitlab/version.rb +1 -1
  48. data/lib/gitlab.rb +14 -6
  49. metadata +24 -47
@@ -8,6 +8,7 @@ module Gitlab
8
8
  class Request
9
9
  include HTTParty
10
10
  format :json
11
+ maintain_method_across_redirects true
11
12
  headers 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'
12
13
  parser(proc { |body, _| parse(body) })
13
14
 
@@ -25,8 +26,6 @@ module Gitlab
25
26
  true
26
27
  elsif !body
27
28
  false
28
- elsif body.nil?
29
- false
30
29
  else
31
30
  raise Error::Parsing, "Couldn't parse a response body"
32
31
  end
@@ -41,29 +40,34 @@ module Gitlab
41
40
 
42
41
  %w[get post put delete].each do |method|
43
42
  define_method method do |path, options = {}|
44
- httparty_config(options)
45
- authorization_header(options)
46
- validate self.class.send(method, @endpoint + path, options)
43
+ params = options.dup
44
+
45
+ httparty_config(params)
46
+
47
+ unless params[:unauthenticated]
48
+ params[:headers] ||= {}
49
+ params[:headers].merge!(authorization_header)
50
+ end
51
+
52
+ retries_left = params[:ratelimit_retries] || 3
53
+ begin
54
+ response = self.class.send(method, endpoint + path, params)
55
+ validate response
56
+ rescue Gitlab::Error::TooManyRequests => e
57
+ retries_left -= 1
58
+ raise e if retries_left.zero?
59
+
60
+ wait_time = response.headers['Retry-After'] || 2
61
+ sleep(wait_time.to_i)
62
+ retry
63
+ end
47
64
  end
48
65
  end
49
66
 
50
67
  # Checks the response code for common errors.
51
68
  # Returns parsed response for successful requests.
52
69
  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
-
70
+ error_klass = Error.klass(response)
67
71
  raise error_klass, response if error_klass
68
72
 
69
73
  parsed = response.parsed_response
@@ -75,28 +79,25 @@ module Gitlab
75
79
  # Sets a base_uri and default_params for requests.
76
80
  # @raise [Error::MissingCredentials] if endpoint not set.
77
81
  def request_defaults(sudo = nil)
78
- self.class.default_params sudo: sudo
79
- raise Error::MissingCredentials, 'Please set an endpoint to API' unless @endpoint
82
+ raise Error::MissingCredentials, 'Please set an endpoint to API' unless endpoint
80
83
 
84
+ self.class.default_params sudo: sudo
81
85
  self.class.default_params.delete(:sudo) if sudo.nil?
82
86
  end
83
87
 
84
88
  private
85
89
 
86
- # Sets a PRIVATE-TOKEN or Authorization header for requests.
90
+ # Returns an Authorization header hash
87
91
  #
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
92
  # @raise [Error::MissingCredentials] if private_token and auth_token are not set.
91
- def authorization_header(options)
92
- return if options[:unauthenticated]
93
- raise Error::MissingCredentials, 'Please provide a private_token or auth_token for user' unless @private_token
94
-
95
- options[:headers] = if @private_token.size < 21
96
- { 'PRIVATE-TOKEN' => @private_token }
97
- else
98
- { 'Authorization' => "Bearer #{@private_token}" }
99
- end
93
+ def authorization_header
94
+ raise Error::MissingCredentials, 'Please provide a private_token or auth_token for user' unless private_token
95
+
96
+ if private_token.size < 21
97
+ { 'PRIVATE-TOKEN' => private_token }
98
+ else
99
+ { 'Authorization' => "Bearer #{private_token}" }
100
+ end
100
101
  end
101
102
 
102
103
  # 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.'
@@ -46,12 +42,12 @@ class Gitlab::Shell
46
42
  File.expand_path(@file_path)
47
43
  end
48
44
 
49
- def read_from_file
45
+ def read_from_file(&block)
50
46
  path = history_file_path
51
47
 
52
- File.foreach(path) { |line| yield(line) } if File.exist?(path)
53
- rescue StandardError => error
54
- warn "History file not loaded: #{error.message}"
48
+ File.foreach(path, &block) if File.exist?(path)
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.10.0'
4
+ VERSION = '4.19.0'
5
5
  end
data/lib/gitlab.rb CHANGED
@@ -21,11 +21,18 @@ module Gitlab
21
21
  Gitlab::Client.new(options)
22
22
  end
23
23
 
24
- # Delegate to Gitlab::Client
25
- def self.method_missing(method, *args, &block)
26
- return super unless client.respond_to?(method)
27
-
28
- client.send(method, *args, &block)
24
+ if Gem::Version.new(RUBY_VERSION).release >= Gem::Version.new('3.0.0')
25
+ def self.method_missing(method, *args, **keywargs, &block)
26
+ return super unless client.respond_to?(method)
27
+
28
+ client.send(method, *args, **keywargs, &block)
29
+ end
30
+ else
31
+ def self.method_missing(method, *args, &block)
32
+ return super unless client.respond_to?(method)
33
+
34
+ client.send(method, *args, &block)
35
+ end
29
36
  end
30
37
 
31
38
  # Delegate to Gitlab::Client
@@ -42,7 +49,8 @@ module Gitlab
42
49
  #
43
50
  # @return [Array<Symbol>]
44
51
  def self.actions
45
- hidden = /endpoint|private_token|auth_token|user_agent|sudo|get|post|put|\Adelete\z|validate|request_defaults|httparty/
52
+ hidden =
53
+ /endpoint|private_token|auth_token|user_agent|sudo|get|post|put|\Adelete\z|validate\z|request_defaults|httparty/
46
54
  (Gitlab::Client.instance_methods - Object.methods).reject { |e| e[hidden] }
47
55
  end
48
56
  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.10.0
4
+ version: 4.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nihad Abbasov
@@ -9,35 +9,26 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-02-22 00:00:00.000000000 Z
12
+ date: 2022-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: 0.14.0
21
18
  - - "~>"
22
19
  - !ruby/object:Gem::Version
23
- version: '0.14'
20
+ version: '0.20'
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- version: 0.14.0
31
25
  - - "~>"
32
26
  - !ruby/object:Gem::Version
33
- version: '0.14'
27
+ version: '0.20'
34
28
  - !ruby/object:Gem::Dependency
35
29
  name: terminal-table
36
30
  requirement: !ruby/object:Gem::Requirement
37
31
  requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.5'
41
32
  - - ">="
42
33
  - !ruby/object:Gem::Version
43
34
  version: 1.5.1
@@ -45,26 +36,9 @@ dependencies:
45
36
  prerelease: false
46
37
  version_requirements: !ruby/object:Gem::Requirement
47
38
  requirements:
48
- - - "~>"
49
- - !ruby/object:Gem::Version
50
- version: '1.5'
51
39
  - - ">="
52
40
  - !ruby/object:Gem::Version
53
41
  version: 1.5.1
54
- - !ruby/object:Gem::Dependency
55
- name: pry
56
- requirement: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '0'
61
- type: :development
62
- prerelease: false
63
- version_requirements: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: '0'
68
42
  - !ruby/object:Gem::Dependency
69
43
  name: rake
70
44
  requirement: !ruby/object:Gem::Requirement
@@ -93,20 +67,6 @@ dependencies:
93
67
  - - ">="
94
68
  - !ruby/object:Gem::Version
95
69
  version: '0'
96
- - !ruby/object:Gem::Dependency
97
- name: rubocop
98
- requirement: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: '0'
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
70
  - !ruby/object:Gem::Dependency
111
71
  name: webmock
112
72
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +100,7 @@ files:
140
100
  - lib/gitlab/cli_helpers.rb
141
101
  - lib/gitlab/client.rb
142
102
  - lib/gitlab/client/access_requests.rb
103
+ - lib/gitlab/client/application_settings.rb
143
104
  - lib/gitlab/client/avatar.rb
144
105
  - lib/gitlab/client/award_emojis.rb
145
106
  - lib/gitlab/client/boards.rb
@@ -148,23 +109,31 @@ files:
148
109
  - lib/gitlab/client/build_variables.rb
149
110
  - lib/gitlab/client/builds.rb
150
111
  - lib/gitlab/client/commits.rb
112
+ - lib/gitlab/client/container_registry.rb
151
113
  - lib/gitlab/client/deployments.rb
152
114
  - lib/gitlab/client/environments.rb
115
+ - lib/gitlab/client/epic_issues.rb
116
+ - lib/gitlab/client/epics.rb
153
117
  - lib/gitlab/client/events.rb
154
118
  - lib/gitlab/client/features.rb
119
+ - lib/gitlab/client/group_badges.rb
155
120
  - lib/gitlab/client/group_boards.rb
156
121
  - lib/gitlab/client/group_labels.rb
157
122
  - lib/gitlab/client/group_milestones.rb
158
123
  - lib/gitlab/client/groups.rb
124
+ - lib/gitlab/client/issue_links.rb
159
125
  - lib/gitlab/client/issues.rb
160
126
  - lib/gitlab/client/jobs.rb
161
127
  - lib/gitlab/client/keys.rb
162
128
  - lib/gitlab/client/labels.rb
129
+ - lib/gitlab/client/lint.rb
130
+ - lib/gitlab/client/markdown.rb
163
131
  - lib/gitlab/client/merge_request_approvals.rb
164
132
  - lib/gitlab/client/merge_requests.rb
165
133
  - lib/gitlab/client/milestones.rb
166
134
  - lib/gitlab/client/namespaces.rb
167
135
  - lib/gitlab/client/notes.rb
136
+ - lib/gitlab/client/packages.rb
168
137
  - lib/gitlab/client/pipeline_schedules.rb
169
138
  - lib/gitlab/client/pipeline_triggers.rb
170
139
  - lib/gitlab/client/pipelines.rb
@@ -174,10 +143,12 @@ files:
174
143
  - lib/gitlab/client/project_releases.rb
175
144
  - lib/gitlab/client/projects.rb
176
145
  - lib/gitlab/client/protected_tags.rb
146
+ - lib/gitlab/client/remote_mirrors.rb
177
147
  - lib/gitlab/client/repositories.rb
178
148
  - lib/gitlab/client/repository_files.rb
179
149
  - lib/gitlab/client/repository_submodules.rb
180
150
  - lib/gitlab/client/resource_label_events.rb
151
+ - lib/gitlab/client/resource_state_events.rb
181
152
  - lib/gitlab/client/runners.rb
182
153
  - lib/gitlab/client/search.rb
183
154
  - lib/gitlab/client/services.rb
@@ -187,6 +158,7 @@ files:
187
158
  - lib/gitlab/client/tags.rb
188
159
  - lib/gitlab/client/templates.rb
189
160
  - lib/gitlab/client/todos.rb
161
+ - lib/gitlab/client/user_snippets.rb
190
162
  - lib/gitlab/client/users.rb
191
163
  - lib/gitlab/client/versions.rb
192
164
  - lib/gitlab/client/wikis.rb
@@ -204,7 +176,12 @@ files:
204
176
  homepage: https://github.com/NARKOZ/gitlab
205
177
  licenses:
206
178
  - BSD-2-Clause
207
- metadata: {}
179
+ metadata:
180
+ homepage_uri: https://github.com/NARKOZ/gitlab
181
+ source_code_uri: https://github.com/NARKOZ/gitlab
182
+ bug_tracker_uri: https://github.com/NARKOZ/gitlab/issues
183
+ changelog_uri: https://github.com/NARKOZ/gitlab/releases
184
+ funding_uri: https://github.com/NARKOZ/SponsorMe
208
185
  post_install_message:
209
186
  rdoc_options: []
210
187
  require_paths:
@@ -213,14 +190,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
190
  requirements:
214
191
  - - ">="
215
192
  - !ruby/object:Gem::Version
216
- version: '2.3'
193
+ version: '2.6'
217
194
  required_rubygems_version: !ruby/object:Gem::Requirement
218
195
  requirements:
219
196
  - - ">="
220
197
  - !ruby/object:Gem::Version
221
198
  version: '0'
222
199
  requirements: []
223
- rubygems_version: 3.0.2
200
+ rubygems_version: 3.1.6
224
201
  signing_key:
225
202
  specification_version: 4
226
203
  summary: A Ruby wrapper and CLI for the GitLab API