gitlab 4.14.0 → 4.17.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.
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to user snippets.
5
+ # @see https://docs.gitlab.com/ce/api/snippets.html
6
+ module UserSnippets
7
+ # Get a list of the snippets of the current user.
8
+ #
9
+ # @example
10
+ # Gitlab.user_snippets
11
+ #
12
+ # @return [Array<Gitlab::ObjectifiedHash>] List of snippets of current user
13
+ def user_snippets
14
+ get('/snippets')
15
+ end
16
+
17
+ # Get a single snippet.
18
+ #
19
+ # @example
20
+ # Gitlab.user_snippet(1)
21
+ #
22
+ # @param [Integer] id ID of snippet to retrieve.
23
+ # @return [Gitlab::ObjectifiedHash] Information about the user snippet
24
+ def user_snippet(id)
25
+ get("/snippets/#{id}")
26
+ end
27
+
28
+ # Get raw contents of a single snippet.
29
+ #
30
+ # @example
31
+ # Gitlab.user_snippet_raw(1)
32
+ #
33
+ # @param [Integer] id ID of snippet to retrieve.
34
+ # @return [String] User snippet text
35
+ def user_snippet_raw(id)
36
+ get("/snippets/#{id}/raw",
37
+ format: nil,
38
+ headers: { Accept: 'text/plain' },
39
+ parser: ::Gitlab::Request::Parser)
40
+ end
41
+
42
+ # Create a new snippet.
43
+ #
44
+ # @example
45
+ # Gitlab.create_user_snippet({ title: 'REST', file_name: 'api.rb', content: 'some code', description: 'Hello World snippet', visibility: 'public'})
46
+ #
47
+ # @param [Hash] options A customizable set of options.
48
+ # @option options [String] :title (required) Title of a snippet.
49
+ # @option options [String] :file_name (required) Name of a snippet file.
50
+ # @option options [String] :content (required) Content of a snippet.
51
+ # @option options [String] :description (optional) Description of a snippet.
52
+ # @option options [String] :visibility (optional) visibility of a snippet.
53
+ # @return [Gitlab::ObjectifiedHash] Information about created snippet.
54
+ def create_user_snippet(options = {})
55
+ post('/snippets', body: options)
56
+ end
57
+
58
+ # Update an existing snippet.
59
+ #
60
+ # @example
61
+ # Gitlab.edit_user_snippet(34, { file_name: 'README.txt' })
62
+ # Gitlab.edit_user_snippet(34, { file_name: 'README.txt', title: 'New title' })
63
+ #
64
+ # @param [Integer] id ID of snippet to update.
65
+ # @param [Hash] options A customizable set of options.
66
+ # @option options [String] :title (optional) Title of a snippet.
67
+ # @option options [String] :file_name (optional) Name of a snippet file.
68
+ # @option options [String] :content (optional) Content of a snippet.
69
+ # @option options [String] :description (optional) Description of a snippet.
70
+ # @option options [String] :visibility (optional) visibility of a snippet.
71
+ # @return [Gitlab::ObjectifiedHash] Information about updated snippet.
72
+ def edit_user_snippet(id, options = {})
73
+ put("/snippets/#{id}", body: options)
74
+ end
75
+
76
+ # Delete an existing snippet.
77
+ #
78
+ # @example
79
+ # Gitlab.delete_user_snippet(14)
80
+ #
81
+ # @param [Integer] id ID of snippet to delete.
82
+ # @return [void] This API call returns an empty response body.
83
+ def delete_user_snippet(id)
84
+ delete("/snippets/#{id}")
85
+ end
86
+
87
+ # List all public snippets.
88
+ #
89
+ # @example
90
+ # Gitlab.public_snippets
91
+ # Gitlab.public_snippets(per_page: 2, page: 1)
92
+ #
93
+ # @param [Hash] options A customizable set of options.
94
+ # @option options [String] :per_page (optional) Number of snippets to return per page.
95
+ # @option options [String] :page (optional) Page to retrieve.
96
+ #
97
+ # @return [Array<Gitlab::ObjectifiedHash>] List of all public snippets
98
+ def public_snippets(options = {})
99
+ get('/snippets/public', query: options)
100
+ end
101
+
102
+ # Get user agent details for a snippet.
103
+ #
104
+ # @example
105
+ # Gitlab.snippet_user_agent_details(1)
106
+ #
107
+ # @param [Integer] id ID of snippet to delete.
108
+ #
109
+ # @return [Array<Gitlab::ObjectifiedHash>] Details of the user agent
110
+ def snippet_user_agent_details(id)
111
+ get("/snippets/#{id}/user_agent_detail")
112
+ end
113
+ end
114
+ end
@@ -123,6 +123,20 @@ class Gitlab::Client
123
123
  post('/session', body: { email: email, password: password }, unauthenticated: true)
