gitlab 4.2.0 → 4.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (271) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +4 -2
  3. data/LICENSE.txt +1 -1
  4. data/README.md +96 -25
  5. data/exe/gitlab +5 -1
  6. data/lib/gitlab/api.rb +8 -3
  7. data/lib/gitlab/cli.rb +15 -15
  8. data/lib/gitlab/cli_helpers.rb +63 -61
  9. data/lib/gitlab/client/access_requests.rb +103 -0
  10. data/lib/gitlab/client/application_settings.rb +172 -0
  11. data/lib/gitlab/client/avatar.rb +21 -0
  12. data/lib/gitlab/client/award_emojis.rb +5 -3
  13. data/lib/gitlab/client/boards.rb +62 -4
  14. data/lib/gitlab/client/branches.rb +53 -14
  15. data/lib/gitlab/client/broadcast_messages.rb +75 -0
  16. data/lib/gitlab/client/build_variables.rb +78 -9
  17. data/lib/gitlab/client/builds.rb +13 -11
  18. data/lib/gitlab/client/commits.rb +89 -19
  19. data/lib/gitlab/client/container_registry.rb +85 -0
  20. data/lib/gitlab/client/deployments.rb +34 -0
  21. data/lib/gitlab/client/environments.rb +5 -3
  22. data/lib/gitlab/client/epic_issues.rb +23 -0
  23. data/lib/gitlab/client/epics.rb +73 -0
  24. data/lib/gitlab/client/events.rb +60 -0
  25. data/lib/gitlab/client/features.rb +48 -0
  26. data/lib/gitlab/client/group_badges.rb +88 -0
  27. data/lib/gitlab/client/group_boards.rb +141 -0
  28. data/lib/gitlab/client/group_labels.rb +88 -0
  29. data/lib/gitlab/client/group_milestones.rb +94 -0
  30. data/lib/gitlab/client/groups.rb +197 -17
  31. data/lib/gitlab/client/issue_links.rb +48 -0
  32. data/lib/gitlab/client/issues.rb +98 -4
  33. data/lib/gitlab/client/jobs.rb +96 -8
  34. data/lib/gitlab/client/keys.rb +13 -0
  35. data/lib/gitlab/client/labels.rb +7 -5
  36. data/lib/gitlab/client/lint.rb +19 -0
  37. data/lib/gitlab/client/markdown.rb +23 -0
  38. data/lib/gitlab/client/merge_request_approvals.rb +265 -0
  39. data/lib/gitlab/client/merge_requests.rb +237 -9
  40. data/lib/gitlab/client/milestones.rb +19 -5
  41. data/lib/gitlab/client/namespaces.rb +4 -2
  42. data/lib/gitlab/client/notes.rb +58 -12
  43. data/lib/gitlab/client/pipeline_schedules.rb +147 -0
  44. data/lib/gitlab/client/pipeline_triggers.rb +12 -10
  45. data/lib/gitlab/client/pipelines.rb +40 -3
  46. data/lib/gitlab/client/project_badges.rb +85 -0
  47. data/lib/gitlab/client/project_clusters.rb +83 -0
  48. data/lib/gitlab/client/project_release_links.rb +76 -0
  49. data/lib/gitlab/client/project_releases.rb +79 -0
  50. data/lib/gitlab/client/projects.rb +280 -47
  51. data/lib/gitlab/client/protected_tags.rb +59 -0
  52. data/lib/gitlab/client/remote_mirrors.rb +51 -0
  53. data/lib/gitlab/client/repositories.rb +60 -6
  54. data/lib/gitlab/client/repository_files.rb +23 -5
  55. data/lib/gitlab/client/repository_submodules.rb +27 -0
  56. data/lib/gitlab/client/resource_label_events.rb +82 -0
  57. data/lib/gitlab/client/resource_state_events.rb +57 -0
  58. data/lib/gitlab/client/runners.rb +111 -15
  59. data/lib/gitlab/client/search.rb +66 -0
  60. data/lib/gitlab/client/services.rb +4 -1
  61. data/lib/gitlab/client/sidekiq.rb +39 -0
  62. data/lib/gitlab/client/snippets.rb +8 -4
  63. data/lib/gitlab/client/system_hooks.rb +9 -7
  64. data/lib/gitlab/client/tags.rb +15 -14
  65. data/lib/gitlab/client/templates.rb +100 -0
  66. data/lib/gitlab/client/todos.rb +7 -5
  67. data/lib/gitlab/client/user_snippets.rb +114 -0
  68. data/lib/gitlab/client/users.rb +166 -30
  69. data/lib/gitlab/client/versions.rb +18 -0
  70. data/lib/gitlab/client/wikis.rb +79 -0
  71. data/lib/gitlab/client.rb +49 -12
  72. data/lib/gitlab/configuration.rb +8 -6
  73. data/lib/gitlab/error.rb +74 -5
  74. data/lib/gitlab/file_response.rb +5 -3
  75. data/lib/gitlab/help.rb +19 -20
  76. data/lib/gitlab/objectified_hash.rb +27 -10
  77. data/lib/gitlab/page_links.rb +11 -9
  78. data/lib/gitlab/paginated_response.rb +37 -24
  79. data/lib/gitlab/request.rb +42 -53
  80. data/lib/gitlab/shell.rb +11 -12
  81. data/lib/gitlab/shell_history.rb +11 -13
  82. data/lib/gitlab/version.rb +3 -1
  83. data/lib/gitlab.rb +19 -8
  84. metadata +50 -395
  85. data/.gitignore +0 -22
  86. data/.travis.yml +0 -8
  87. data/CONTRIBUTING.md +0 -195
  88. data/Gemfile +0 -4
  89. data/Rakefile +0 -9
  90. data/bin/console +0 -10
  91. data/bin/setup +0 -6
  92. data/gitlab.gemspec +0 -31
  93. data/spec/fixtures/board_list.json +0 -1
  94. data/spec/fixtures/board_lists.json +0 -1
  95. data/spec/fixtures/boards.json +0 -1
  96. data/spec/fixtures/branch.json +0 -1
  97. data/spec/fixtures/branch_delete.json +0 -3
  98. data/spec/fixtures/branches.json +0 -1
  99. data/spec/fixtures/build.json +0 -38
  100. data/spec/fixtures/build_artifacts.json +0 -0
  101. data/spec/fixtures/build_cancel.json +0 -24
  102. data/spec/fixtures/build_erase.json +0 -24
  103. data/spec/fixtures/build_retry.json +0 -24
  104. data/spec/fixtures/builds.json +0 -78
  105. data/spec/fixtures/builds_commits.json +0 -64
  106. data/spec/fixtures/compare_merge_request_diff.json +0 -31
  107. data/spec/fixtures/empty.json +0 -0
  108. data/spec/fixtures/environment.json +0 -6
  109. data/spec/fixtures/environments.json +0 -14
  110. data/spec/fixtures/error_already_exists.json +0 -1
  111. data/spec/fixtures/error_project_not_found.json +0 -1
  112. data/spec/fixtures/get_repository_file.json +0 -1
  113. data/spec/fixtures/group.json +0 -60
  114. data/spec/fixtures/group_create.json +0 -1
  115. data/spec/fixtures/group_create_with_description.json +0 -1
  116. data/spec/fixtures/group_delete.json +0 -1
  117. data/spec/fixtures/group_member.json +0 -1
  118. data/spec/fixtures/group_member_delete.json +0 -1
  119. data/spec/fixtures/group_member_edit.json +0 -1
  120. data/spec/fixtures/group_members.json +0 -1
  121. data/spec/fixtures/group_projects.json +0 -44
  122. data/spec/fixtures/group_search.json +0 -2
  123. data/spec/fixtures/groups.json +0 -2
  124. data/spec/fixtures/issue.json +0 -1
  125. data/spec/fixtures/issue_award_emoji.json +0 -16
  126. data/spec/fixtures/issue_award_emojis.json +0 -34
  127. data/spec/fixtures/issues.json +0 -1
  128. data/spec/fixtures/job.json +0 -43
  129. data/spec/fixtures/job_trace.json +0 -1
  130. data/spec/fixtures/jobs.json +0 -91
  131. data/spec/fixtures/key.json +0 -1
  132. data/spec/fixtures/keys.json +0 -1
  133. data/spec/fixtures/label.json +0 -1
  134. data/spec/fixtures/label_unsubscribe.json +0 -1
  135. data/spec/fixtures/labels.json +0 -1
  136. data/spec/fixtures/merge_request.json +0 -1
  137. data/spec/fixtures/merge_request_award_emoji.json +0 -16
  138. data/spec/fixtures/merge_request_award_emojis.json +0 -34
  139. data/spec/fixtures/merge_request_changes.json +0 -1
  140. data/spec/fixtures/merge_request_closes_issues.json +0 -1
  141. data/spec/fixtures/merge_request_comment.json +0 -1
  142. data/spec/fixtures/merge_request_comments.json +0 -1
  143. data/spec/fixtures/merge_request_commits.json +0 -1
  144. data/spec/fixtures/merge_requests.json +0 -1
  145. data/spec/fixtures/milestone.json +0 -1
  146. data/spec/fixtures/milestone_issues.json +0 -1
  147. data/spec/fixtures/milestone_merge_requests.json +0 -1
  148. data/spec/fixtures/milestones.json +0 -1
  149. data/spec/fixtures/namespaces.json +0 -1
  150. data/spec/fixtures/note.json +0 -1
  151. data/spec/fixtures/note_award_emoji.json +0 -16
  152. data/spec/fixtures/note_award_emojis.json +0 -18
  153. data/spec/fixtures/notes.json +0 -1
  154. data/spec/fixtures/pipeline.json +0 -23
  155. data/spec/fixtures/pipeline_cancel.json +0 -23
  156. data/spec/fixtures/pipeline_create.json +0 -23
  157. data/spec/fixtures/pipeline_jobs.json +0 -91
  158. data/spec/fixtures/pipeline_retry.json +0 -23
  159. data/spec/fixtures/pipelines.json +0 -48
  160. data/spec/fixtures/project.json +0 -1
  161. data/spec/fixtures/project_commit.json +0 -13
  162. data/spec/fixtures/project_commit_comment.json +0 -1
  163. data/spec/fixtures/project_commit_comments.json +0 -1
  164. data/spec/fixtures/project_commit_create.json +0 -22
  165. data/spec/fixtures/project_commit_diff.json +0 -10
  166. data/spec/fixtures/project_commit_status.json +0 -42
  167. data/spec/fixtures/project_commits.json +0 -1
  168. data/spec/fixtures/project_edit.json +0 -21
  169. data/spec/fixtures/project_events.json +0 -1
  170. data/spec/fixtures/project_for_user.json +0 -1
  171. data/spec/fixtures/project_fork.json +0 -50
  172. data/spec/fixtures/project_fork_link.json +0 -1
  173. data/spec/fixtures/project_forked_for_user.json +0 -50
  174. data/spec/fixtures/project_hook.json +0 -1
  175. data/spec/fixtures/project_hooks.json +0 -1
  176. data/spec/fixtures/project_issues.json +0 -1
  177. data/spec/fixtures/project_key.json +0 -6
  178. data/spec/fixtures/project_keys.json +0 -6
  179. data/spec/fixtures/project_runner_enable.json +0 -7
  180. data/spec/fixtures/project_runners.json +0 -16
  181. data/spec/fixtures/project_search.json +0 -1
  182. data/spec/fixtures/project_star.json +0 -44
  183. data/spec/fixtures/project_tag_annotated.json +0 -1
  184. data/spec/fixtures/project_tag_lightweight.json +0 -1
  185. data/spec/fixtures/project_tags.json +0 -1
  186. data/spec/fixtures/project_unstar.json +0 -44
  187. data/spec/fixtures/project_update_commit_status.json +0 -20
  188. data/spec/fixtures/projects.json +0 -1
  189. data/spec/fixtures/push_rule.json +0 -1
  190. data/spec/fixtures/raw_file.json +0 -2
  191. data/spec/fixtures/release_create.json +0 -1
  192. data/spec/fixtures/release_update.json +0 -1
  193. data/spec/fixtures/repository_file.json +0 -1
  194. data/spec/fixtures/run_trigger.json +0 -1
  195. data/spec/fixtures/runner.json +0 -26
  196. data/spec/fixtures/runner_delete.json +0 -7
  197. data/spec/fixtures/runner_edit.json +0 -26
  198. data/spec/fixtures/runners.json +0 -16
  199. data/spec/fixtures/runners_all.json +0 -30
  200. data/spec/fixtures/service.json +0 -1
  201. data/spec/fixtures/session.json +0 -1
  202. data/spec/fixtures/shell_history.json +0 -2
  203. data/spec/fixtures/snippet.json +0 -1
  204. data/spec/fixtures/snippet_award_emoji.json +0 -16
  205. data/spec/fixtures/snippet_award_emojis.json +0 -34
  206. data/spec/fixtures/snippet_content.json +0 -3
  207. data/spec/fixtures/snippets.json +0 -1
  208. data/spec/fixtures/system_hook.json +0 -1
  209. data/spec/fixtures/system_hooks.json +0 -1
  210. data/spec/fixtures/tag.json +0 -1
  211. data/spec/fixtures/tag_create.json +0 -1
  212. data/spec/fixtures/tag_create_with_description.json +0 -1
  213. data/spec/fixtures/tag_delete.json +0 -1
  214. data/spec/fixtures/tags.json +0 -1
  215. data/spec/fixtures/team_member.json +0 -1
  216. data/spec/fixtures/team_members.json +0 -1
  217. data/spec/fixtures/todo.json +0 -73
  218. data/spec/fixtures/todos.json +0 -148
  219. data/spec/fixtures/tree.json +0 -1
  220. data/spec/fixtures/trigger.json +0 -10
  221. data/spec/fixtures/triggers.json +0 -12
  222. data/spec/fixtures/user.json +0 -1
  223. data/spec/fixtures/user_block_unblock.json +0 -1
  224. data/spec/fixtures/user_email.json +0 -1
  225. data/spec/fixtures/user_emails.json +0 -1
  226. data/spec/fixtures/user_search.json +0 -1
  227. data/spec/fixtures/users.json +0 -1
  228. data/spec/fixtures/variable.json +0 -4
  229. data/spec/fixtures/variables.json +0 -10
  230. data/spec/gitlab/cli_helpers_spec.rb +0 -57
  231. data/spec/gitlab/cli_spec.rb +0 -119
  232. data/spec/gitlab/client/award_emojis_spec.rb +0 -391
  233. data/spec/gitlab/client/boards_spec.rb +0 -94
  234. data/spec/gitlab/client/branches_spec.rb +0 -116
  235. data/spec/gitlab/client/build_variables_spec.rb +0 -86
  236. data/spec/gitlab/client/builds_spec.rb +0 -148
  237. data/spec/gitlab/client/client_spec.rb +0 -11
  238. data/spec/gitlab/client/commits_spec.rb +0 -168
  239. data/spec/gitlab/client/environments_spec.rb +0 -132
  240. data/spec/gitlab/client/groups_spec.rb +0 -195
  241. data/spec/gitlab/client/issues_spec.rb +0 -186
  242. data/spec/gitlab/client/jobs_spec.rb +0 -135
  243. data/spec/gitlab/client/keys_spec.rb +0 -19
  244. data/spec/gitlab/client/labels_spec.rb +0 -100
  245. data/spec/gitlab/client/merge_requests_spec.rb +0 -224
  246. data/spec/gitlab/client/milestones_spec.rb +0 -98
  247. data/spec/gitlab/client/namespaces_spec.rb +0 -22
  248. data/spec/gitlab/client/notes_spec.rb +0 -333
  249. data/spec/gitlab/client/pipeline_triggers_spec.rb +0 -157
  250. data/spec/gitlab/client/pipelines_spec.rb +0 -95
  251. data/spec/gitlab/client/projects_spec.rb +0 -613
  252. data/spec/gitlab/client/repositories_spec.rb +0 -94
  253. data/spec/gitlab/client/repository_files_spec.rb +0 -95
  254. data/spec/gitlab/client/runners_spec.rb +0 -185
  255. data/spec/gitlab/client/services_spec.rb +0 -55
  256. data/spec/gitlab/client/snippets_spec.rb +0 -100
  257. data/spec/gitlab/client/system_hooks_spec.rb +0 -69
  258. data/spec/gitlab/client/tags_spec.rb +0 -109
  259. data/spec/gitlab/client/todos_spec.rb +0 -45
  260. data/spec/gitlab/client/users_spec.rb +0 -418
  261. data/spec/gitlab/error_spec.rb +0 -45
  262. data/spec/gitlab/file_response_spec.rb +0 -33
  263. data/spec/gitlab/help_spec.rb +0 -46
  264. data/spec/gitlab/objectified_hash_spec.rb +0 -48
  265. data/spec/gitlab/page_links_spec.rb +0 -16
  266. data/spec/gitlab/paginated_response_spec.rb +0 -60
  267. data/spec/gitlab/request_spec.rb +0 -73
  268. data/spec/gitlab/shell_history_spec.rb +0 -53
  269. data/spec/gitlab/shell_spec.rb +0 -80
  270. data/spec/gitlab_spec.rb +0 -97
  271. data/spec/spec_helper.rb +0 -74
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'httparty'
2
4
  require 'json'
