gitlab 5.1.0 → 6.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1453623fe0d87a006492342f5726338aba971afcc6b693295f537a037d7e2e9
4
- data.tar.gz: ab5e4e4d81bdeeef8802dc03bc8b7c912c6b41f1d4ac25ab5ca752b4af53121b
3
+ metadata.gz: 3d3b231261621f73bdfcb46e2609bf5190494736aef0de757a2fa259d440d9d7
4
+ data.tar.gz: 5c33a995fa9eadca8ac096fa95431c98dd8abcd9851a9a6d1f22f19fbc2b4beb
5
5
  SHA512:
6
- metadata.gz: 54dae253ce896dcbf3e612fdd4bb3e092373557e5959292e5a949108679d4ead1ac69e34e45f9d15c795e826d19b55175ad234598aa68f2e51c8384289af7267
7
- data.tar.gz: 14ab36332c58d98f43216df49bfa6e1cbe8aa6a540ef83cb4b1d2090cad66c9eb8351172f1d13feb369f7f32b8d65503094be358d855b1d5636f01418b129f4f
6
+ metadata.gz: 76a5f90b660a6186f2948bd69187269c9f03be79a9359e8f37dc855bf83410f203f74e9c27fca512b66244f736617f93912f84077498920d1bc468f57d028a8d
7
+ data.tar.gz: 77a4e11963a719227f536412ad13ecc70737961eca68075b3f69a7e91d650b4a4ed592af13062da85b07e973495229ac8ef6ff5388bb470aaceb29629492f22a
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2024 Nihad Abbasov <nihad@42na.in>
1
+ Copyright (c) 2012-2025 Nihad Abbasov <nihad@42na.in>
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -42,6 +42,7 @@ Gitlab.configure do |config|
42
42
  # Optional
43
43
  # config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]'
44
44
  # config.sudo = 'user' # username for sudo mode, default: nil
45
+ # config.body_as_json = false # use application/json for all requests with a body, default: false
45
46
  end