124
124
  end
125
125
 
126
+ # Gets a list of user activities (for admin access only).
127
+ #
128
+ # @example
129
+ # Gitlab.activities
130
+ #
131
+ # @param [Hash] options A customizable set of options.
132
+ # @option options [Integer] :page The page number.
133
+ # @option options [Integer] :per_page The number of results per page.
134
+ # @option options [String] :from The start date for paginated results.
135
+ # @return [Array<Gitlab::ObjectifiedHash>]
136
+ def activities(options = {})
137
+ get('/user/activities', query: options)
138
+ end
139
+
126
140
  # Gets a list of user's SSH keys.
127
141
  #
128
142
  # @example
@@ -225,10 +239,15 @@ class Gitlab::Client
225
239
  #
226
240
  # @param [String] email Email address
227
241
  # @param [Integer] user_id The ID of a user.
242
+ # @param [Boolean] skip_confirmation Skip confirmation and assume e-mail is verified
228
243
  # @return [Gitlab::ObjectifiedHash]
229
- def add_email(email, user_id = nil)
244
+ def add_email(email, user_id = nil, skip_confirmation = nil)
230
245
  url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails"
231
- post(url, body: { email: email })
246
+ if skip_confirmation.nil?
247
+ post(url, body: { email: email })
248
+ else
249
+ post(url, body: { email: email, skip_confirmation: skip_confirmation })
250
+ end
232
251
  end
233
252
 
234
253
  # Delete email
@@ -34,6 +34,17 @@ module Gitlab
34
34
  @response.parsed_response.message
35
35
  end
36
36
 
37
+ # Additional error context returned by some API endpoints
38
+ #
39
+ # @return [String]
40
+ def error_code
41
+ if @response.respond_to?(:error_code)
42
+ @response.error_code
43
+ else
44
+ ''
45
+ end
46
+ end
47
+
37
48
  private
38
49
 
39
50
  # Human friendly message.
@@ -63,6 +74,14 @@ module Gitlab
63
74
  else
64
75
  @response.parsed_response
65
76
  end
77
+ rescue Gitlab::Error::Parsing
78
+ # Return stringified response when receiving a
79
+ # parsing error to avoid obfuscation of the
80
+ # api error.
81
+ #
82
+ # note: The Gitlab API does not always return valid
83
+ # JSON when there are errors.
84
+ @response.to_s
66
85
  end
67
86
 
68
87
  # Handle error response message in case of nested hashes
@@ -74,20 +74,21 @@ module Gitlab::Help
74
74
  # Returns full namespace of a command (e.g. Gitlab::Client::Branches.cmd)
75
75
  def namespace(cmd)
76
76
  method_owners.select { |method| method[:name] == cmd }
77
- .map { |method| method[:owner] + '.' + method[:name] }
77
+ .map { |method| "#{method[:owner]}.#{method[:name]}" }
78
78
  .shift
79
79
  end
80
80
 
81
81
  # Massage output from 'ri'.
82
82
  def change_help_output!(cmd, output_str)