3
5
 
@@ -6,8 +8,9 @@ module Gitlab
6
8
  class Request
7
9
  include HTTParty
8
10
  format :json
11
+ maintain_method_across_redirects true
9
12
  headers 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'
10
- parser proc { |body, _| parse(body) }
13
+ parser(proc { |body, _| parse(body) })
11
14
 
12
15
  attr_accessor :private_token, :endpoint
13
16
 
@@ -23,61 +26,49 @@ module Gitlab
23
26
  true
24
27
  elsif !body
25
28
  false
26
- elsif body.nil?
27
- false
28
29
  else
29
- raise Error::Parsing.new "Couldn't parse a response body"
30
+ raise Error::Parsing, "Couldn't parse a response body"
30
31
  end
31
32
  end
32
33
 
33
34
  # Decodes a JSON response into Ruby object.
34
35
  def self.decode(response)
35
- JSON.load response
36
+ response ? JSON.load(response) : {}
36
37
  rescue JSON::ParserError
37
- raise Error::Parsing.new "The response is not a valid JSON"
38
+ raise Error::Parsing, 'The response is not a valid JSON'
38
39
  end
39
40
 
40
- def get(path, options={})
41
- set_httparty_config(options)
42
- set_authorization_header(options)
43
- validate self.class.get(@endpoint + path, options)
44
- end
41
+ %w[get post put delete].each do |method|
42
+ define_method method do |path, options = {}|
43
+ params = options.dup
45
44
 
