gitlab 5.1.0 → 6.0.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: d87d3a45a149b5716785aeae8de09e610054957164a6ab6fd72a78ccb61ddc4e
4
+ data.tar.gz: a1b09933c6bb1f55a7d3036b85fec73c3a5563879cf7685b9d0671733454b66d
5
5
  SHA512:
6
- metadata.gz: 54dae253ce896dcbf3e612fdd4bb3e092373557e5959292e5a949108679d4ead1ac69e34e45f9d15c795e826d19b55175ad234598aa68f2e51c8384289af7267
7
- data.tar.gz: 14ab36332c58d98f43216df49bfa6e1cbe8aa6a540ef83cb4b1d2090cad66c9eb8351172f1d13feb369f7f32b8d65503094be358d855b1d5636f01418b129f4f
6
+ metadata.gz: bfab31240d5cbd79d7f620044f7693dae8800bc9c6f725e4732bd1332df2088108c16576c9c568693a248cfc57986c3ba6169e1d29f8590dee9bb624fb77c448
7
+ data.tar.gz: efe36ef14a181fe06deed1065d0cbbca162af6efc290fd80378c12e70b9d2ad0a84ca11e8a5f56667268f8345713af93e43e840c826d9c935de753600ae4aacf
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,34 @@ 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)
158
162
  end
159
163
 
160
164
  # Edit a user of a group.
161
165
  #
162
166
  # @example
163
167
  # Gitlab.edit_group_member(1, 2, 40)
168
+ # Gitlab.edit_group_member(1, 2, 40, member_role_id: 5)
164
169
  #
165
170
  # @param [Integer] team_id The group id of member to edit.
166
171
  # @param [Integer] user_id The user id of the user to edit.
167
172
  # @param [Integer] access_level Project access level.
173
+ # @param [Hash] options A customizable set of options.
174
+ # @option options [Integer] :member_role_id The id of a custom member role.
168
175
  # @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 })
176
+ def edit_group_member(team_id, user_id, access_level, options = {})
177
+ body = { access_level: access_level }.merge(options)
178
+ put("/groups/#{url_encode team_id}/members/#{user_id}", body: body)
171
179
  end
172
180
 
173
181
  # Removes user from user group.
@@ -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
@@ -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.0.0'
5
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
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.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nihad Abbasov
8
8
  - Sean Edge
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-10-29 00:00:00.000000000 Z
12
+ date: 2025-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: base64
@@ -199,7 +199,7 @@ metadata:
199
199
  bug_tracker_uri: https://github.com/NARKOZ/gitlab/issues
200
200
  changelog_uri: https://github.com/NARKOZ/gitlab/releases
201
201
  funding_uri: https://github.com/NARKOZ/SponsorMe
202
- post_install_message:
202
+ post_install_message:
203
203
  rdoc_options: []
204
204
  require_paths:
205
205
  - lib
@@ -207,15 +207,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
207
  requirements:
208
208
  - - ">="
209
209
  - !ruby/object:Gem::Version
210
- version: '3.1'
210
+ version: '3.2'
211
211
  required_rubygems_version: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - ">="
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
216
  requirements: []
217
- rubygems_version: 3.5.16
218
- signing_key:
217
+ rubygems_version: 3.5.22
218
+ signing_key:
219
219
  specification_version: 4
220
220
  summary: A Ruby wrapper and CLI for the GitLab API
221
221
  test_files: []