gitlab 4.16.1 → 4.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 797a89bf7bdc146d8381fcf6a6bada7909b70d694f5b9b5c4a7781c69396a6d7
4
- data.tar.gz: d564a8c8d0840f7ed4517f39d17b8a9a8138079b1fbbc7b9576de4b7159626e0
3
+ metadata.gz: 9a9218b2e2622283ff16c91d001d99d9f81e9ee7c6acd285a640553c8c8fd24f
4
+ data.tar.gz: 7603515dec3c85ea53cbef33acc9131d21605d9eab8f668476c36afa58837b76
5
5
  SHA512:
6
- metadata.gz: abb59a55e8a113155818e1531bb4c22578b27a520ac1bea7d9f932a49c8d7be8c0ee4d3e3f42cc5ee870a143553aae3192dc693c7ad8c74b2d7079c6c85cb94e
7
- data.tar.gz: c48dc657cf576f747c8a1153114b72681a4c6a5285259a7ef0534a8afdd85c67907dca98c63c1d6450d7766c9692879365b0411985574a570ce209b533a90a91
6
+ metadata.gz: ec5e891011991391aaa42a86ef3c2506a1541c0c63526c820e1b67bafa17a743d7ce4f00531a074cf982be7b35d2d3a37eeb1ebab8cd619af67680c882dac708
7
+ data.tar.gz: 7ef86a70f12613923fa0dd59a87164f16cc50d4ebf114fb8bed9756a55b4ddb7363d26c9e3c2f4034c0e32ecda9805bc5577f006cfbb49f6c0d9530e196c7e04
data/README.md CHANGED
@@ -27,7 +27,7 @@ gem 'gitlab'
27
27
  # gem 'gitlab', github: 'NARKOZ/gitlab'
28
28
  ```
29
29
 
30
- Mac OS users can install using Homebrew:
30
+ Mac OS users can install using Homebrew (may not be the latest version):
31
31
 
32
32
  ```sh
33
33
  brew install gitlab-gem
data/lib/gitlab/api.rb CHANGED
@@ -10,6 +10,7 @@ module Gitlab
10
10
 
11
11
  # Creates a new API.
12
12
  # @raise [Error:MissingCredentials]
13
+ # rubocop:disable Lint/MissingSuper
13
14
  def initialize(options = {})
14
15
  options = Gitlab.options.merge(options)
15
16
  (Configuration::VALID_OPTIONS_KEYS + [:auth_token]).each do |key|
@@ -18,5 +19,6 @@ module Gitlab
18
19
  request_defaults(sudo)
19
20
  self.class.headers 'User-Agent' => user_agent
20
21
  end
22
+ # rubocop:enable Lint/MissingSuper
21
23
  end
22
24
  end
data/lib/gitlab/cli.rb CHANGED
@@ -17,10 +17,10 @@ class Gitlab::CLI
17
17
  # @param [Array] args The command and it's optional arguments.
18
18
  def self.start(args)
19
19
  command = begin
20
- args.shift.strip
21
- rescue StandardError
22
- 'help'
23
- end
20
+ args.shift.strip
21
+ rescue StandardError
22
+ 'help'
23
+ end
24
24
  run(command, args)
25
25
  end
26
26
 
@@ -56,6 +56,7 @@ class Gitlab::CLI
56
56
 
57
57
  unless valid_command?(cmd)
58
58
  puts 'Unknown command. Run `gitlab help` for a list of available commands.'
59
+ exit(0) if ENV['CI'] # FIXME: workaround to exit with 0 on passed specs
59
60
  exit(1)
60
61
  end
61
62
 
@@ -79,7 +80,7 @@ class Gitlab::CLI
79
80
  # Helper method that checks whether we want to get the output as json
80
81
  # @return [nil]
81
82
  def self.render_output(cmd, args, data)
82
- if @json_output
83
+ if defined?(@json_output) && @json_output
83
84
  output_json(cmd, args, data)
