gitlab 4.5.0 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/stale.yml +18 -0
  3. data/.rubocop_todo.yml +46 -0
  4. data/Gemfile +2 -0
  5. data/README.md +22 -22
  6. data/Rakefile +3 -5
  7. data/bin/console +1 -0
  8. data/exe/gitlab +5 -1
  9. data/gitlab.gemspec +9 -6
  10. data/lib/gitlab.rb +6 -3
  11. data/lib/gitlab/api.rb +5 -3
  12. data/lib/gitlab/cli.rb +11 -5
  13. data/lib/gitlab/cli_helpers.rb +31 -22
  14. data/lib/gitlab/client.rb +7 -8
  15. data/lib/gitlab/client/access_requests.rb +100 -93
  16. data/lib/gitlab/client/award_emojis.rb +127 -127
  17. data/lib/gitlab/client/boards.rb +82 -82
  18. data/lib/gitlab/client/branches.rb +89 -89
  19. data/lib/gitlab/client/build_variables.rb +117 -117
  20. data/lib/gitlab/client/builds.rb +98 -98
  21. data/lib/gitlab/client/commits.rb +154 -154
  22. data/lib/gitlab/client/deployments.rb +29 -29
  23. data/lib/gitlab/client/environments.rb +80 -80
  24. data/lib/gitlab/client/events.rb +54 -54
  25. data/lib/gitlab/client/group_milestones.rb +85 -86
  26. data/lib/gitlab/client/groups.rb +178 -178
  27. data/lib/gitlab/client/issues.rb +195 -196
  28. data/lib/gitlab/client/jobs.rb +150 -150
  29. data/lib/gitlab/client/keys.rb +14 -14
  30. data/lib/gitlab/client/labels.rb +79 -79
  31. data/lib/gitlab/client/merge_request_approvals.rb +102 -102
  32. data/lib/gitlab/client/merge_requests.rb +281 -256
  33. data/lib/gitlab/client/milestones.rb +85 -85
  34. data/lib/gitlab/client/namespaces.rb +18 -18
  35. data/lib/gitlab/client/notes.rb +260 -260
  36. data/lib/gitlab/client/pipeline_schedules.rb +123 -123
  37. data/lib/gitlab/client/pipeline_triggers.rb +93 -93
  38. data/lib/gitlab/client/pipelines.rb +62 -62
  39. data/lib/gitlab/client/projects.rb +526 -505
  40. data/lib/gitlab/client/repositories.rb +68 -55
  41. data/lib/gitlab/client/repository_files.rb +103 -103
  42. data/lib/gitlab/client/runners.rb +113 -115
  43. data/lib/gitlab/client/services.rb +46 -45
  44. data/lib/gitlab/client/sidekiq.rb +32 -32
  45. data/lib/gitlab/client/snippets.rb +86 -86
  46. data/lib/gitlab/client/system_hooks.rb +57 -57
  47. data/lib/gitlab/client/tags.rb +87 -88
  48. data/lib/gitlab/client/todos.rb +41 -41
  49. data/lib/gitlab/client/users.rb +242 -228
  50. data/lib/gitlab/client/versions.rb +16 -0
  51. data/lib/gitlab/configuration.rb +7 -5
  52. data/lib/gitlab/error.rb +3 -1
  53. data/lib/gitlab/file_response.rb +4 -2
  54. data/lib/gitlab/help.rb +9 -9
  55. data/lib/gitlab/objectified_hash.rb +5 -4
  56. data/lib/gitlab/page_links.rb +9 -7
  57. data/lib/gitlab/paginated_response.rb +14 -4
  58. data/lib/gitlab/request.rb +8 -5
  59. data/lib/gitlab/shell.rb +6 -4
  60. data/lib/gitlab/shell_history.rb +7 -5
  61. data/lib/gitlab/version.rb +3 -1
  62. metadata +8 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4709e421064af0cf5367a459989920ad1e88d324dbb01437f5bf70673f7b3e98
4
- data.tar.gz: 0d3242640c2f27ee04607b5dcd2e78b9e6e38f4c49d107d5217306abbb00ff81
3
+ metadata.gz: c2abe85ce03f9110e9d7c55e516487e125898a960de1c8f69ce752b12851a026
4
+ data.tar.gz: 9bda4675dc3a8e1c408ba68c366a14855f4456660001bff17bba98f06de9ca42
5
5
  SHA512:
