gitlab 4.5.0 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines methods related to version
4
+ # @see https://docs.gitlab.com/ce/api/version.html
5
+ module Versions
6
+ # Returns server version.
7
+ # @see https://docs.gitlab.com/ce/api/version.html
8
+ #
9
+ # @example
10
+ # Gitlab.version
11
+ #
12
+ # @return [Array<Gitlab::ObjectifiedHash>]
13
+ def version
14
+ get('/version')
15
+ end
16
+ end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'gitlab/cli_helpers'
2
4
  module Gitlab
3
5
  # Defines constants and methods related to configuration.
4
6
  module Configuration
5
7
  # An array of valid keys in the options hash when configuring a Gitlab::API.
6
- VALID_OPTIONS_KEYS = %i(endpoint private_token user_agent sudo httparty).freeze
8
+ VALID_OPTIONS_KEYS = %i[endpoint private_token user_agent sudo httparty].freeze
7
9
 
8
10
  # The user agent that will be sent to the API endpoint if none is set.
9
- DEFAULT_USER_AGENT = "Gitlab Ruby Gem #{Gitlab::VERSION}".freeze
11
+ DEFAULT_USER_AGENT = "Gitlab Ruby Gem #{Gitlab::VERSION}"
10
12
 
11
13
  # @private
12
14
  attr_accessor(*VALID_OPTIONS_KEYS)
13
15
  # @private
14
- alias_method :auth_token=, :private_token=
16
+ alias auth_token= private_token=
15
17
 
16
18
  # Sets all configuration options to their default values
17
19
  # when this module is extended.
@@ -44,11 +46,11 @@ module Gitlab
44
46
 
45
47
  # Allows HTTParty config to be specified in ENV using YAML hash.
46
48
  def get_httparty_config(options)
47
- return options if options.nil?
49
+ return if options.nil?
48
50
 
49
51
  httparty = Gitlab::CLI::Helpers.yaml_load(options)
50
-
51
52
  raise ArgumentError, 'HTTParty config should be a Hash.' unless httparty.is_a? Hash
53
+
52
54
  Gitlab::CLI::Helpers.symbolize_keys httparty
53
55
  end
54
56
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  module Error
3
5
  # Custom error class for rescuing from all Gitlab errors.
@@ -11,7 +13,7 @@ module Gitlab
11
13
 
12
14
  # Custom error class for rescuing from HTTP response errors.
13
15
  class ResponseError < Error
14
- POSSIBLE_MESSAGE_KEYS = %i(message error_description error)
16
+ POSSIBLE_MESSAGE_KEYS = %i[message error_description error].freeze
15
17
 
16
18
  def initialize(response)
17
19
  @response = response
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  # Wrapper class of file response.
3
5
  class FileResponse
4
- HEADER_CONTENT_DISPOSITION = 'Content-Disposition'.freeze
6
+ HEADER_CONTENT_DISPOSITION = 'Content-Disposition'
5
7
 
6
8
  attr_reader :filename
7
9
 
@@ -18,7 +20,7 @@ module Gitlab
18
20
  def to_hash
19
21
  { filename: @filename, data: @file }
20
22
  end
21
- alias_method :to_h, :to_hash
23
+ alias to_h to_hash
22
24
 
23
25
  # @return [String] Formatted string with the class name, object id and filename.
24
26
  def inspect
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'gitlab'
2
4
  require 'gitlab/cli_helpers'
3
5
 
@@ -32,9 +34,7 @@ module Gitlab::Help
32
34
  # @return [String]
33
35
  def ri_cmd
34
36
  which_ri = `which ri`.chomp
35
- if which_ri.empty?
36
- raise "'ri' tool not found in $PATH. Please install it to use the help."
37
- end
37
+ raise "'ri' tool not found in $PATH. Please install it to use the help." if which_ri.empty?
38
38
 
39
39
  which_ri
40
40
  end
@@ -47,8 +47,8 @@ module Gitlab::Help
47
47
  def help_map
48
48
  @help_map ||= begin
49
49
  actions.each_with_object({}) do |action, hsh|
50
- key = client.method(action).
51
- owner.to_s.gsub(/Gitlab::(?:Client::)?/, '')
50
+ key = client.method(action)
51
+ .owner.to_s.gsub(/Gitlab::(?:Client::)?/, '')
52
52
  hsh[key] ||= []
53
53
  hsh[key] << action.to_s
54
54
  end
@@ -58,7 +58,7 @@ module Gitlab::Help
58
58
  # Table with available commands.
59
59
  #
60
60
  # @return [Terminal::Table]
61
- def actions_table(topic=nil)
61
+ def actions_table(topic = nil)
62
62
  rows = topic ? help_map[topic] : help_map.keys
63
63
  table do |t|
64
64
  t.title = topic || 'Help Topics'