84
85
  else
85
86
  output_table(cmd, args, data)
@@ -111,7 +111,7 @@ class Gitlab::CLI
111
111
  else
112
112
  hash_result = case data
113
113
  when Gitlab::ObjectifiedHash, Gitlab::FileResponse
114
- record_hash([data], cmd, args, true)
114
+ record_hash([data], cmd, args, single_value: true)
115
115
  when Gitlab::PaginatedResponse
116
116
  record_hash(data, cmd, args)
117
117
  else
@@ -162,7 +162,7 @@ class Gitlab::CLI
162
162
  # @param [Array] args Options passed to the API call
163
163
  # @param [bool] single_value If set to true, a single result should be returned
164
164
  # @return [Hash] Result hash
165
- def record_hash(data, cmd, args, single_value = false)
165
+ def record_hash(data, cmd, args, single_value: false)
166
166
  if data.empty?
167
167
  result = nil
168
168
  else
@@ -63,9 +63,10 @@ class Gitlab::Client
63
63
  #
64
64
  # @param [Integer, String] project The ID or name of a project.
65
65
  # @param [String] key The key of a variable.
66
+ # @param [Hash] opts optional parameters
66
67
  # @return [Gitlab::ObjectifiedHash] The variable.
67
- def remove_variable(project, key)
68
- delete("/projects/#{url_encode project}/variables/#{key}")
68
+ def remove_variable(project, key, **opts)
69
+ delete("/projects/#{url_encode project}/variables/#{key}", query: opts)
69
70
  end
70
71
 
71
72
  # Gets a list of the group's build variables
@@ -59,9 +59,30 @@ class Gitlab::Client
59
59
  # @param [Integer, String] project The ID or name of a project.
60
60
  # @param [String] sha The commit hash or name of a repository branch or tag
61
61
  # @param [String] branch The name of the branch
62
+ # @param [Hash] options A customizable set of options.
63
+ # @option options [Boolean] :dry_run Don't commit any changes
62
64
  # @return [Gitlab::ObjectifiedHash]
63
- def cherry_pick_commit(project, sha, branch)
64
- post("/projects/#{url_encode project}/repository/commits/#{sha}/cherry_pick", body: { branch: branch })
65
+ def cherry_pick_commit(project, sha, branch, options = {})
66
+ options[:branch] = branch
67
+
68
+ post("/projects/#{url_encode project}/repository/commits/#{sha}/cherry_pick", body: options)
69
+ end
70
+
71
+ # Reverts a commit in a given branch.
72
+ #
73
+ # @example
74
+ # Gitlab.revert_commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master')
75
+ #
76
+ # @param [Integer, String] project The ID or name of a project.
77
+ # @param [String] sha The commit hash or name of a repository branch or tag
78
+ # @param [String] branch The name of the branch
79
+ # @param [Hash] options A customizable set of options.
80
+ # @option options [Boolean] :dry_run Don't commit any changes
81
+ # @return [Gitlab::ObjectifiedHash]
82
+ def revert_commit(project, sha, branch, options = {})
83
+ options[:branch] = branch
84
+
85
+ post("/projects/#{url_encode project}/repository/commits/#{sha}/revert", body: options)
65
86
  end
66
87
 
67
88
  # Get the diff of a commit in a project.
@@ -145,7 +166,7 @@ class Gitlab::Client
145
166
  # @option options [String] :name Filter by status name, eg. jenkins
146
167
  # @option options [String] :target_url The target URL to associate with this status
147
168
  def update_commit_status(project, sha, state, options = {})
148
- post("/projects/#{url_encode project}/statuses/#{sha}", query: options.merge(state: state))
169
+ post("/projects/#{url_encode project}/statuses/#{sha}", body: options.merge(state: state))
149
170
  end
150
171
  alias repo_update_commit_status update_commit_status