6
- metadata.gz: 9d5bd203c61aca2526b0c378333c3e5a003e33eedaf3e592d88270ce86c4daa1742c14cce45d35e3c4d5e1dd4dcd3eee00daa64c533fa3fbd95cbc1bdddac5a6
7
- data.tar.gz: 947dc65cf181b02049ca052a04e9f42f68c2ca0387da7cbe36151590b7fee9e64afa6a726eda0e8ed91eae540f22e0c192c5cc6af353c05e64e5aaf9d60ba6fa
6
+ metadata.gz: be06faf90e256343833177899f3064af39042cb7e299364f499cc29a0d903b62219d0dc80cf8588b956a424c43f01d58d28fd7bdba69609b5cf3c23a495f44f0
7
+ data.tar.gz: 412245730f19b0adc1f4fff19dd0e39373f7810ec00991e0303bf3287ac3f5d6b0dc2d132af93a09a272b254dc4c73fdadd29b2926e9e1761f55f66f4ef75f5e
@@ -0,0 +1,18 @@
1
+ # Number of days of inactivity before an issue becomes stale
2
+ daysUntilStale: 90
3
+ # Number of days of inactivity before a stale issue is closed
4
+ daysUntilClose: 10
5
+ # Issues with these labels will never be considered stale
6
+ exemptLabels:
7
+ - pinned
8
+ - security
9
+ - contribution welcome
10
+ # Label to use when marking an issue as stale
11
+ staleLabel: stale
12
+ # Comment to post when marking an issue as stale. Set to `false` to disable
13
+ markComment: >
14
+ This issue has been automatically marked as stale because it has not had
15
+ recent activity. It will be closed if no further activity occurs. Thank you
16
+ for your contributions.
17
+ # Comment to post when closing a stale issue. Set to `false` to disable
18
+ closeComment: false
@@ -0,0 +1,46 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-10-10 10:25:27 +0400 using RuboCop version 0.59.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Lint/UriEscapeUnescape:
11
+ Exclude:
12
+ - 'lib/gitlab/client.rb'
13
+
14
+ # Offense count: 5
15
+ Metrics/AbcSize:
16
+ Max: 34
17
+
18
+ # Offense count: 4
19
+ Metrics/CyclomaticComplexity:
20
+ Max: 14
21
+
22
+ # Offense count: 10
23
+ # Configuration parameters: CountComments, ExcludedMethods.
24
+ Metrics/MethodLength:
25
+ Max: 34
26
+
27
+ # Offense count: 2
28
+ # Configuration parameters: CountComments.
29
+ Metrics/ModuleLength:
30
+ Max: 165
31
+
32
+ # Offense count: 2
33
+ # Configuration parameters: CountKeywordArgs.
34
+ Metrics/ParameterLists:
35
+ Max: 6
36
+
37
+ # Offense count: 1
38
+ Metrics/PerceivedComplexity:
39
+ Max: 10
40
+
41
+ # Offense count: 1
42
+ # Cop supports --auto-correct.
43
+ # Configuration parameters: AutoCorrect.
44
+ Security/JSONLoad:
45
+ Exclude:
46
+ - 'lib/gitlab/request.rb'
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in gitlab.gemspec
data/README.md CHANGED
@@ -1,17 +1,17 @@
1
1
  # Gitlab
2
2
 