83
- output_str.gsub!(/#{cmd}\((.*?)\)/m, cmd + ' \1')
84
- output_str.gsub!(/\,[\s]*/, ' ')
83
+ output_str = +output_str
84
+ output_str.gsub!(/#{cmd}\((.*?)\)/m, "#{cmd} \1")
85
+ output_str.gsub!(/,\s*/, ' ')
85
86
 
86
87
  # Ensure @option descriptions are on a single line
87
88
  output_str.gsub!(/\n\[/, " \[")
88
89
  output_str.gsub!(/\s(@)/, "\n@")
89
- output_str.gsub!(/(\])\n(\:)/, '\1 \2')
90
- output_str.gsub!(/(\:.*)(\n)(.*\.)/, '\1 \3')
90
+ output_str.gsub!(/(\])\n(:)/, '\1 \2')
91
+ output_str.gsub!(/(:.*)(\n)(.*\.)/, '\1 \3')
91
92
  output_str.gsub!(/\{(.+)\}/, '"{\1}"')
92
93
  end
93
94
  end
@@ -7,29 +7,45 @@ module Gitlab
7
7
  def initialize(hash)
8
8
  @hash = hash
9
9
  @data = hash.each_with_object({}) do |(key, value), data|
10
- value = ObjectifiedHash.new(value) if value.is_a? Hash
10
+ value = self.class.new(value) if value.is_a? Hash
11
+ value = value.map { |v| v.is_a?(Hash) ? self.class.new(v) : v } if value.is_a? Array
11
12
  data[key.to_s] = value
12
13
  end
13
14
  end
14
15
 
15
16
  # @return [Hash] The original hash.
16
17
  def to_hash
17
- @hash
18
+ hash
18
19
  end
19
20
  alias to_h to_hash
20
21
 
21
22
  # @return [String] Formatted string with the class name, object id and original hash.
22
23
  def inspect
23
- "#<#{self.class}:#{object_id} {hash: #{@hash.inspect}}"
24
+ "#<#{self.class}:#{object_id} {hash: #{hash.inspect}}"
24
25
  end
25
26
 
26
- # Delegate to ObjectifiedHash.
27
- def method_missing(key)
28
- @data.key?(key.to_s) ? @data[key.to_s] : super
27
+ def [](key)
28
+ data[key]
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :hash, :data
34
+
35
+ # Respond to messages for which `self.data` has a key
36
+ def method_missing(method_name, *args, &block)
37
+ if data.key?(method_name.to_s)
38
+ data[method_name.to_s]
39
+ elsif data.respond_to?(method_name)
40
+ warn 'WARNING: Please convert ObjectifiedHash object to hash before calling Hash methods on it.'
41
+ data.send(method_name, *args, &block)
42
+ else
43
+ super
44
+ end
29
45
  end
30
46
 
31
47
  def respond_to_missing?(method_name, include_private = false)
32
- @hash.keys.map(&:to_sym).include?(method_name.to_sym) || super
48
+ hash.keys.map(&:to_sym).include?(method_name.to_sym) || super
33
49
  end
34
50
  end
35
51
  end
@@ -7,7 +7,7 @@ module Gitlab
7
7
  class PageLinks
8
8
  HEADER_LINK = 'Link'
9
9
  DELIM_LINKS = ','
10
- LINK_REGEX = /<([^>]+)>; rel=\"([^\"]+)\"/.freeze
10
+ LINK_REGEX = /<([^>]+)>; rel="([^"]+)"/.freeze
11
11
  METAS = %w[last next first prev].freeze
12
12
 
13
13
  attr_accessor(*METAS)
@@ -42,37 +42,20 @@ module Gitlab
42
42
  end
43
43
  end
44
44
 
45
- def auto_paginate
46
- response = block_given? ? nil : []
47
- each_page do |page|
48
- if block_given?
49
- page.each do |item|
50
- yield item
51
- end
52
- else
53
- response += page
54
- end
55
- end
56
- response
57
- end
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
45
+ def lazy_paginate
46
+ to_enum(:each_page).lazy.flat_map(&:to_ary) # rubocop:disable Lint/ToEnumArguments
47
+ end
48
+
49
+ def auto_paginate(&block)
50
+ return lazy_paginate.to_a unless block
51
+
52
+ lazy_paginate.each(&block)
53
+ end
54
+
55
+ def paginate_with_limit(limit, &block)
56
+ return lazy_paginate.take(limit).to_a unless block
57
+
58
+ lazy_paginate.take(limit).each(&block)
76
59
  end
77
60
 
78
61
  def last_page?
@@ -83,8 +66,7 @@ module Gitlab
83
66
  def last_page
84
67
  return nil if @client.nil? || !has_last_page?
85
68
 