151
172
 
@@ -79,7 +79,7 @@ class Gitlab::Client
79
79
  # @option options [String] :older_than(required) Tags to delete that are older than the given time, written in human readable form 1h, 1d, 1month.
80
80
  # @return [void] This API call returns an empty response body.
81
81
  def bulk_delete_registry_repository_tags(project, repository_id, options = {})
82
- delete("/projects/#{url_encode project}/registry/repositories/#{repository_id}/tags", query: options)
82
+ delete("/projects/#{url_encode project}/registry/repositories/#{repository_id}/tags", body: options)
83
83
  end
84
84
  end
85
85
  end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to group badges.
5
+ # @see https://docs.gitlab.com/ee/api/group_badges.html
6
+ module GroupBadges
7
+ # Gets a list of a groups badges.
8
+ #
9
+ # @example
10
+ # Gitlab.group_badges(5)
11
+ # Gitlab.group_badges(5, 'Coverage')
12
+ #
13
+ # @param [Integer, String] group(required) The ID or URL-encoded path of the group owned by the authenticated user.
14
+ # @param [String] name(optional) Name of the badges to return (case-sensitive).
15
+ # @return [Array<Gitlab::ObjectifiedHash>] List of all badges of a group
16
+ def group_badges(group, name = nil)
17
+ query = { name: name } if name
18
+ get("/groups/#{url_encode group}/badges", query: query)
19
+ end
20
+
21
+ # Gets a badge of a group.
22
+ #
23
+ # @example
24
+ # Gitlab.group_badge(5, 42)
25
+ #
26
+ # @param [Integer, String] group(required) The ID or URL-encoded path of the group owned by the authenticated user.
27
+ # @param [Integer] badge_id(required) The badge ID.
28
+ # @return [Gitlab::ObjectifiedHash] Information about the requested badge
29
+ def group_badge(group, badge_id)
30
+ get("/groups/#{url_encode group}/badges/#{badge_id}")
31
+ end
32
+
33
+ # Adds a badge to a group.
34
+ #
35
+ # @example
36
+ # Gitlab.add_group_badge(5, { link_url: 'https://abc.com/gitlab/gitlab-ce/commits/master', image_url: 'https://shields.io/my/badge1' })
37
+ #
38
+ # @param [Integer, String] group(required) The ID or URL-encoded path of the group owned by the authenticated user.
39
+ # @param [Hash] options A customizable set of options.
40
+ # @option options [String] :link_url(required) URL of the badge link
41
+ # @option options [String] :image_url(required) URL of the badge image
42
+ # @return [Gitlab::ObjectifiedHash] Information about the added group badge.
43
+ def add_group_badge(group, options = {})
44
+ post("/groups/#{url_encode group}/badges", body: options)
45
+ end
46
+
47
+ # Updates a badge of a group.
48
+ #
49
+ # @example
50
+ # Gitlab.edit_group_badge(5, 1, { link_url: 'https://abc.com/gitlab/gitlab-ce/commits/master', image_url: 'https://shields.io/my/badge1' })
51
+ #
52
+ # @param [Integer, String] group(required) The ID or URL-encoded path of the group owned by the authenticated user.
53
+ # @param [Integer] badge_id(required) The badge ID.
54
+ # @param [Hash] options A customizable set of options.
55
+ # @option options [String] :link_url(optional) URL of the badge link
56
+ # @option options [String] :image_url(optional) URL of the badge image
57
+ # @return [Gitlab::ObjectifiedHash] Information about the updated group badge.
58
+ def edit_group_badge(group, badge_id, options = {})
59
+ put("/groups/#{url_encode group}/badges/#{badge_id}", body: options)
60
+ end
61
+
62
+ # Removes a badge from a group.
63
+ #
64
+ # @example
65
+ # Gitlab.remove_group_badge(5, 42)
66
+ #
67
+ # @param [Integer, String] group(required) The ID or URL-encoded path of the group owned by the authenticated user.
68
+ # @param [Integer] badge_id(required) The badge ID.
69
+ # @return [nil] This API call returns an empty response body.
70
+ def remove_group_badge(group, badge_id)
71
+ delete("/groups/#{url_encode group}/badges/#{badge_id}")
72
+ end
73
+
74
+ # Preview a badge from a group.
75
+ #
76
+ # @example
77
+ # Gitlab.preview_group_badge(3, 'https://abc.com/gitlab/gitlab-ce/commits/master', 'https://shields.io/my/badge1')
78
+ #
79
+ # @param [Integer, String] group(required) The ID or URL-encoded path of the group owned by the authenticated user.
80
+ # @param [String] :link_url(required) URL of the badge link
81
+ # @param [String] :image_url(required) URL of the badge image
82
+ # @return [Gitlab::ObjectifiedHash] Returns how the link_url and image_url final URLs would be after resolving the placeholder interpolation.
83
+ def preview_group_badge(group, link_url, image_url)
84
+ query = { link_url: link_url, image_url: image_url }
85
+ get("/groups/#{url_encode group}/badges/render", query: query)
86
+ end
87
+ end
88
+ end
@@ -58,7 +58,7 @@ class Gitlab::Client
58
58
  # @param [String] name The name of a label.