@@ -73,9 +73,9 @@ module Gitlab::Help
73
73
 
74
74
  # Returns full namespace of a command (e.g. Gitlab::Client::Branches.cmd)
75
75
  def namespace(cmd)
76
- method_owners.select { |method| method[:name] == cmd }.
77
- map { |method| method[:owner] + '.' + method[:name] }.
78
- shift
76
+ method_owners.select { |method| method[:name] == cmd }
77
+ .map { |method| 'Gitlab::Client::' + method[:owner] + '.' + method[:name] }
78
+ .shift
79
79
  end
80
80
 
81
81
  # Massage output from 'ri'.
@@ -1,13 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  # Converts hashes to the objects.
3
5
  class ObjectifiedHash
4
6
  # Creates a new ObjectifiedHash object.
5
7
  def initialize(hash)
6
8
  @hash = hash
7
- @data = hash.inject({}) do |data, (key, value)|
9
+ @data = hash.each_with_object({}) do |(key, value), data|
8
10
  value = ObjectifiedHash.new(value) if value.is_a? Hash
9
11
  data[key.to_s] = value
10
- data
11
12
  end
12
13
  end
13
14
 
@@ -15,7 +16,7 @@ module Gitlab
15
16
  def to_hash
16
17
  @hash
17
18
  end
18
- alias_method :to_h, :to_hash
19
+ alias to_h to_hash
19
20
 
20
21
  # @return [String] Formatted string with the class name, object id and original hash.
21
22
  def inspect
@@ -24,7 +25,7 @@ module Gitlab
24
25
 
25
26
  # Delegate to ObjectifiedHash.
26
27
  def method_missing(key)
27
- @data.key?(key.to_s) ? @data[key.to_s] : nil
28
+ @data.key?(key.to_s) ? @data[key.to_s] : super
28
29
  end
29
30
 
30
31
  def respond_to_missing?(method_name, include_private = false)
@@ -1,21 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  # Parses link header.
3
5
  #
4
6
  # @private
5
7
  class PageLinks
6
- HEADER_LINK = 'Link'.freeze
7
- DELIM_LINKS = ','.freeze
8
+ HEADER_LINK = 'Link'
9
+ DELIM_LINKS = ','
8
10
  LINK_REGEX = /<([^>]+)>; rel=\"([^\"]+)\"/
9
- METAS = %w(last next first prev).freeze
11
+ METAS = %w[last next first prev].freeze
10
12
 
11
13
  attr_accessor(*METAS)
12
14
 
13
15
  def initialize(headers)
14
16
  link_header = headers[HEADER_LINK]
15
17
 
16
- if link_header && link_header =~ /(next|first|last|prev)/
17
- extract_links(link_header)
18
- end
18
+ extract_links(link_header) if link_header && link_header =~ /(next|first|last|prev)/
19
19
  end
20
20
 
21
21
  private
@@ -23,8 +23,10 @@ module Gitlab
23
23
  def extract_links(header)
24
24
  header.split(DELIM_LINKS).each do |link|
25
25
  LINK_REGEX.match(link.strip) do |match|
26
- url, meta = match[1], match[2]
26
+ url = match[1]
27
+ meta = match[2]
27
28
  next if !url || !meta || METAS.index(meta).nil?
29
+
28
30
  send("#{meta}=", url)
29
31
  end
30
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  # Wrapper class of paginated response.
3
5
  class PaginatedResponse
@@ -54,42 +56,50 @@ module Gitlab
54
56
  response
55
57
  end
56
58
 
57
- def has_last_page?
59
+ def last_page?
58
60
  !(@links.nil? || @links.last.nil?)
59
61
  end
62
+ alias has_last_page? last_page?
60
63
 
61
64
  def last_page
62
65
  return nil if @client.nil? || !has_last_page?