46
47
  ```
47
48
 
data/lib/gitlab/cli.rb CHANGED
@@ -16,12 +16,13 @@ class Gitlab::CLI
16
16
  #
17
17
  # @param [Array] args The command and it's optional arguments.
18
18
  def self.start(args)
19
+ args_dup = args.dup
19
20
  command = begin
20
- args.shift.strip
21
+ args_dup.shift.strip
21
22
  rescue StandardError
22
23
  'help'
23
24
  end
24
- run(command, args)
25
+ run(command, args_dup)
25
26
  end
26
27
 
27
28
  # Processes a CLI command and outputs a result to the stream (stdout).
@@ -3,6 +3,7 @@
3
3
  require 'yaml'
4
4
  require 'json'
5
5
  require 'base64'
6
+ require 'stringio'
6
7
 
7
8
  class Gitlab::CLI
8
9
  # Defines methods related to CLI output and formatting.
@@ -172,14 +172,14 @@ class Gitlab::Client
172
172
 
173
173
  # Creates a single commit with one or more changes
174
174
  #
175
- # @see https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
175
+ # @see https://docs.gitlab.com/api/commits/#create-a-commit-with-multiple-files-and-actions
176
176
  # Introduced in Gitlab 8.13
177
177
  #
178
178
  # @example
179
- # Gitlab.create_commit(2726132, 'master', 'refactors everything', [{action: 'create', file_path: '/foo.txt', content: 'bar'}])
180
- # Gitlab.create_commit(2726132, 'master', 'refactors everything', [{action: 'delete', file_path: '/foo.txt'}])
179
+ # Gitlab.create_commit(2726132, 'master', 'refactors everything', [{action: 'create', file_path: '/foo.txt', content: 'bar'}])
180
+ # Gitlab.create_commit(2726132, 'master', 'refactors everything', [{action: 'delete', file_path: '/foo.txt'}])
181
181
  #
182
- # @param [Integer, String] project The ID or name of a project.
182
+ # @param [Integer, String] project The ID or name of a project.
183
183
  # @param [String] branch the branch name you wish to commit to
184
184
  # @param [String] message the commit message
185
185
  # @param [Array[Hash]] An array of action hashes to commit as a batch. See the next table for what attributes it can take.
@@ -10,9 +10,14 @@ class Gitlab::Client
10
10
  # Gitlab.registry_repositories(5)
11
11
  #
12
12
  # @param [Integer, String] project The ID or name of a project.
13
+ # @param [Hash] options A customizable set of options.
14
+ # @option options [Boolean] :tags Return tags array in the response.
15
+ # @option options [Boolean] :tags_count Return tags count in the response.
16
+ # @option options [Integer] :page The page number.
17
+ # @option options [Integer] :per_page The number of results per page.
13
18
  # @return [Array<Gitlab::ObjectifiedHash>] Returns list of registry repositories in a project.
14
- def registry_repositories(project)
15
- get("/projects/#{url_encode project}/registry/repositories")
19
+ def registry_repositories(project, options = {})
20
+ get("/projects/#{url_encode project}/registry/repositories", query: options)
16
21
  end
17
22
 
18
23
  # Delete a repository in registry.
@@ -148,26 +148,45 @@ class Gitlab::Client
148
148
  #
149
149
  # @example
150
150
  # Gitlab.add_group_member(1, 2, 40)
151
+ # Gitlab.add_group_member(1, 2, 40, member_role_id: 5)
151
152
  #
152
153
  # @param [Integer] team_id The group id to add a member to.
153
154
  # @param [Integer] user_id The user id of the user to add to the team.
154
155
  # @param [Integer] access_level Project access level.
156
+ # @param [Hash] options A customizable set of options.
157
+ # @option options [Integer] :member_role_id The id of a custom member role.
155
158
  # @return [Gitlab::ObjectifiedHash] Information about added team member.
156
- def add_group_member(team_id, user_id, access_level)
157
- post("/groups/#{url_encode team_id}/members", body: { user_id: user_id, access_level: access_level })
159
+ def add_group_member(team_id, user_id, access_level, options = {})
160
+ body = { user_id: user_id, access_level: access_level }.merge(options)
161
+ post("/groups/#{url_encode team_id}/members", body: body)
162
+ end
163
+
164
+ # Set LDAP override flag for a member of a group
165
+ #
166
+ # @example
167
+ # Gitlab.override_group_member(1, 2)
168
+ #
169
+ # @param [Integer] team_id The group id into which LDAP syncs the user.
170
+ # @param [Integer] user_id The user id of the user.
171
+ def override_group_member(team_id, user_id)
172
+ post("/groups/#{url_encode team_id}/members/#{user_id}/override")
158
173
  end
159
174
 
160
175
  # Edit a user of a group.
161
176
  #
162
177
  # @example
163
178
  # Gitlab.edit_group_member(1, 2, 40)
179
+ # Gitlab.edit_group_member(1, 2, 40, member_role_id: 5)
164
180
  #
165
181
  # @param [Integer] team_id The group id of member to edit.
166
182
  # @param [Integer] user_id The user id of the user to edit.
167
183
  # @param [Integer] access_level Project access level.
184
+ # @param [Hash] options A customizable set of options.
185
+ # @option options [Integer] :member_role_id The id of a custom member role.
168
186
  # @return [Gitlab::ObjectifiedHash] Information about edited team member.
169
- def edit_group_member(team_id, user_id, access_level)
170
- put("/groups/#{url_encode team_id}/members/#{user_id}", body: { access_level: access_level })
187
+ def edit_group_member(team_id, user_id, access_level, options = {})
188
+ body = { access_level: access_level }.merge(options)
189
+ put("/groups/#{url_encode team_id}/members/#{user_id}", body: body)
171
190
  end
172
191
 
173
192
  # Removes user from user group.
@@ -365,9 +365,12 @@ class Gitlab::Client
365
365
  # Gitlab.merge_request_diffs('gitlab', 1)
366
366
  # @param [Integer, String] project The ID or name of a project.
367
367
  # @param [Integer] id The ID of a merge request.
368
+ # @option options [Integer] :page The page number.
369
+ # @option options [Integer] :per_page The number of results per page.
370
+ # @option options [Boolean] :unidiff Present diffs in the unified diff format.
368
371
  # @return [Gitlab::ObjectifiedHash] A list of the merge request diffs.
369
- def merge_request_diffs(project, merge_request_id)
370
- get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/diffs")
372
+ def merge_request_diffs(project, merge_request_id, options = {})
373
+ get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/diffs", query: options)
371
374
  end
372
375
 
373
376
  # Gets a list of merge request diff versions
@@ -24,7 +24,7 @@ class Gitlab::Client
24
24
  # @param [String] tag_name The tag where the release will be created from..
25
25
  # @return [Gitlab::ObjectifiedHash] Information about the release
26
26
  def project_release(project, tag_name)
27
- get("/projects/#{url_encode project}/releases/#{tag_name}")
27
+ get("/projects/#{url_encode project}/releases/#{url_encode tag_name}")
28
28
  end
29
29
 
30
30
  # Creates a Release. You need push access to the repository to create a Release.
@@ -61,7 +61,7 @@ class Gitlab::Client
61
61
  # @option options [String] :description(optional) The description of the release. You can use markdown.
62
62
  # @return [Gitlab::ObjectifiedHash] Information about the updated release.
63
63
  def update_project_release(project, tag_name, options = {})
64
- put("/projects/#{url_encode project}/releases/#{tag_name}", body: options)
64
+ put("/projects/#{url_encode project}/releases/#{url_encode tag_name}", body: options)
65
65
  end
66
66
 
67
67
  # Delete a Release. Deleting a Release will not delete the associated tag.
@@ -73,7 +73,7 @@ class Gitlab::Client
73
73
  # @param [String] tag_name The tag where the release will be created from.
74
74
  # @return [Gitlab::ObjectifiedHash] Information about the deleted release.
75
75
  def delete_project_release(project, tag_name)
76
- delete("/projects/#{url_encode project}/releases/#{tag_name}")
76
+ delete("/projects/#{url_encode project}/releases/#{url_encode tag_name}")
77
77
  end
78
78
 
79
79
  # Gets Latest Release
@@ -138,12 +138,14 @@ class Gitlab::Client
138
138
  # @example
139
139
  # Gitlab.add_team_member('gitlab', 2, 40)
140
140
  # Gitlab.add_team_member('gitlab', 2, 40, { expires_at: "2018-12-31"})
141
+ # Gitlab.add_team_member('gitlab', 2, 40, { member_role_id: 5 })
141
142
  #
142
143
  # @param [Integer, String] project The ID or path of a project.
143
144
  # @param [Integer] id The ID of a user.
144
145
  # @param [Integer] access_level The access level to project.
145
146
  # @param [Hash] options A customizable set of options.
146
147
  # @option options [String] :expires_at A date string in the format YEAR-MONTH-DAY.
148
+ # @option options [Integer] :member_role_id The id of a custom member role.
147
149
  # @return [Gitlab::ObjectifiedHash] Information about added team member.
148
150
  def add_team_member(project, id, access_level, options = {})
149
151
  body = { user_id: id, access_level: access_level }.merge(options)
@@ -155,12 +157,14 @@ class Gitlab::Client
155
157
  # @example
156
158
  # Gitlab.edit_team_member('gitlab', 3, 20)
157
159
  # Gitlab.edit_team_member('gitlab', 3, 20, { expires_at: "2018-12-31"})
160
+ # Gitlab.edit_team_member('gitlab', 3, 20, { member_role_id: 5 })
158
161
  #
159
162
  # @param [Integer, String] project The ID or path of a project.
160
163
  # @param [Integer] id The ID of a user.
161
164
  # @param [Integer] access_level The access level to project.
162
165
  # @param [Hash] options A customizable set of options.
163
166
  # @option options [String] :expires_at A date string in the format YEAR-MONTH-DAY.
167
+ # @option options [Integer] :member_role_id The id of a custom member role.
164
168
  # @return [Array<Gitlab::ObjectifiedHash>] Information about updated team member.
165
169
  def edit_team_member(project, id, access_level, options = {})
166
170
  body = { access_level: access_level }.merge(options)
@@ -16,6 +16,19 @@ class Gitlab::Client
16
16
  get("/projects/#{url_encode project}/remote_mirrors")
17
17
  end
18
18
 
19
+ # Get a specific remote mirror.
20
+ #
21
+ # @example
22
+ # Gitlab.remote_mirror(42, 1234)
23
+ #
24
+ # @param [Integer, String] project The ID or path of a project.
25
+ # @param [Integer] id The ID of the remote mirror.
26
+ #
27
+ # @return [Gitlab::ObjectifiedHash] Information about the specified remote mirror.
28
+ def remote_mirror(project, id)
29
+ get("/projects/#{url_encode project}/remote_mirrors/#{id}")
30
+ end
31
+
19
32
  # Create a remote mirror
20
33
  #
21
34
  # @example
@@ -47,5 +60,31 @@ class Gitlab::Client
47
60
  def edit_remote_mirror(project, id, options = {})
48
61
  put("/projects/#{url_encode project}/remote_mirrors/#{id}", body: options)
49
62
  end
63
+
64
+ # Delete a remote mirror.
65
+ #
66
+ # @example
67
+ # Gitlab.delete_remote_mirror(42, 1234)
68
+ #
69
+ # @param [Integer, String] project The ID or path of a project.
70
+ # @param [Integer] id The ID of the remote mirror.
71
+ #
72
+ # @return [Gitlab::ObjectifiedHash]
73
+ def delete_remote_mirror(project, id)
74
+ delete("/projects/#{url_encode project}/remote_mirrors/#{id}")
75
+ end
76
+
77
+ # Force push mirror update.
78
+ #
79
+ # @example
80
+ # Gitlab.sync_remote_mirror(42, 1234)
81
+ #
82
+ # @param [Integer, String] project The ID or path of a project.
83
+ # @param [Integer] id The ID of the remote mirror.
84
+ #
85
+ # @return [Gitlab::ObjectifiedHash]
86
+ def sync_remote_mirror(project, id)
87
+ post("/projects/#{url_encode project}/remote_mirrors/#{id}/sync")
88
+ end
50
89
  end
51
90
  end
data/lib/gitlab/client.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cgi'
4
+
3
5
  module Gitlab
4
6
  # Wrapper for the Gitlab REST API.
5
7
  class Client < API
@@ -82,11 +84,10 @@ module Gitlab
82
84
  end
83
85
 
84
86
  # Utility method for URL encoding of a string.
85
- # Copied from https://ruby-doc.org/stdlib-2.7.0/libdoc/erb/rdoc/ERB/Util.html
86
87
  #
87
88
  # @return [String]
88
89
  def url_encode(url)
89
- url.to_s.b.gsub(/[^a-zA-Z0-9_\-.~]/n) { |m| sprintf('%%%02X', m.unpack1('C')) } # rubocop:disable Style/FormatString
90
+ CGI.escapeURIComponent(url.to_s)
90
91
  end
91
92
 
92
93
  private
@@ -5,7 +5,7 @@ module Gitlab
5
5
  # Defines constants and methods related to configuration.
6
6
  module Configuration
7
7
  # An array of valid keys in the options hash when configuring a Gitlab::API.
8
- VALID_OPTIONS_KEYS = %i[endpoint private_token user_agent sudo httparty pat_prefix].freeze
8
+ VALID_OPTIONS_KEYS = %i[endpoint private_token user_agent sudo httparty pat_prefix body_as_json].freeze
9
9
 
10
10
  # The user agent that will be sent to the API endpoint if none is set.
11
11
  DEFAULT_USER_AGENT = "Gitlab Ruby Gem #{Gitlab::VERSION}"
@@ -41,6 +41,7 @@ module Gitlab
41
41
  self.httparty = get_httparty_config(ENV['GITLAB_API_HTTPARTY_OPTIONS'])
42
42
  self.sudo = nil
43
43
  self.user_agent = DEFAULT_USER_AGENT
44
+ self.body_as_json = false
44
45
  end
45
46
 
46
47
  private
@@ -12,7 +12,7 @@ module Gitlab
12
12
  headers 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'
13
13
  parser(proc { |body, _| parse(body) })
14
14
 
15
- attr_accessor :private_token, :endpoint, :pat_prefix
15
+ attr_accessor :private_token, :endpoint, :pat_prefix, :body_as_json
16
16
 
17
17
  # Converts the response body to an ObjectifiedHash.
18
18
  def self.parse(body)
@@ -49,6 +49,8 @@ module Gitlab
49
49
  params[:headers].merge!(authorization_header)
50
50
  end
51
51
 
52
+ jsonify_body_content(params) if body_as_json
53
+
52
54
  retries_left = params[:ratelimit_retries] || 3
53
55
  begin
54
56
  response = self.class.send(method, endpoint + path, params)
@@ -114,5 +116,24 @@ module Gitlab
114
116
  def httparty_config(options)
115
117
  options.merge!(httparty) if httparty
116
118
  end
119
+
120
+ # Handle 'body_as_json' configuration option
121
+ # Modifies passed params in place.
122
+ def jsonify_body_content(params)
123
+ # Only modify the content type if there is a body to process AND multipath
124
+ # was not explicitly requested. There are no uses of multipart in this code
125
+ # today, but file upload methods require it and someone might be manually
126
+ # crafting a post call with it:
127
+ return unless params[:body] && params[:multipart] != true
128
+
129
+ # If the caller explicitly requested a Content-Type during the call, assume
130
+ # they know best and have formatted the body as required:
131
+ return if params[:headers]&.key?('Content-Type')
132
+
133
+ # If we make it here, then we assume it is safe to JSON encode the body:
134
+ params[:headers] ||= {}
135
+ params[:headers]['Content-Type'] = 'application/json'
136
+ params[:body] = params[:body].to_json
137
+ end
117
138
  end
118
139
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitlab
4
- VERSION = '5.1.0'
4
+ VERSION = '6.1.0'
5
5
  end
metadata CHANGED
@@ -1,30 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nihad Abbasov
8
- - Sean Edge
9
- autorequire:
10
8
  bindir: exe
11
9
  cert_chain: []
12
- date: 2024-10-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
13
11
  dependencies:
14
12
  - !ruby/object:Gem::Dependency
15
13
  name: base64
16
14
  requirement: !ruby/object:Gem::Requirement
17
15
  requirements:
18
- - - "~>"
16
+ - - ">="
19
17
  - !ruby/object:Gem::Version
20
- version: 0.2.0
18
+ version: '0'
21
19
  type: :runtime
22
20
  prerelease: false
23
21
  version_requirements: !ruby/object:Gem::Requirement
24
22
  requirements:
25
- - - "~>"
23
+ - - ">="
26
24
  - !ruby/object:Gem::Version
27
- version: 0.2.0
25
+ version: '0'
28
26
  - !ruby/object:Gem::Dependency
29
27
  name: httparty
30
28
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +96,6 @@ dependencies:
98
96
  description: Ruby client and CLI for GitLab API
99
97
  email:
100
98
  - nihad@42na.in
101
- - asedge@gmail.com
102
99
  executables:
103
100
  - gitlab
104
101
  extensions: []
@@ -199,7 +196,6 @@ metadata:
199
196
  bug_tracker_uri: https://github.com/NARKOZ/gitlab/issues
200
197
  changelog_uri: https://github.com/NARKOZ/gitlab/releases
201
198
  funding_uri: https://github.com/NARKOZ/SponsorMe
202
- post_install_message:
203
199
  rdoc_options: []
204
200
  require_paths:
205
201
  - lib
@@ -207,15 +203,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
203
  requirements:
208
204
  - - ">="
209
205
  - !ruby/object:Gem::Version
210
- version: '3.1'
206
+ version: '3.2'
211
207
  required_rubygems_version: !ruby/object:Gem::Requirement
212
208
  requirements:
213
209
  - - ">="
214
210
  - !ruby/object:Gem::Version
215
211
  version: '0'
216
212
  requirements: []
217
- rubygems_version: 3.5.16
218
- signing_key:
213
+ rubygems_version: 3.6.9
219
214
  specification_version: 4
220
215
  summary: A Ruby wrapper and CLI for the GitLab API
221
216
  test_files: []