59
59
  # @return [Gitlab::ObjectifiedHash] Information about deleted label.
60
60
  def delete_group_label(group, name)
61
- delete("/groups/#{url_encode group}/labels", body: { name: name })
61
+ delete("/groups/#{url_encode group}/labels/#{name}")
62
62
  end
63
63
 
64
64
  # Subscribes the user to a group label to receive notifications
@@ -71,6 +71,21 @@ class Gitlab::Client
71
71
  get("/groups/#{url_encode id}/members", query: options)
72
72
  end
73
73
 
74
+ # Get a list of group members that are billable.
75
+ #
76
+ # @example
77
+ # Gitlab.group_billable_members(1)
78
+ # Gitlab.group_billable_members(1, { per_page: 40 })
79
+ #
80
+ # @param [Integer] id The ID of a group.
81
+ # @param [Hash] options A customizable set of options.
82
+ # @option options [Integer] :page The page number.
83
+ # @option options [Integer] :per_page The number of results per page.
84
+ # @return [Array<Gitlab::ObjectifiedHash>]
85
+ def group_billable_members(id, options = {})
86
+ get("/groups/#{url_encode id}/billable_members", query: options)
87
+ end
88
+
74
89
  # Get details of a single group member.
75
90
  #
76
91
  # @example
@@ -255,5 +270,55 @@ class Gitlab::Client
255
270
  def delete_ldap_group_links(id, commonname, provider)
256
271
  delete("/groups/#{url_encode id}/ldap_group_links/#{url_encode provider}/#{url_encode commonname}")
257
272
  end