66
+
63
67
  path = @links.last.sub(/#{@client.endpoint}/, '')
64
68
  @client.get(path)
65
69
  end
66
70
 
67
- def has_first_page?
71
+ def first_page?
68
72
  !(@links.nil? || @links.first.nil?)
69
73
  end
74
+ alias has_first_page? first_page?
70
75
 
71
76
  def first_page
72
77
  return nil if @client.nil? || !has_first_page?
78
+
73
79
  path = @links.first.sub(/#{@client.endpoint}/, '')
74
80
  @client.get(path)
75
81
  end
76
82
 
77
- def has_next_page?
83
+ def next_page?
78
84
  !(@links.nil? || @links.next.nil?)
79
85
  end
86
+ alias has_next_page? next_page?
80
87
 
81
88
  def next_page
82
89
  return nil if @client.nil? || !has_next_page?
90
+
83
91
  path = @links.next.sub(/#{@client.endpoint}/, '')
84
92
  @client.get(path)
85
93
  end
86
94
 
87
- def has_prev_page?
95
+ def prev_page?
88
96
  !(@links.nil? || @links.prev.nil?)
89
97
  end
98
+ alias has_prev_page? prev_page?
90
99
 
91
100
  def prev_page
92
101
  return nil if @client.nil? || !has_prev_page?
102
+
93
103
  path = @links.prev.sub(/#{@client.endpoint}/, '')
94
104
  @client.get(path)
95
105
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'httparty'
2
4
  require 'json'
3
5
 
@@ -7,7 +9,7 @@ module Gitlab
7
9
  include HTTParty
8
10
  format :json
9
11
  headers 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'
10
- parser proc { |body, _| parse(body) }
12
+ parser(proc { |body, _| parse(body) })
11
13
 
12
14
  attr_accessor :private_token, :endpoint
13
15
 
@@ -32,13 +34,13 @@ module Gitlab
32
34
 
33
35
  # Decodes a JSON response into Ruby object.
34
36
  def self.decode(response)
35
- return response ? JSON.load(response) : {}
37
+ response ? JSON.load(response) : {}
36
38
  rescue JSON::ParserError
37
39
  raise Error::Parsing, 'The response is not a valid JSON'
38
40
  end
39
41
 
40
- %w(get post put delete).each do |method|
41
- define_method method do |path, options={}|
42
+ %w[get post put delete].each do |method|
43
+ define_method method do |path, options = {}|
42
44
  httparty_config(options)
43
45
  authorization_header(options)
44
46
  validate self.class.send(method, @endpoint + path, options)
@@ -71,9 +73,10 @@ module Gitlab
71
73
 
72
74
  # Sets a base_uri and default_params for requests.
73
75
  # @raise [Error::MissingCredentials] if endpoint not set.
74
- def request_defaults(sudo=nil)
76
+ def request_defaults(sudo = nil)
75
77
  self.class.default_params sudo: sudo
76
78
  raise Error::MissingCredentials, 'Please set an endpoint to API' unless @endpoint
79
+
77
80
  self.class.default_params.delete(:sudo) if sudo.nil?
78
81
  end
79
82
 
@@ -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,7 +64,7 @@ class Gitlab::Shell
62
64
  end
63
65
 
64
66
  # Execute a given command with arguements
65
- def execute(cmd=command, args=arguments)
67
+ def execute(cmd = command, args = arguments)
66
68
  raise "Unknown command: #{cmd}. See the 'help' for a list of valid commands." unless actions.include?(cmd.to_sym)
67
69
 
68
70
  confirm_command(cmd)
@@ -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)
@@ -31,7 +33,7 @@ class Gitlab::Shell
31
33
  if defined?(@history_file)
32
34
  @history_file
33
35
  else
34
- @history_file = File.open(history_file_path, 'w', 0600).tap do |file|
36
+ @history_file = File.open(history_file_path, 'w', 0o600).tap do |file|
35
37
  file.sync = true
36
38
  end
37
39
  end
@@ -48,7 +50,7 @@ class Gitlab::Shell
48
50
  path = history_file_path
49
51
 
50
52
  File.foreach(path) { |line| yield(line) } if File.exist?(path)
51
- rescue => error
53
+ rescue StandardError => error
52
54
  warn "History file not loaded: #{error.message}"
53
55
  end
54
56
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
- VERSION = '4.5.0'.freeze
4
+ VERSION = '4.6.0'
3
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.5.0
4
+ version: 4.6.0
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: 2018-08-07 00:00:00.000000000 Z
12
+ date: 2018-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -82,7 +82,7 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: webmock
85
+ name: rubocop
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
@@ -96,7 +96,7 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
- name: rubocop
99
+ name: webmock
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
@@ -118,7 +118,9 @@ executables:
118
118
  extensions: []
119
119
  extra_rdoc_files: []
120
120
  files:
121
+ - ".github/stale.yml"
121
122
  - ".gitignore"
123
+ - ".rubocop_todo.yml"
122
124
  - CHANGELOG.md
123
125
  - CONTRIBUTING.md
124
126
  - Gemfile
@@ -169,6 +171,7 @@ files:
169
171
  - lib/gitlab/client/tags.rb
170
172
  - lib/gitlab/client/todos.rb
171
173
  - lib/gitlab/client/users.rb
174
+ - lib/gitlab/client/versions.rb
172
175
  - lib/gitlab/configuration.rb
173
176
  - lib/gitlab/error.rb
174
177
  - lib/gitlab/file_response.rb
@@ -192,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
195
  requirements:
193
196
  - - ">="
194
197
  - !ruby/object:Gem::Version
195
- version: 2.0.0
198
+ version: '2.3'
196
199
  required_rubygems_version: !ruby/object:Gem::Requirement
197
200
  requirements:
198
201
  - - ">="