3
3
  [![Build Status](https://img.shields.io/travis/NARKOZ/gitlab.svg)](https://travis-ci.org/NARKOZ/gitlab)
4
- [![Code Climate](https://img.shields.io/codeclimate/maintainability/NARKOZ/gitlab.svg)](https://codeclimate.com/github/NARKOZ/gitlab)
5
- [![Inline docs](http://inch-ci.org/github/NARKOZ/gitlab.svg)](https://inch-ci.org/github/NARKOZ/gitlab)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/2e310b334b1b5db4a7e1/maintainability)](https://codeclimate.com/github/NARKOZ/gitlab)
5
+ [![Inline docs](https://inch-ci.org/github/NARKOZ/gitlab.svg)](https://inch-ci.org/github/NARKOZ/gitlab)
6
6
  [![Gem version](https://img.shields.io/gem/v/gitlab.svg)](https://rubygems.org/gems/gitlab)
7
7
  [![License](https://img.shields.io/badge/license-BSD-red.svg)](https://github.com/NARKOZ/gitlab/blob/master/LICENSE.txt)
8
8
 
9
- [website](http://narkoz.github.io/gitlab) |
10
- [documentation](http://rubydoc.info/gems/gitlab/frames) |
9
+ [website](https://narkoz.github.io/gitlab) |
10
+ [documentation](https://rubydoc.info/gems/gitlab/frames) |
11
11
  [gitlab-live](https://github.com/NARKOZ/gitlab-live)
12
12
 
13
13
  Gitlab is a Ruby wrapper and CLI for the [GitLab API](https://docs.gitlab.com/ce/api/README.html).
14
- As of version `4.0.0` this gem only supports Ruby 2.0+ and Gitlab API v4.
14
+ As of version `4.0.0` this gem only supports Ruby 2.0+ and GitLab API v4.
15
15
 
16
16
  ## Installation
17
17
 
@@ -54,8 +54,8 @@ Usage examples:
54
54
 
55
55
  ```ruby
56
56
  # set an API endpoint
57
- Gitlab.endpoint = 'http://example.net/api/v4'
58
- # => "http://example.net/api/v4"
57
+ Gitlab.endpoint = 'https://example.net/api/v4'
58
+ # => "https://example.net/api/v4"
59
59
 
60
60
  # set a user private token
61
61
  Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG'
@@ -63,7 +63,7 @@ Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG'
63
63
 
64
64
  # configure a proxy server
65
65
  Gitlab.http_proxy('proxyhost', 8888)
66
- # proxy server w/ basic auth
66
+ # proxy server with basic auth
67
67
  Gitlab.http_proxy('proxyhost', 8888, 'proxyuser', 'strongpasswordhere')
68
68
 
69
69
  # list projects
@@ -108,11 +108,11 @@ end
108
108
  projects.auto_paginate
109
109
  ```
110
110
 
111
- For more information, refer to [documentation](http://rubydoc.info/gems/gitlab/frames).
111
+ For more information, refer to [documentation](https://rubydoc.info/gems/gitlab/frames).
112
112
 
113
113
  ## CLI
114
114
 
115
- It is possible to use this gem as a command line interface to gitlab. In order to make that work you need to set a few environment variables:
115
+ It is possible to use this gem as a command line interface to GitLab. In order to make that work you need to set a few environment variables:
116
116
  ```sh
117
117
  export GITLAB_API_ENDPOINT=https://gitlab.yourcompany.com/api/v4
118
118
  export GITLAB_API_PRIVATE_TOKEN=<your private token from /profile/account>
@@ -124,21 +124,21 @@ export GITLAB_API_HTTPARTY_OPTIONS="{verify: false}"
124
124
 
125
125
  Usage:
126
126
 
127
- When you want to know which CLI commands are supported, take a look at the client [commands implemented in this gem](http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client). Any of those methods can be called as a command by passing the parameters of the commands as parameters of the CLI.
127
+ When you want to know which CLI commands are supported, take a look at the client [commands implemented in this gem](https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client). Any of those methods can be called as a command by passing the parameters of the commands as parameters of the CLI.
128
128
 
129
129
  Usage examples:
130
130
 
131
131
  ```sh
132
132
  # list users
133
- # see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#users-instance_method
133
+ # see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#users-instance_method
134
134
  gitlab users
135
135
 
136
136
  # get current user
137
- # see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method
137
+ # see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#user-instance_method
138
138
  gitlab user
139
139
 
140
140
  # get a user
141
- # see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method
141
+ # see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#user-instance_method
142
142
  gitlab user 2
143
143
 
144
144
  # filter output
@@ -150,7 +150,7 @@ gitlab user --except=email,bio
150
150
  gitlab user 2 --json
151
151
 
152
152
  # passing options hash to a command (use YAML)
153
- # see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method
153
+ # see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method
154
154
  gitlab create_merge_request 4 "New merge request" "{source_branch: 'new_branch', target_branch: 'master', assignee_id: 42}"
155
155
 
156
156
  ```
@@ -177,17 +177,17 @@ gitlab> create_merge_request 4 "New merge request" "{source_branch: 'new_branch'
177
177
  ```
178
178
 
179
179
  Web version is available at https://gitlab-live.herokuapp.com
180
- For more information, refer to [website](http://narkoz.github.io/gitlab).
180
+ For more information, refer to [website](https://narkoz.github.io/gitlab).
181
181
 
182
182
  ## Development
183
183
 
184
- ### With a dockerized Gitlab instance
184
+ ### With a dockerized GitLab instance
185
185
 
186
186
  ```shell
187
- docker-compose up -d gitlab # Will start the gitlab instance in the background (approx. 3 minutes)
187
+ docker-compose up -d gitlab # Will start the GitLab instance in the background (approx. 3 minutes)
188
188
  ```
189
189
 
190
- After a while, your Gitlab instance will be accessible on http://localhost:3000.
190
+ After a while, your GitLab instance will be accessible on http://localhost:3000.
191
191
 
192
192
  Once you have set your new root password, you can login with the root user.
193
193
 
@@ -206,17 +206,17 @@ Gitlab.users
206
206
  => [#<Gitlab::ObjectifiedHash:47231290771040 {hash: {"id"=>1, "name"=>"Administrator", "username"=>"root", ...]
207
207
  ```
208
208
 
209
- To launch the specs,
209
+ To launch the specs:
210
210
 
211
211
  ```shell
212
212
  docker-compose run app rake spec
213
213
  ```
214
214
 
215
- #### Want to use Gitlab Enterprise?
215
+ #### Want to use GitLab Enterprise?
216
216
 
217
217
  Just change the image from `gitlab/gitlab-ce:latest` to `gitlab/gitlab-ee:latest` in the `docker-compose.yml` file.
218
218
 
219
- ### With an external Gitlab instance
219
+ ### With an external GitLab instance
220
220
 
221
221
  First, set the variables to the correct values in the `docker.env` file.
222
222
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
 
3
5
  require 'rspec/core/rake_task'
@@ -10,8 +12,4 @@ RuboCop::RakeTask.new(:rubocop) do |task|
10
12
  task.options = ['-D', '--parallel']
11
13
  end
12
14
 
13
- if ENV['TRAVIS_CI_RUBOCOP']
14
- task default: :rubocop
15
- else
16
- task default: :spec
17
- end
15
+ task default: :spec
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  # ENV['GITLAB_API_ENDPOINT'] = ''
4
5
  # ENV['GITLAB_API_PRIVATE_TOKEN'] = ''
data/exe/gitlab CHANGED
@@ -1,6 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
5
+
6
+ # Exit cleanly from an early interrupt
7
+ Signal.trap('INT') { exit 1 }
4
8
 
5
9
  require 'gitlab/cli'
6
10
 
@@ -1,4 +1,6 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'gitlab/version'
4
6
 
@@ -11,16 +13,17 @@ Gem::Specification.new do |gem|
11
13
  gem.summary = 'A Ruby wrapper and CLI for the GitLab API'
12
14
  gem.homepage = 'https://github.com/narkoz/gitlab'
13
15
 
14
- gem.files = `git ls-files`.split($/).
15
- reject { |f| f[/^spec/] } -
16
- %w[Dockerfile docker-compose.yml docker.env .travis.yml .rubocop.yml .dockerignore]
16
+ gem.files = `git ls-files`.split($/)
17
+ .grep_v(/^spec/) -
18
+ %w[Dockerfile docker-compose.yml docker.env .travis.yml
19
+ .rubocop.yml .dockerignore]
17
20
  gem.bindir = 'exe'
18
21
  gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
22
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
23
  gem.require_paths = ['lib']
21
24
  gem.license = 'BSD'
22
25
 
23
- gem.required_ruby_version = '>= 2.0.0'
26
+ gem.required_ruby_version = '>= 2.3'
24
27
 
25
28
  gem.add_runtime_dependency 'httparty', '>= 0.14.0'
26
29
  gem.add_runtime_dependency 'terminal-table', '>= 1.5.1'
@@ -28,6 +31,6 @@ Gem::Specification.new do |gem|
28
31
  gem.add_development_dependency 'pry'
29
32
  gem.add_development_dependency 'rake'
30
33
  gem.add_development_dependency 'rspec'
31
- gem.add_development_dependency 'webmock'
32
34
  gem.add_development_dependency 'rubocop'
35
+ gem.add_development_dependency 'webmock'
33
36
  end
@@ -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,24 @@ 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
24
  # Delegate to Gitlab::Client
23
25
  def self.method_missing(method, *args, &block)
24
26
  return super unless client.respond_to?(method)
27
+
25
28
  client.send(method, *args, &block)
26
29
  end
27
30
 
28
31
  # Delegate to Gitlab::Client
29
- def self.respond_to_missing?(method_name, include_private=false)
32
+ def self.respond_to_missing?(method_name, include_private = false)
30
33
  client.respond_to?(method_name) || super
31
34
  end
32
35
 
33
36
  # Delegate to HTTParty.http_proxy
34
- def self.http_proxy(address=nil, port=nil, username=nil, password=nil)
37
+ def self.http_proxy(address = nil, port = nil, username = nil, password = nil)
35
38
  Gitlab::Request.http_proxy(address, port, username, password)
36
39
  end
37
40
 
@@ -1,19 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  # @private
3
5
  class API < Request
4
6
  # @private
5
7
  attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
6
8
  # @private
7
- alias_method :auth_token=, :private_token=
9
+ alias auth_token= private_token=
8
10
 
9
11
  # Creates a new API.
10
12
  # @raise [Error:MissingCredentials]
11
- def initialize(options={})
13
+ def initialize(options = {})
12
14
  options = Gitlab.options.merge(options)
13
15
  (Configuration::VALID_OPTIONS_KEYS + [:auth_token]).each do |key|
14
16
  send("#{key}=", options[key]) if options[key]
15
17
  end
16
- request_defaults(@sudo)
18
+ request_defaults(sudo)
17
19
  self.class.headers 'User-Agent' => user_agent
18
20
  end
19
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'gitlab'
2
4
  require 'terminal-table/import'
3
5
  require_relative 'cli_helpers'
@@ -17,7 +19,11 @@ class Gitlab::CLI
17
19
  #
18
20
  # @param [Array] args The command and it's optional arguments.
19
21
  def self.start(args)
20
- command = args.shift.strip rescue 'help'
22
+ command = begin
23
+ args.shift.strip
24
+ rescue StandardError
25
+ 'help'
26
+ end
21
27
  run(command, args)
22
28
  end
23
29
 
@@ -30,13 +36,13 @@ class Gitlab::CLI
30
36
  # @param [String] cmd The name of a command.
31
37
  # @param [Array] args The optional arguments for a command.
32
38
  # @return [nil]
33
- def self.run(cmd, args=[])
39
+ def self.run(cmd, args = [])
34
40
  case cmd
35
41
  when 'help'
36
42
  puts help(args.shift) { |out| out.gsub!(/Gitlab\./, 'gitlab ') }
37
43
  when 'info'
38
- endpoint = Gitlab.endpoint ? Gitlab.endpoint : 'not set'
39
- private_token = Gitlab.private_token ? Gitlab.private_token : 'not set'
44
+ endpoint = Gitlab.endpoint || 'not set'
45
+ private_token = Gitlab.private_token || 'not set'
40
46
  puts "Gitlab endpoint is #{endpoint}"
41
47
  puts "Gitlab private token is #{private_token}"
42
48
  puts "Ruby Version is #{RUBY_VERSION}"
@@ -60,7 +66,7 @@ class Gitlab::CLI
60
66
 
61
67
  begin
62
68
  command_args.map! { |arg| symbolize_keys(yaml_load(arg)) }
63
- rescue => e
69
+ rescue StandardError => e
64
70
  puts e.message
65
71
  exit 1
66
72
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'json'
3
5
  require 'base64'
@@ -5,7 +7,7 @@ require 'base64'
5
7
  class Gitlab::CLI
6
8
  # Defines methods related to CLI output and formatting.
7
9
  module Helpers
8
- extend self
10
+ module_function
9
11
 
10
12
  # Returns actions available to CLI & Shell
11
13
  #
@@ -71,7 +73,7 @@ class Gitlab::CLI
71
73
 
72
74
  puts 'Are you sure? (y/n)'
73
75
 
74
- if %w(y yes).include?($stdin.gets.to_s.strip.downcase)
76
+ if %w[y yes].include?($stdin.gets.to_s.strip.downcase)
75
77
  puts 'Proceeding..'
76
78
  else
77
79
  puts 'Command aborted.'
@@ -82,7 +84,7 @@ class Gitlab::CLI
82
84
  # Gets defined help for a specific command/action.
83
85
  #
84
86
  # @return [String]
85
- def help(cmd=nil, &block)
87
+ def help(cmd = nil, &block)
86
88
  if cmd.nil? || Gitlab::Help.help_map.key?(cmd)
87
89
  Gitlab::Help.actions_table(cmd)
88
90
  else
@@ -90,14 +92,14 @@ class Gitlab::CLI
90
92
  end
91
93
  end
92
94
 
93
- # Outputs a nicely formatted table or error msg.
95
+ # Outputs a nicely formatted table or error message.
94
96
  def output_table(cmd, args, data)
95
97
  case data
96
98
  when Gitlab::ObjectifiedHash, Gitlab::FileResponse
97
99
  puts record_table([data], cmd, args)
98
100
  when Gitlab::PaginatedResponse
99
101
  puts record_table(data, cmd, args)
100
- else # probably just an error msg
102
+ else # probably just an error message
101
103
  puts data
102
104
  end
103
105
  end
@@ -159,7 +161,7 @@ class Gitlab::CLI
159
161
  # @param [Array] args Options passed to the API call
160
162
  # @param [bool] single_value If set to true, a single result should be returned
161
163
  # @return [Hash] Result hash
162
- def record_hash(data, cmd, args, single_value=false)
164
+ def record_hash(data, cmd, args, single_value = false)
163
165
  if data.empty?
164
166
  result = nil
165
167
  else
@@ -169,21 +171,21 @@ class Gitlab::CLI
169
171
  row = {}
170
172
 
171
173
  keys.each do |key|
172
- case hash[key]
173
- when Hash
174
- row[key] = 'Hash'
175
- when StringIO
176
- row[key] = Base64.encode64(hash[key].read)
177
- when nil
178
- row[key] = nil
179
- else
180
- row[key] = hash[key]
181
- end
174
+ row[key] = case hash[key]
175
+ when Hash
176
+ 'Hash'
177
+ when StringIO
178
+ Base64.encode64(hash[key].read)
179
+ when nil
180
+ nil
181
+ else
182
+ hash[key]
183
+ end
182
184
  end
183
185
 
184
186
  result.push row
185
187
  end
186
- result = result[0] if single_value && result.count > 0
188
+ result = result[0] if single_value && result.count.positive?
187
189
  end
188
190
 
189
191
  {
@@ -202,10 +204,10 @@ class Gitlab::CLI
202
204
  end
203
205
 
204
206
  # Helper function to call Gitlab commands with args.
205
- def gitlab_helper(cmd, args=[])
207
+ def gitlab_helper(cmd, args = [])
206
208
  begin
207
209
  data = args.any? ? Gitlab.send(cmd, *args) : Gitlab.send(cmd)
208
- rescue => e
210
+ rescue StandardError => e
209
211
  puts e.message
210
212
  yield if block_given?
211
213
  end
@@ -217,9 +219,9 @@ class Gitlab::CLI
217
219
  # @return [Hash]
218
220
  def symbolize_keys(hash)
219
221
  if hash.is_a?(Hash)
220
- hash = hash.each_with_object({}) do |(key, value), newhash|
222
+ hash = hash.each_with_object({}) do |(key, value), new_hash|
221
223
  begin
222
- newhash[key.to_sym] = symbolize_keys(value)
224
+ new_hash[key.to_sym] = symbolize_keys(value)
223
225
  rescue NoMethodError
224
226
  raise "Error: cannot convert hash key to symbol: #{key}"
225
227
  end
@@ -229,9 +231,16 @@ class Gitlab::CLI
229
231
  hash
230
232
  end
231
233
 
234
+ # Check if arg is a color in 6-digit hex notation with leading '#' sign
235
+ def hex_color?(arg)
236
+ pattern = /\A#\h{6}\Z/
237
+
238
+ pattern.match(arg)
239
+ end
240
+
232
241
  # YAML::load on a single argument
233
242
  def yaml_load(arg)
234
- YAML.safe_load(arg)
243
+ hex_color?(arg) ? arg : YAML.safe_load(arg)
235
244
  rescue Psych::SyntaxError
236
245
  raise "Error: Argument is not valid YAML syntax: #{arg}"
237
246
  end