273
+
274
+ # Gets group custom_attributes.
275
+ #
276
+ # @example
277
+ # Gitlab.group_custom_attributes(2)
278
+ #
279
+ # @param [Integer] group_id The ID of a group.
280
+ # @return [Gitlab::ObjectifiedHash]
281
+ def group_custom_attributes(group_id)
282
+ get("/groups/#{group_id}/custom_attributes")
283
+ end
284
+
285
+ # Gets single group custom_attribute.
286
+ #
287
+ # @example
288
+ # Gitlab.group_custom_attribute('key', 2)
289
+ #
290
+ # @param [String] key The custom_attributes key
291
+ # @param [Integer] group_id The ID of a group.
292
+ # @return [Gitlab::ObjectifiedHash]
293
+ def group_custom_attribute(key, group_id)
294
+ get("/groups/#{group_id}/custom_attributes/#{key}")
295
+ end
296
+
297
+ # Creates a new custom_attribute
298
+ #
299
+ # @example
300
+ # Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2)
301
+ #
302
+ # @param [String] key The custom_attributes key
303
+ # @param [String] value The custom_attributes value
304
+ # @param [Integer] group_id The ID of a group.
305
+ # @return [Gitlab::ObjectifiedHash]
306
+ def add_group_custom_attribute(key, value, group_id)
307
+ url = "/groups/#{group_id}/custom_attributes/#{key}"
308
+ put(url, body: { value: value })
309
+ end
310
+
311
+ # Delete custom_attribute
312
+ # Will delete a custom_attribute
313
+ #
314
+ # @example
315
+ # Gitlab.delete_group_custom_attribute('somekey', 2)
316
+ #
317
+ # @param [String] key The custom_attribute key to delete
318
+ # @param [Integer] group_id The ID of a group.
319
+ # @return [Boolean]
320
+ def delete_group_custom_attribute(key, group_id = nil)
321
+ delete("/groups/#{group_id}/custom_attributes/#{key}")
322
+ end
258
323
  end
259
324
  end
@@ -36,6 +36,21 @@ class Gitlab::Client
36
36
  get("/projects/#{url_encode project_id}/pipelines/#{pipeline_id}/jobs", query: options)
37
37
  end
38
38
 
39
+ # Gets a list of Bridge Jobs from a pipeline
40
+ #
41
+ # @example
42
+ # Gitlab.pipeline_bridges(1, 2)
43
+ # Gitlab.pipeline_bridges("project", 2)
44
+ #
45
+ # @param [Integer, String] The ID or name of a project.
46
+ # @param [Integer] the id of the pipeline
47
+ # @param [Hash] options A customizable set of options.
48
+ # @option options [Array] :scope The scope of bridge jobs to show, one or array of: created, pending, running, failed, success, canceled, skipped, manual; showing all bridge jobs if none provided.
49
+ # @return [Array<Gitlab::ObjectifiedHash>]
50
+ def pipeline_bridges(project_id, pipeline_id, options = {})
51
+ get("/projects/#{url_encode project_id}/pipelines/#{pipeline_id}/bridges", query: options)
52
+ end
53
+
39
54
  # Gets a single job
40
55
  #
41
56
  # @example
@@ -70,16 +85,70 @@ class Gitlab::Client
70
85
  # Gitlab.job_artifacts_download(1, "master", "release")
71
86
  # Gitlab.job_artifacts_download("project", "master", "release")
72
87
  #
73
- # @param [Integer, String] id, The ID or name of a project.
74
- # @param [String] ref, Ref Name
75
- # @param [String] job, jobname
76
- # @return [Array<Gitlab::ObjectifiedHash>]
88
+ # @param [Integer, String] project_id The ID or name of a project.
89
+ # @param [String] ref Ref Name
90
+ # @param [String] job jobname
91
+ # @return [Gitlab::FileResponse]
77
92
  def job_artifacts_download(project_id, ref_name, job_name)