46
- def post(path, options={})
47
- set_httparty_config(options)
48
- set_authorization_header(options)
49
- validate self.class.post(@endpoint + path, options)
50
- end
45
+ httparty_config(params)
51
46
 
52
- def put(path, options={})
53
- set_httparty_config(options)
54
- set_authorization_header(options)
55
- validate self.class.put(@endpoint + path, options)
56
- end
47
+ unless params[:unauthenticated]
48
+ params[:headers] ||= {}
49
+ params[:headers].merge!(authorization_header)
50
+ end
57
51
 
58
- def delete(path, options={})
59
- set_httparty_config(options)
60
- set_authorization_header(options)
61
- validate self.class.delete(@endpoint + path, options)
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
64
+ end
62
65
  end
63
66
 
64
67
  # Checks the response code for common errors.
65
68
  # Returns parsed response for successful requests.
66
69
  def validate(response)
67
- error_klass = case response.code
68
- when 400 then Error::BadRequest
69
- when 401 then Error::Unauthorized
70
- when 403 then Error::Forbidden
71
- when 404 then Error::NotFound
72
- when 405 then Error::MethodNotAllowed
73
- when 409 then Error::Conflict
74
- when 422 then Error::Unprocessable
75
- when 500 then Error::InternalServerError
76
- when 502 then Error::BadGateway
77
- when 503 then Error::ServiceUnavailable
78
- end
79
-
80
- fail error_klass.new(response) if error_klass
70
+ error_klass = Error::STATUS_MAPPINGS[response.code]
71
+ raise error_klass, response if error_klass
81
72
 