86
- path = @links.last.sub(/#{@client.endpoint}/, '')
87
- @client.get(path)
69
+ @client.get(client_relative_path(@links.last))
88
70
  end
89
71
 
90
72
  def first_page?
@@ -95,8 +77,7 @@ module Gitlab
95
77
  def first_page
96
78
  return nil if @client.nil? || !has_first_page?
97
79
 
98
- path = @links.first.sub(/#{@client.endpoint}/, '')
99
- @client.get(path)
80
+ @client.get(client_relative_path(@links.first))
100
81
  end
101
82
 
102
83
  def next_page?
@@ -107,8 +88,7 @@ module Gitlab
107
88
  def next_page
108
89
  return nil if @client.nil? || !has_next_page?
109
90
 
110
- path = @links.next.sub(/#{@client.endpoint}/, '')
111
- @client.get(path)
91
+ @client.get(client_relative_path(@links.next))
112
92
  end
113
93
 
114
94
  def prev_page?
@@ -119,8 +99,12 @@ module Gitlab
119
99
  def prev_page
120
100
  return nil if @client.nil? || !has_prev_page?
121
101
 
122
- path = @links.prev.sub(/#{@client.endpoint}/, '')
123
- @client.get(path)
102
+ @client.get(client_relative_path(@links.prev))
103
+ end
104
+
105
+ def client_relative_path(link)
106
+ client_endpoint_path = URI.parse(@client.endpoint).request_uri # api/v4
107
+ URI.parse(link).request_uri.sub(client_endpoint_path, '')
124
108
  end
125
109
  end
126
110
  end
@@ -25,8 +25,6 @@ module Gitlab
25
25
  true
26
26
  elsif !body
27
27
  false
28
- elsif body.nil?
29
- false
30
28
  else
31
29
  raise Error::Parsing, "Couldn't parse a response body"
32
30
  end
@@ -42,10 +42,10 @@ class Gitlab::Shell
42
42
  File.expand_path(@file_path)
43
43
  end
44
44
 
45
- def read_from_file
45
+ def read_from_file(&block)
46
46
  path = history_file_path
47
47
 
48
- File.foreach(path) { |line| yield(line) } if File.exist?(path)
48
+ File.foreach(path, &block) if File.exist?(path)
49
49
  rescue StandardError => e
50
50
  warn "History file not loaded: #{e.message}"
51
51
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitlab
4
- VERSION = '4.14.0'
4
+ VERSION = '4.17.0'
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.14.0
4
+ version: 4.17.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: 2020-03-11 00:00:00.000000000 Z
12
+ date: 2020-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -17,20 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0.14'
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 0.14.0
20
+ version: '0.18'
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
25
  - - "~>"
29
26
  - !ruby/object:Gem::Version
30
- version: '0.14'
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.14.0
27
+ version: '0.18'
34
28
  - !ruby/object:Gem::Dependency
35
29
  name: terminal-table
36
30
  requirement: !ruby/object:Gem::Requirement
@@ -51,20 +45,6 @@ dependencies:
51
45
  - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  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
48
  - !ruby/object:Gem::Dependency
69
49
  name: rake
70
50
  requirement: !ruby/object:Gem::Requirement
@@ -93,20 +73,6 @@ dependencies:
93
73
  - - ">="
94
74
  - !ruby/object:Gem::Version
95
75
  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
76
  - !ruby/object:Gem::Dependency
111
77
  name: webmock
112
78
  requirement: !ruby/object:Gem::Requirement
@@ -152,9 +118,11 @@ files:
152
118
  - lib/gitlab/client/container_registry.rb
153
119
  - lib/gitlab/client/deployments.rb
154
120
  - lib/gitlab/client/environments.rb
121
+ - lib/gitlab/client/epic_issues.rb
155
122
  - lib/gitlab/client/epics.rb
156
123
  - lib/gitlab/client/events.rb
157
124
  - lib/gitlab/client/features.rb
125
+ - lib/gitlab/client/group_badges.rb
158
126
  - lib/gitlab/client/group_boards.rb
159
127
  - lib/gitlab/client/group_labels.rb
160
128
  - lib/gitlab/client/group_milestones.rb
@@ -184,6 +152,7 @@ files:
184
152
  - lib/gitlab/client/repository_files.rb
185
153
  - lib/gitlab/client/repository_submodules.rb
186
154
  - lib/gitlab/client/resource_label_events.rb
155
+ - lib/gitlab/client/resource_state_events.rb
187
156
  - lib/gitlab/client/runners.rb
188
157
  - lib/gitlab/client/search.rb
189
158
  - lib/gitlab/client/services.rb
@@ -193,6 +162,7 @@ files:
193
162
  - lib/gitlab/client/tags.rb
194
163
  - lib/gitlab/client/templates.rb
195
164
  - lib/gitlab/client/todos.rb
165
+ - lib/gitlab/client/user_snippets.rb
196
166
  - lib/gitlab/client/users.rb
197
167
  - lib/gitlab/client/versions.rb
198
168
  - lib/gitlab/client/wikis.rb
@@ -219,14 +189,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
189
  requirements:
220
190
  - - ">="
221
191
  - !ruby/object:Gem::Version
222
- version: '2.3'
192
+ version: '2.5'
223
193
  required_rubygems_version: !ruby/object:Gem::Requirement
224
194
  requirements:
225
195
  - - ">="
226
196
  - !ruby/object:Gem::Version
227
197
  version: '0'
228
198
  requirements: []
229
- rubygems_version: 3.1.2
199
+ rubygems_version: 3.1.4
230
200
  signing_key:
231
201
  specification_version: 4
232
202
  summary: A Ruby wrapper and CLI for the GitLab API