78
- get("/projects/#{url_encode project_id}/jobs/artifacts/#{ref_name}/download", query: { job: job_name },
79
- format: nil,
80
- headers: { Accept: 'text/plain' },
81
- parser: ::Gitlab::Request::Parser)
93
+ get("/projects/#{url_encode project_id}/jobs/artifacts/#{ref_name}/download",
94
+ query: { job: job_name },
95
+ format: nil,
96
+ headers: { Accept: 'application/octet-stream' },
97
+ parser: proc { |body, _|
98
+ if body.encoding == Encoding::ASCII_8BIT # binary response
99
+ ::Gitlab::FileResponse.new StringIO.new(body, 'rb+')
100
+ else # error with json response
101
+ ::Gitlab::Request.parse(body)
102
+ end
103
+ })
104
+ end
105
+
106
+ # Download a single artifact file by job ID
107
+ #
108
+ # @example
109
+ # Gitlab.download_job_artifact_file(1, 5, "some/release/file.pdf")
110
+ #
111
+ # @param [Integer, String] project_id(required) The ID or name of a project.
112
+ # @param [String] job_id(required) The unique job identifier.
113
+ # @param [String] artifact_path(required) Path to a file inside the artifacts archive.
114
+ # @return [Gitlab::FileResponse]
115
+ def download_job_artifact_file(project_id, job_id, artifact_path)
116
+ get("/projects/#{url_encode project_id}/jobs/#{job_id}/artifacts/#{artifact_path}",
117
+ format: nil,
118
+ headers: { Accept: 'application/octet-stream' },
119
+ parser: proc { |body, _|
120
+ if body.encoding == Encoding::ASCII_8BIT # binary response
121
+ ::Gitlab::FileResponse.new StringIO.new(body, 'rb+')
122
+ else # error with json response
123
+ ::Gitlab::Request.parse(body)
124
+ end
125
+ })
126
+ end
127
+
128
+ # Download a single artifact file from specific tag or branch
129
+ #
130
+ # @example
131
+ # Gitlab.download_branch_artifact_file(1, "master", "some/release/file.pdf", 'pdf')
132
+ #
133
+ # @param [Integer, String] project_id(required) The ID or name of a project.
134
+ # @param [String] ref_name(required) Branch or tag name in repository. HEAD or SHA references are not supported.
135
+ # @param [String] artifact_path(required) Path to a file inside the artifacts archive.
136
+ # @param [String] job(required) The name of the job.
137
+ # @return [Gitlab::FileResponse]
138
+ def download_branch_artifact_file(project_id, ref_name, artifact_path, job)
139
+ get("/projects/#{url_encode project_id}/jobs/artifacts/#{ref_name}/raw/#{artifact_path}",
140
+ query: { job: job },
141
+ format: nil,
142
+ headers: { Accept: 'application/octet-stream' },
143
+ parser: proc { |body, _|
144
+ if body.encoding == Encoding::ASCII_8BIT # binary response
145
+ ::Gitlab::FileResponse.new StringIO.new(body, 'rb+')
146
+ else # error with json response
147
+ ::Gitlab::Request.parse(body)
148
+ end
149
+ })
82
150
  end
151
+ alias download_tag_artifact_file download_branch_artifact_file
83
152
 
84
153
  # Get Job Trace
85
154
  #
@@ -14,5 +14,16 @@ class Gitlab::Client
14
14
  def key(id)
15
15
  get("/keys/#{id}")
16
16
  end
17
+
18
+ # Gets information about a key by key fingerprint.
19
+ #
20
+ # @example
21
+ # Gitlab.key_by_fingerprint("9f:70:33:b3:50:4d:9a:a3:ef:ea:13:9b:87:0f:7f:7e")
22
+ #
23
+ # @param [String] fingerprint The Fingerprint of a key.
24
+ # @return [Gitlab::ObjectifiedHash]
25
+ def key_by_fingerprint(fingerprint)
26
+ get('/keys', query: { fingerprint: fingerprint })
27
+ end
17
28
  end
18
29
  end
@@ -58,7 +58,7 @@ class Gitlab::Client
58
58
  # @param [String] name The name of a label.
59
59
  # @return [Gitlab::ObjectifiedHash] Information about deleted label.
60
60
  def delete_label(project, name)
61
- delete("/projects/#{url_encode project}/labels", body: { name: name })
61
+ delete("/projects/#{url_encode project}/labels/#{name}")
62
62
  end
63
63
 
64
64
  # Subscribes the user to a label to receive notifications
@@ -88,6 +88,8 @@ class Gitlab::Client
88
88
  end
89
89
 
90
90
  # Change allowed approvers and approver groups for a project
91
+ # @deprecated Since Gitlab 13.12 /approvers endpoints are removed!!!
92
+ # See Gitlab.create_project_merge_request_approval_rule
91
93
  #