82
73
  parsed = response.parsed_response
83
74
  parsed.client = self if parsed.respond_to?(:client=)
@@ -87,33 +78,31 @@ module Gitlab
87
78
 
88
79
  # Sets a base_uri and default_params for requests.
89
80
  # @raise [Error::MissingCredentials] if endpoint not set.
90
- def set_request_defaults(sudo=nil)
81
+ def request_defaults(sudo = nil)
82
+ raise Error::MissingCredentials, 'Please set an endpoint to API' unless endpoint
83
+
91
84
  self.class.default_params sudo: sudo
92
- raise Error::MissingCredentials.new("Please set an endpoint to API") unless @endpoint
93
85
  self.class.default_params.delete(:sudo) if sudo.nil?
94
86
  end
95
87
 
96
88
  private
97
89
 
98
- # Sets a PRIVATE-TOKEN or Authorization header for requests.
90
+ # Returns an Authorization header hash
99
91
  #
100
- # @param [Hash] options A customizable set of options.
101
- # @option options [Boolean] :unauthenticated true if the API call does not require user authentication.
102
92
  # @raise [Error::MissingCredentials] if private_token and auth_token are not set.
103
- def set_authorization_header(options)
104
- unless options[:unauthenticated]
105
- raise Error::MissingCredentials.new("Please provide a private_token or auth_token for user") unless @private_token
106
- if @private_token.length <= 20
107
- options[:headers] = { 'PRIVATE-TOKEN' => @private_token }
108
- else
109
- options[:headers] = { 'Authorization' => "Bearer #{@private_token}" }
110
- 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}" }
111
100
  end