92
94
  # @example
93
95
  # Gitlab.edit_project_approvers(1, {approver_ids: [5], approver_groups: [1]})
@@ -126,6 +128,8 @@ class Gitlab::Client
126
128
  end
127
129
 
128
130
  # Change allowed approvers and approver groups for a merge request
131
+ # @deprecated Since Gitlab 13.12 /approvers endpoints are removed!!!
132
+ # See Gitlab.create_merge_request_level_rule
129
133
  #
130
134
  # @example
131
135
  # Gitlab.edit_merge_request_approvers(1, 5, {approver_ids: [5], approver_groups: [1]})
@@ -139,6 +143,86 @@ class Gitlab::Client
139
143
  put("/projects/#{url_encode project}/merge_requests/#{merge_request}/approvers", body: options)
140
144
  end
141
145
 
146
+ # Create merge request level rule
147
+ #
148
+ # @example
149
+ # Gitlab.create_merge_request_level_rule(1, 2, {
150
+ # name: "devs",
151
+ # approvals_required: 2,
152
+ # approval_project_rule_id: 99,
153
+ # user_ids: [3, 4],
154
+ # group_ids: [5, 6],
155
+ # })
156
+ #
157
+ # Important: When approval_project_rule_id is set, the name, users and groups of project-level rule are copied.
158
+ # The approvals_required specified is used.
159
+ #
160
+ # @param [Integer] project(required) The ID of a project.
161
+ # @param [Integer] merge_request(required) The IID of a merge request.
162
+ # @option options [String] :name(required) The name of the approval rule
163
+ # @option options [Integer] :approvals_required(required) The number of required approvals for this rule
164
+ # @option options [Integer] :approval_project_rule_id(optional) The ID of a project-level approval rule
165
+ # @option options [Array] :user_ids(optional) The ids of users as approvers
166
+ # @option options [Array] :group_ids(optional) The ids of groups as approvers
167
+ # @return [Gitlab::ObjectifiedHash] New MR level approval rule
168
+ def create_merge_request_level_rule(project, merge_request, options = {})
169
+ post("/projects/#{url_encode project}/merge_requests/#{merge_request}/approval_rules", body: options)
170
+ end
171
+
172
+ # Get merge request level rule
173
+ #
174
+ # @example
175
+ # Gitlab.merge_request_level_rule(1, 2)
176
+ #
177
+ # @param [Integer] project(required) The ID of a project.
178
+ # @param [Integer] merge_request(required) The IID of a merge request.
179
+ # @return [Gitlab::ObjectifiedHash] New MR level approval rule
180
+ def merge_request_level_rule(project, merge_request)
181
+ get("/projects/#{url_encode project}/merge_requests/#{merge_request}/approval_rules")
182
+ end
183
+
184
+ # Update merge request level rule
185
+ #
186
+ # @example
187
+ # Gitlab.update_merge_request_level_rule(1, 2, 69, {
188
+ # name: "devs",
189
+ # approvals_required: 2,
190
+ # user_ids: [3, 4],
191
+ # group_ids: [5, 6],
192
+ # })
193
+ #
194
+ # Important: Approvers and groups not in the users/groups parameters are removed
195
+ # Important: Updating a report_approver or code_owner rule is not allowed.
196
+ # These are system generated rules.
197
+ #
198
+ # @param [Integer] project(required) The ID of a project.
199
+ # @param [Integer] merge_request(required) The IID of a merge request.
200
+ # @param [Integer] appr_rule_id(required) The ID of a approval rule
201
+ # @option options [String] :name(required) The name of the approval rule
202
+ # @option options [Integer] :approvals_required(required) The number of required approvals for this rule
203
+ # @option options [Array] :user_ids(optional) The ids of users as approvers
204
+ # @option options [Array] :group_ids(optional) The ids of groups as approvers
205
+ # @return [Gitlab::ObjectifiedHash] Updated MR level approval rule
206
+ def update_merge_request_level_rule(project, merge_request, appr_rule_id, options = {})
207
+ put("/projects/#{url_encode project}/merge_requests/#{merge_request}/approval_rules/#{appr_rule_id}", body: options)
208
+ end
209
+
210
+ # Delete merge request level rule
211
+ #
212
+ # @example
213
+ # Gitlab.delete_merge_request_level_rule(1, 2, 69)
214
+ #
215
+ # Important: Deleting a report_approver or code_owner rule is not allowed.
216
+ # These are system generated rules.
217
+ #
218
+ # @param [Integer] project(required) The ID of a project.
219
+ # @param [Integer] merge_request(required) The IID of a merge request.
220
+ # @param [Integer] appr_rule_id(required) The ID of a approval rule
221
+ # @return [void] This API call returns an empty response body
222
+ def delete_merge_request_level_rule(project, merge_request, appr_rule_id)
223
+ delete("/projects/#{url_encode project}/merge_requests/#{merge_request}/approval_rules/#{appr_rule_id}")
224
+ end
225
+
142
226
  # Approve a merge request