112
101
  end
113
102
 
114
103
  # Set HTTParty configuration
115
104
  # @see https://github.com/jnunemaker/httparty
116
- def set_httparty_config(options)
105
+ def httparty_config(options)
117
106
  options.merge!(httparty) if httparty
118
107
  end
119
108
  end
data/lib/gitlab/shell.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'gitlab'
2
4
  require 'gitlab/help'
3
5
  require 'gitlab/cli_helpers'
@@ -15,7 +17,7 @@ class Gitlab::Shell
15
17
  trap('INT') { quit_shell } # capture ctrl-c
16
18
  setup
17
19
 
18
- while buffer = Readline.readline('gitlab> ')
20
+ while (buffer = Readline.readline('gitlab> '))
19
21
  begin
20
22
  parse_input buffer
21
23
 
@@ -34,7 +36,7 @@ class Gitlab::Shell
34
36
  data = execute command, arguments
35
37
  output_table command, arguments, data
36
38
  end
37
- rescue => e
39
+ rescue StandardError => e
38
40
  puts e.message
39
41
  end
40
42
  end
@@ -46,7 +48,7 @@ class Gitlab::Shell
46
48
  buf = Shellwords.shellwords(buffer)
47
49
 
48
50
  @command = buf.shift
49
- @arguments = buf.count > 0 ? buf : []
51
+ @arguments = buf.count.positive? ? buf : []
50
52
  end
51
53
 
52
54
  def setup
@@ -62,14 +64,11 @@ class Gitlab::Shell
62
64
  end
63
65
 
64
66
  # Execute a given command with arguements
65
- def execute(cmd=command, args=arguments)
66
- if actions.include?(cmd.to_sym)
67
- confirm_command(cmd)
68
- gitlab_helper(cmd, args)
69
- else
70
- fail "Unknown command: #{cmd}. " \
71
- "See the 'help' for a list of valid commands."
72
- end
67
+ def execute(cmd = command, args = arguments)
68
+ raise "Unknown command: #{cmd}. See the 'help' for a list of valid commands." unless actions.include?(cmd.to_sym)
69
+
70
+ confirm_command(cmd)
71
+ gitlab_helper(cmd, args)
73
72
  end
74
73
 
75
74
  def quit_shell
@@ -80,5 +79,5 @@ class Gitlab::Shell
80
79
  def history
81
80
  @history ||= History.new
82
81
  end
83
- end # class << self
82
+ end
84
83
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Gitlab::Shell
2
4
  class History
3
5
  DEFAULT_HISTFILESIZE = 200
4
6
  DEFAULT_FILE_PATH = File.join(Dir.home, '.gitlab_shell_history')
5
7
 
6
- def initialize(options={})
8
+ def initialize(options = {})
7
9
  @file_path = options[:file_path] || DEFAULT_FILE_PATH