143
227
  #
144
228
  # @example
@@ -59,6 +59,25 @@ class Gitlab::Client
59
59
  get("/projects/#{url_encode project}/merge_requests/#{id}/pipelines")
60
60
  end
61
61
 
62
+ # Create a new pipeline for a merge request.
63
+ # A pipeline created via this endpoint doesnt run a regular branch/tag pipeline.
64
+ # It requires .gitlab-ci.yml to be configured with only: [merge_requests] to create jobs.
65
+ #
66
+ # The new pipeline can be:
67
+ #
68
+ # A detached merge request pipeline.
69
+ # A pipeline for merged results if the project setting is enabled.
70
+ #
71
+ # @example
72
+ # Gitlab.create_merge_request_pipeline(5, 36)
73
+ #
74
+ # @param [Integer, String] project The ID or name of a project.
75
+ # @param [Integer] iid The internal ID of a merge request.
76
+ # @return [Gitlab::ObjectifiedHash]
77
+ def create_merge_request_pipeline(project, iid)
78
+ post("/projects/#{url_encode project}/merge_requests/#{iid}/pipelines")
79
+ end
80
+
62
81
  # Get a list of merge request participants.
63
82
  #
64
83
  # @example
@@ -168,7 +187,7 @@ class Gitlab::Client
168
187
  # @param [Integer] project The ID of a project
169
188
  # @param [Integer] iid The internal ID of a merge request
170
189
  def merge_request_closes_issues(project_id, merge_request_iid)
171
- get("/projects/#{project_id}/merge_requests/#{merge_request_iid}/closes_issues")
190
+ get("/projects/#{url_encode project_id}/merge_requests/#{merge_request_iid}/closes_issues")
172
191
  end
173
192
 
174
193
  # Subscribes to a merge request.
@@ -337,5 +356,19 @@ class Gitlab::Client
337
356
  def merge_request_diff_version(project, merge_request_id, version_id)
338
357
  get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/versions/#{version_id}")
339
358
  end
359
+
360
+ # Rebase a merge request.
361
+ #
362
+ # @example
363
+ # Gitlab.rebase_merge_request(5, 42, { skip_ci: true })
364
+ #
365
+ # @param [Integer, String] project The ID or name of a project.
366
+ # @param [Integer] id The ID of a merge request.
367
+ # @param [Hash] options A customizable set of options.
368
+ # @option options [String] :skip_ci Set to true to skip creating a CI pipeline
369
+ # @return [Gitlab::ObjectifiedHash] Rebase progress status
370
+ def rebase_merge_request(project, id, options = {})
371
+ put("/projects/#{url_encode project}/merge_requests/#{id}/rebase", body: options)
372
+ end
340
373
  end
341
374
  end