8
10
  Readline::HISTORY.clear
9
11
  end
@@ -13,13 +15,13 @@ class Gitlab::Shell
13
15
  end
14
16
 
15
17
  def save
16
- lines.each { |line| history_file.puts line if history_file }
18
+ lines.each { |line| history_file&.puts line }
17
19
  end
18
20
 
19
21
  def push(line)
20
22
  Readline::HISTORY << line
21
23
  end
22
- alias_method :<<, :push
24
+ alias << push
23
25
 
24
26
  def lines
25
27
  Readline::HISTORY.to_a.last(max_lines)
@@ -28,12 +30,8 @@ class Gitlab::Shell
28
30
  private
29
31
 
30
32
  def history_file
31
- if defined?(@history_file)
32
- @history_file
33
- else
34
- @history_file = File.open(history_file_path, 'w', 0600).tap do |file|
35
- file.sync = true
36
- end
33
+ @history_file ||= File.open(history_file_path, 'w', 0o600).tap do |file|
34
+ file.sync = true
37
35
  end
38
36
  rescue Errno::EACCES
39
37
  warn 'History not saved; unable to open your history file for writing.'
@@ -44,12 +42,12 @@ class Gitlab::Shell
44
42
  File.expand_path(@file_path)
45
43
  end
46
44
 
47
- def read_from_file
45
+ def read_from_file(&block)
48
46
  path = history_file_path
49
47
 
50
- File.foreach(path) { |line| yield(line) } if File.exist?(path)
51
- rescue => error
52
- 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}"
53
51
  end
54
52
 
55
53
  def max_lines
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
- VERSION = "4.2.0"
4
+ VERSION = '4.18.0'
3
5
  end
data/lib/gitlab.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'gitlab/version'
2
4
  require 'gitlab/objectified_hash'
3
5
  require 'gitlab/configuration'
@@ -15,23 +17,31 @@ module Gitlab
15
17
  # Alias for Gitlab::Client.new
16
18
  #
17
19
  # @return [Gitlab::Client]
18
- def self.client(options={})
20
+ def self.client(options = {})
19
21
  Gitlab::Client.new(options)
20
22
  end
21
23
 
22
- # Delegate to Gitlab::Client
23
- def self.method_missing(method, *args, &block)
24
- return super unless client.respond_to?(method)
25
- 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
26
36
  end
27
37
 
28
38
  # Delegate to Gitlab::Client
29
- def respond_to_missing?(method_name, include_private = false)
39
+ def self.respond_to_missing?(method_name, include_private = false)
30
40
  client.respond_to?(method_name) || super
31
41
  end
32
42
 
33
43
  # Delegate to HTTParty.http_proxy
34
- def self.http_proxy(address=nil, port=nil, username=nil, password=nil)
44
+ def self.http_proxy(address = nil, port = nil, username = nil, password = nil)
35
45
  Gitlab::Request.http_proxy(address, port, username, password)
36
46
  end
37
47
 
@@ -39,7 +49,8 @@ module Gitlab
39
49
  #
40
50
  # @return [Array<Symbol>]
41
51
  def self.actions
42
- hidden = /endpoint|private_token|auth_token|user_agent|sudo|get|post|put|\Adelete\z|validate|set_request_defaults|httparty/
52
+ hidden =
53
+ /endpoint|private_token|auth_token|user_agent|sudo|get|post|put|\Adelete\z|validate\z|request_defaults|httparty/
43
54
  (Gitlab::Client.instance_methods - Object.methods).reject { |e| e[hidden] }
44
55
  end
45
56
  end