gitlab 4.18.0 → 4.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +14 -11
- data/lib/gitlab/cli_helpers.rb +1 -1
- data/lib/gitlab/client/groups.rb +128 -0
- data/lib/gitlab/client/issues.rb +11 -0
- data/lib/gitlab/client/merge_requests.rb +24 -0
- data/lib/gitlab/client/merge_trains.rb +55 -0
- data/lib/gitlab/client/packages.rb +95 -0
- data/lib/gitlab/client/pipelines.rb +25 -0
- data/lib/gitlab/client/project_exports.rb +54 -0
- data/lib/gitlab/client/project_releases.rb +11 -0
- data/lib/gitlab/client/repositories.rb +17 -0
- data/lib/gitlab/client/runners.rb +67 -0
- data/lib/gitlab/client/users.rb +136 -1
- data/lib/gitlab/client.rb +3 -1
- data/lib/gitlab/error.rb +17 -1
- data/lib/gitlab/headers/page_links.rb +37 -0
- data/lib/gitlab/headers/total.rb +29 -0
- data/lib/gitlab/paginated_response.rb +6 -1
- data/lib/gitlab/request.rb +2 -2
- data/lib/gitlab/version.rb +1 -1
- data/lib/gitlab.rb +5 -2
- metadata +16 -7
- data/lib/gitlab/page_links.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f389659769cea087b957d51a996f1cb7de58b26a839b254bd110cef3ea7c8c5
|
4
|
+
data.tar.gz: b33dde60af1a08e93da7e97e12b8ba2715bd2e12f3d857080ef39dc114f42d03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9577ff13278017671a7c72b5eb41d48de9aac067c5417eddccb0d51ee8c86922c462e4e75d5aeeed22be83827ebdc9678d50ab1d494042849f0f191698826c5c
|
7
|
+
data.tar.gz: 2661411c9b542b36b81ba8629310e75d89e9353a7be9bb7c077ce9ae0d0e649c6d9412edb47ce5709fa76630102307e2b7a55c2c3f380d9535015cb4dce4f69b
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Gitlab
|
2
2
|
|
3
|
-
[![Build Status](https://img.shields.io/github/workflow/status/NARKOZ/gitlab/
|
4
|
-
[![Inline docs](https://inch-ci.org/github/NARKOZ/gitlab.svg)](https://inch-ci.org/github/NARKOZ/gitlab)
|
3
|
+
[![Build Status](https://img.shields.io/github/actions/workflow/status/NARKOZ/gitlab/ci.yml?branch=master)](https://github.com/NARKOZ/gitlab/actions/workflows/ci.yml)
|
5
4
|
[![Gem version](https://img.shields.io/gem/v/gitlab.svg)](https://rubygems.org/gems/gitlab)
|
6
5
|
[![License](https://img.shields.io/badge/license-BSD-red.svg)](https://github.com/NARKOZ/gitlab/blob/master/LICENSE.txt)
|
7
6
|
|
@@ -9,8 +8,7 @@
|
|
9
8
|
[documentation](https://www.rubydoc.info/gems/gitlab/frames) |
|
10
9
|
[gitlab-live](https://github.com/NARKOZ/gitlab-live)
|
11
10
|
|
12
|
-
Gitlab is a Ruby wrapper and CLI for the [GitLab API](https://docs.gitlab.com/
|
13
|
-
As of version `4.0.0` this gem only supports GitLab API v4.
|
11
|
+
Gitlab is a Ruby wrapper and CLI for the [GitLab API](https://docs.gitlab.com/ee/api/index.html).
|
14
12
|
|
15
13
|
## Installation
|
16
14
|
|
@@ -97,6 +95,10 @@ Gitlab.sudo = 'other_user'
|
|
97
95
|
Gitlab.sudo = nil
|
98
96
|
# => nil
|
99
97
|
|
98
|
+
# set the private token to an empty string to make unauthenticated API requests
|
99
|
+
Gitlab.private_token = ''
|
100
|
+
# => ""
|
101
|
+
|
100
102
|
# a paginated response
|
101
103
|
projects = Gitlab.projects(per_page: 5)
|
102
104
|
|
@@ -121,8 +123,9 @@ For more information, refer to [documentation](https://www.rubydoc.info/gems/git
|
|
121
123
|
|
122
124
|
It is possible to use this gem as a command line interface to GitLab. In order to make that work you need to set a few environment variables:
|
123
125
|
```sh
|
124
|
-
export GITLAB_API_ENDPOINT=https://gitlab.
|
125
|
-
export GITLAB_API_PRIVATE_TOKEN=<your private token from /profile/
|
126
|
+
export GITLAB_API_ENDPOINT=https://gitlab.example.com/api/v4
|
127
|
+
export GITLAB_API_PRIVATE_TOKEN=<your private token from /profile/personal_access_tokens>
|
128
|
+
|
126
129
|
# This one is optional and can be used to set any HTTParty option you may need
|
127
130
|
# using YAML hash syntax. For example, this is how you would disable SSL
|
128
131
|
# verification (useful if using a self-signed cert).
|
@@ -131,21 +134,21 @@ export GITLAB_API_HTTPARTY_OPTIONS="{verify: false}"
|
|
131
134
|
|
132
135
|
Usage:
|
133
136
|
|
134
|
-
When you want to know which CLI commands are supported, take a look at the client [commands implemented in this gem](https://www.rubydoc.info/gems/gitlab/4.
|
137
|
+
When you want to know which CLI commands are supported, take a look at the client [commands implemented in this gem](https://www.rubydoc.info/gems/gitlab/4.18.0/Gitlab/Client). Any of those methods can be called as a command by passing the parameters of the commands as parameters of the CLI.
|
135
138
|
|
136
139
|
Usage examples:
|
137
140
|
|
138
141
|
```sh
|
139
142
|
# list users
|
140
|
-
# see: https://www.rubydoc.info/gems/gitlab/
|
143
|
+
# see: https://www.rubydoc.info/gems/gitlab/Gitlab/Client/Users#users-instance_method
|
141
144
|
gitlab users
|
142
145
|
|
143
146
|
# get current user
|
144
|
-
# see: https://www.rubydoc.info/gems/gitlab/
|
147
|
+
# see: https://www.rubydoc.info/gems/gitlab/Gitlab/Client/Users#user-instance_method
|
145
148
|
gitlab user
|
146
149
|
|
147
150
|
# get a user
|
148
|
-
# see: https://www.rubydoc.info/gems/gitlab/
|
151
|
+
# see: https://www.rubydoc.info/gems/gitlab/Gitlab/Client/Users#user-instance_method
|
149
152
|
gitlab user 2
|
150
153
|
|
151
154
|
# filter output
|
@@ -157,7 +160,7 @@ gitlab user --except=email,bio
|
|
157
160
|
gitlab user 2 --json
|
158
161
|
|
159
162
|
# passing options hash to a command (use YAML)
|
160
|
-
# see: https://www.rubydoc.info/gems/gitlab/
|
163
|
+
# see: https://www.rubydoc.info/gems/gitlab/Gitlab/Client/MergeRequests#create_merge_request-instance_method
|
161
164
|
gitlab create_merge_request 4 "New merge request" "{source_branch: 'new_branch', target_branch: 'master', assignee_id: 42}"
|
162
165
|
|
163
166
|
```
|
data/lib/gitlab/cli_helpers.rb
CHANGED
data/lib/gitlab/client/groups.rb
CHANGED
@@ -71,6 +71,40 @@ class Gitlab::Client
|
|
71
71
|
get("/groups/#{url_encode id}/members", query: options)
|
72
72
|
end
|
73
73
|
|
74
|
+
# Gets a list of all group members including inherited members.
|
75
|
+
#
|
76
|
+
# @example
|
77
|
+
# Gitlab.all_group_members(1)
|
78
|
+
# Gitlab.all_group_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 all_group_members(id, options = {})
|
86
|
+
get("/groups/#{url_encode id}/members/all", query: options)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Get a list of descendant groups of a group.
|
90
|
+
#
|
91
|
+
# @example
|
92
|
+
# Gitlab.group_descendants(42)
|
93
|
+
#
|
94
|
+
# @param [Integer] id the ID of a group
|
95
|
+
# @param [Hash] options A customizable set of options.
|
96
|
+
# @option options [String] :skip_groups Skip the group IDs passed.
|
97
|
+
# @option options [String] :all_available Show all the groups you have access to (defaults to false for authenticated users).
|
98
|
+
# @option options [String] :search Return the list of authorized groups matching the search criteria.
|
99
|
+
# @option options [String] :order_by Order groups by name or path. Default is name.
|
100
|
+
# @option options [String] :sort Order groups in asc or desc order. Default is asc.
|
101
|
+
# @option options [String] :statistics Include group statistics (admins only).
|
102
|
+
# @option options [String] :owned Limit to groups owned by the current user.
|
103
|
+
# @return [Array<Gitlab::ObjectifiedHash>] List of all subgroups under a group
|
104
|
+
def group_descendants(id, options = {})
|
105
|
+
get("/groups/#{url_encode id}/descendant_groups", query: options)
|
106
|
+
end
|
107
|
+
|
74
108
|
# Get a list of group members that are billable.
|
75
109
|
#
|
76
110
|
# @example
|
@@ -320,5 +354,99 @@ class Gitlab::Client
|
|
320
354
|
def delete_group_custom_attribute(key, group_id = nil)
|
321
355
|
delete("/groups/#{group_id}/custom_attributes/#{key}")
|
322
356
|
end
|
357
|
+
|
358
|
+
# List all the specified groups hooks
|
359
|
+
#
|
360
|
+
# @example
|
361
|
+
# Gitlab.list_group_hooks(3)
|
362
|
+
#
|
363
|
+
# @param [Integer] group_id The ID of a group.
|
364
|
+
# @return [Gitlab::PaginatedResponse] List of registered hooks https://docs.gitlab.com/ee/api/groups.html#hooks
|
365
|
+
def list_group_hooks(group_id)
|
366
|
+
get("/groups/#{group_id}/hooks")
|
367
|
+
end
|
368
|
+
|
369
|
+
# get specified group hook
|
370
|
+
#
|
371
|
+
# @example
|
372
|
+
# Gitlab.group_hook(3, 1)
|
373
|
+
#
|
374
|
+
# @param [Integer] group_id The ID of a group.
|
375
|
+
# @param [Integer] hook_id The ID of the hook.
|
376
|
+
# @return [Gitlab::ObjectifiedHash] The hook https://docs.gitlab.com/ee/api/groups.html#get-group-hook
|
377
|
+
def group_hook(group_id, hook_id)
|
378
|
+
get("/groups/#{group_id}/hooks/#{hook_id}")
|
379
|
+
end
|
380
|
+
|
381
|
+
# Add a new group hook
|
382
|
+
#
|
383
|
+
# @example
|
384
|
+
# Gitlab.add_group_hook(3, "https://example.com/my-hook-receiver", {token: "verify me"})
|
385
|
+
#
|
386
|
+
# @param [Integer] group_id The ID of a group.
|
387
|
+
# @param [String] the hook url which will receive the selected events
|
388
|
+
# @option options [Boolean] :name The name of the group.
|
389
|
+
# @option options [Boolean] :push_events Trigger hook on push events
|
390
|
+
# @potion options [String] :push_events_branch_filter Trigger hook on push events for matching branches only.
|
391
|
+
# @option options [Boolean] :issues_events Trigger hook on issues events
|
392
|
+
# @option options [Boolean] :confidential_issues_events Trigger hook on confidential issues events
|
393
|
+
# @option options [Boolean] :merge_requests_events Trigger hook on merge requests events
|
394
|
+
# @option options [Boolean] :tag_push_events Trigger hook on tag push events
|
395
|
+
# @option options [Boolean] :note_events Trigger hook on note events
|
396
|
+
# @option options [Boolean] :confidential_note_events Trigger hook on confidential note events
|
397
|
+
# @option options [Boolean] :job_events Trigger hook on job events
|
398
|
+
# @option options [Boolean] :pipeline_events Trigger hook on pipeline events
|
399
|
+
# @option options [Boolean] :wiki_page_events Trigger hook on wiki page events
|
400
|
+
# @option options [Boolean] :deployment_events Trigger hook on deployment events
|
401
|
+
# @option options [Boolean] :releases_events Trigger hook on release events
|
402
|
+
# @option options [Boolean] :subgroup_events Trigger hook on subgroup events
|
403
|
+
# @option options [Boolean] :enable_ssl_verification Do SSL verification when triggering the hook
|
404
|
+
# @option options [String] :token Secret token to validate received payloads; not returned in the response
|
405
|
+
# @return [Gitlab::ObjectifiedHash] Response body matches https://docs.gitlab.com/ee/api/groups.html#get-group-hook
|
406
|
+
def add_group_hook(group_id, url, options = {})
|
407
|
+
post("/groups/#{group_id}/hooks", body: options.merge(url: url))
|
408
|
+
end
|
409
|
+
|
410
|
+
# Edit a group hook
|
411
|
+
#
|
412
|
+
# @example
|
413
|
+
# Gitlab.edit_group_hook(3, 1, "https://example.com/my-hook-receiver", {token: "verify me"})
|
414
|
+
#
|
415
|
+
# @param [Integer] group_id The ID of a group.
|
416
|
+
# @param [Integer] hook_id The ID of a group.
|
417
|
+
# @param [String] the hook url which will receive the selected events
|
418
|
+
# @option options [Boolean] :name The name of the group.
|
419
|
+
# @option options [Boolean] :push_events Trigger hook on push events
|
420
|
+
# @potion options [String] :push_events_branch_filter Trigger hook on push events for matching branches only.
|
421
|
+
# @option options [Boolean] :issues_events Trigger hook on issues events
|
422
|
+
# @option options [Boolean] :confidential_issues_events Trigger hook on confidential issues events
|
423
|
+
# @option options [Boolean] :merge_requests_events Trigger hook on merge requests events
|
424
|
+
# @option options [Boolean] :tag_push_events Trigger hook on tag push events
|
425
|
+
# @option options [Boolean] :note_events Trigger hook on note events
|
426
|
+
# @option options [Boolean] :confidential_note_events Trigger hook on confidential note events
|
427
|
+
# @option options [Boolean] :job_events Trigger hook on job events
|
428
|
+
# @option options [Boolean] :pipeline_events Trigger hook on pipeline events
|
429
|
+
# @option options [Boolean] :wiki_page_events Trigger hook on wiki page events
|
430
|
+
# @option options [Boolean] :deployment_events Trigger hook on deployment events
|
431
|
+
# @option options [Boolean] :releases_events Trigger hook on release events
|
432
|
+
# @option options [Boolean] :subgroup_events Trigger hook on subgroup events
|
433
|
+
# @option options [Boolean] :enable_ssl_verification Do SSL verification when triggering the hook
|
434
|
+
# @option options [String] :token Secret token to validate received payloads; not returned in the response
|
435
|
+
# @return [Gitlab::ObjectifiedHash] Response body matches https://docs.gitlab.com/ee/api/groups.html#edit-group-hook
|
436
|
+
def edit_group_hook(group_id, hook_id, url, options = {})
|
437
|
+
post("/groups/#{group_id}/hooks/#{hook_id}", body: options.merge(url: url))
|
438
|
+
end
|
439
|
+
|
440
|
+
# Delete a group hook
|
441
|
+
#
|
442
|
+
# @example
|
443
|
+
# Gitlab.delete_group_hook(3, 1)
|
444
|
+
#
|
445
|
+
# @param [Integer] group_id The ID of a group.
|
446
|
+
# @param [Integer] hook_id The ID of a group.
|
447
|
+
# @return [Gitlab::ObjectifiedHash] no body, will evaluate to an empty hash. https://docs.gitlab.com/ee/api/groups.html#delete-group-hook
|
448
|
+
def delete_group_hook(group_id, hook_id)
|
449
|
+
delete("/groups/#{group_id}/hooks/#{hook_id}")
|
450
|
+
end
|
323
451
|
end
|
324
452
|
end
|
data/lib/gitlab/client/issues.rb
CHANGED
@@ -227,5 +227,16 @@ class Gitlab::Client
|
|
227
227
|
def merge_requests_closing_issue_on_merge(project, id)
|
228
228
|
get("/projects/#{url_encode project}/issues/#{id}/closed_by")
|
229
229
|
end
|
230
|
+
|
231
|
+
# List related merge requests
|
232
|
+
#
|
233
|
+
# @example
|
234
|
+
# Gitlab.related_merge_requests(3, 42)
|
235
|
+
#
|
236
|
+
# @param [Integer, String] project The ID or name of a project.
|
237
|
+
# @param [Integer] id The ID of an issue.
|
238
|
+
def related_merge_requests(project, id)
|
239
|
+
get("/projects/#{url_encode project}/issues/#{id}/related_merge_requests")
|
240
|
+
end
|
230
241
|
end
|
231
242
|
end
|
@@ -332,6 +332,30 @@ class Gitlab::Client
|
|
332
332
|
delete("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions/#{discussion_id}/notes/#{note_id}")
|
333
333
|
end
|
334
334
|
|
335
|
+
# Delete a merge request
|
336
|
+
#
|
337
|
+
# @example
|
338
|
+
# Gitlab.delete_merge_request(5, 1)
|
339
|
+
# Gitlab.delete_merge_request('gitlab', 1)
|
340
|
+
# @param [Integer, String] project The ID or name of a project.
|
341
|
+
# @param [Integer] id The ID of a merge request.
|
342
|
+
# @return [Gitlab::ObjectifiedHash] An empty response.
|
343
|
+
def delete_merge_request(project, merge_request_id)
|
344
|
+
delete("/projects/#{url_encode project}/merge_requests/#{merge_request_id}")
|
345
|
+
end
|
346
|
+
|
347
|
+
# Gets a list of merge request diffs
|
348
|
+
#
|
349
|
+
# @example
|
350
|
+
# Gitlab.merge_request_diffs(5, 1)
|
351
|
+
# Gitlab.merge_request_diffs('gitlab', 1)
|
352
|
+
# @param [Integer, String] project The ID or name of a project.
|
353
|
+
# @param [Integer] id The ID of a merge request.
|
354
|
+
# @return [Gitlab::ObjectifiedHash] A list of the merge request diffs.
|
355
|
+
def merge_request_diffs(project, merge_request_id)
|
356
|
+
get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/diffs")
|
357
|
+
end
|
358
|
+
|
335
359
|
# Gets a list of merge request diff versions
|
336
360
|
#
|
337
361
|
# @example
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Gitlab::Client
|
4
|
+
# Defines methods related to merge trains.
|
5
|
+
# @see https://docs.gitlab.com/ee/api/merge_trains.html
|
6
|
+
module MergeTrains
|
7
|
+
# Get list of merge trains for a project.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# Gitlab.merge_trains(1, scope: :active, sort: :asc)
|
11
|
+
#
|
12
|
+
# @param [Integer, String] project The ID or name of a project.
|
13
|
+
# @param [Hash] options A customizable set of options.
|
14
|
+
# @option options [String] :scope The scope of merge trains to return, one of: :active, :complete
|
15
|
+
# @option options [String] :sort Sort by created_at either 'asc' or 'desc'
|
16
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
17
|
+
def merge_trains(project, options = {})
|
18
|
+
get("/projects/#{url_encode project}/merge_trains", query: options)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get all merge requests added to a merge train for the requested target branch.
|
22
|
+
#
|
23
|
+
# @param [Integer, String] project The ID or name of a project.
|
24
|
+
# @param [String] target_branch The target branch of the merge train.
|
25
|
+
# @param [Hash] options A customizable set of options.
|
26
|
+
# @option options [String] :scope The scope of merge trains to return, one of: :active, :complete
|
27
|
+
# @option options [String] :sort Sort by created_at either 'asc' or 'desc'
|
28
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
29
|
+
def merge_train_merge_requests(project, target_branch, options = {})
|
30
|
+
get("/projects/#{url_encode project}/merge_trains/#{target_branch}", query: options)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Get merge train information for the requested merge request.
|
34
|
+
#
|
35
|
+
# @param [Integer, String] project The ID or name of a project.
|
36
|
+
# @param [Integer] merge_request_iid The IID of the merge request.
|
37
|
+
# @return [Gitlab::ObjectifiedHash]
|
38
|
+
def merge_train_status(project, merge_request_iid)
|
39
|
+
get("/projects/#{url_encode project}/merge_trains/merge_requests/#{merge_request_iid}")
|
40
|
+
end
|
41
|
+
|
42
|
+
# Add a merge request to the merge train targeting the merge request’s target branch.
|
43
|
+
#
|
44
|
+
# @param [Integer, String] project The ID or name of a project.
|
45
|
+
# @param [Integer] merge_request_iid The IID of the merge request.
|
46
|
+
# @param [Hash] options A customizable set of options.
|
47
|
+
# @option options [Boolean] :when_pipeline_succeeds Add merge request to merge train when pipeline succeeds.
|
48
|
+
# @option options [String] :sha If present, the SHA must match the HEAD of the source branch, otherwise the merge fails.
|
49
|
+
# @option options [Boolean] :squash If true, the commits are squashed into a single commit on merge.
|
50
|
+
# @return [Array<Gitlab::ObjectifiedHash>] <description>
|
51
|
+
def add_merge_request_to_merge_train(project, merge_request_iid, options = {})
|
52
|
+
post("/projects/#{url_encode project}/merge_trains/merge_requests/#{merge_request_iid}", query: options)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Gitlab::Client
|
4
|
+
# Defines methods related to GitLab Packages.
|
5
|
+
# @see https://docs.gitlab.com/ee/api/packages.html
|
6
|
+
module Packages
|
7
|
+
# Gets a list of project packages.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# Gitlab.project_packages(5)
|
11
|
+
# Gitlab.project_packages(5, { package_type: 'npm', sort: 'desc' })
|
12
|
+
#
|
13
|
+
# @param [Integer, String] :project the ID or name of a project.
|
14
|
+
# @param [Hash] options A customizable set of options.
|
15
|
+
# @options options [String] :order_by The field to use as order. One of created_at (default), name, version, or type.
|
16
|
+
# @options options [String] :sort The direction of the order, either asc (default) for ascending order or desc for descending order.
|
17
|
+
# @options options [String] :package_type Filter the returned packages by type. One of conan, maven, npm, pypi, composer, nuget, helm, terraform_module, or golang.
|
18
|
+
# @options options [String] :package_name Filter the project packages with a fuzzy search by name.
|
19
|
+
# @options options [String] :include_versionless When set to true, versionless packages are included in the response.
|
20
|
+
# @options options [String] :status Filter the returned packages by status. One of default (default), hidden, processing, error, or pending_destruction.
|
21
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
22
|
+
def project_packages(project, options = {})
|
23
|
+
get("/projects/#{url_encode project}/packages", query: options)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Gets a list of project packages.
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# Gitlab.group_packages(5)
|
30
|
+
# Gitlab.group_packages(5, { package_type: 'npm', sort: 'desc' })
|
31
|
+
#
|
32
|
+
# @param [Integer, String] project the ID or name of a project.
|
33
|
+
# @param [Hash] options A customizable set of options.
|
34
|
+
# @options options [String] :exclude_subgroups If the parameter is included as true, packages from projects from subgroups are not listed. Default is false.
|
35
|
+
# @options options [String] :order_by The field to use as order. One of created_at (default), name, version, or type.
|
36
|
+
# @options options [String] :sort The direction of the order, either asc (default) for ascending order or desc for descending order.
|
37
|
+
# @options options [String] :package_type Filter the returned packages by type. One of conan, maven, npm, pypi, composer, nuget, helm, terraform_module, or golang.
|
38
|
+
# @options options [String] :package_name Filter the project packages with a fuzzy search by name.
|
39
|
+
# @options options [String] :include_versionless When set to true, versionless packages are included in the response.
|
40
|
+
# @options options [String] :status Filter the returned packages by status. One of default (default), hidden, processing, error, or pending_destruction.
|
41
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
42
|
+
def group_packages(group, options = {})
|
43
|
+
get("/groups/#{url_encode group}/packages", query: options)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Get a single project package.
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
# Gitlab.project_package(5, 3)
|
50
|
+
#
|
51
|
+
# @param [Integer, String] project The ID or name of a project.
|
52
|
+
# @param [Integer] id ID of a package.
|
53
|
+
# @return [Gitlab::ObjectifiedHash]
|
54
|
+
def project_package(project, id)
|
55
|
+
get("/projects/#{url_encode project}/packages/#{id}")
|
56
|
+
end
|
57
|
+
|
58
|
+
# Get a list of package files of a single package.
|
59
|
+
#
|
60
|
+
# @example
|
61
|
+
# Gitlab.project_package_files(5, 3)
|
62
|
+
#
|
63
|
+
# @param [Integer, String] project The ID or name of a project.
|
64
|
+
# @param [Integer] id ID of a package.
|
65
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
66
|
+
def project_package_files(project, id)
|
67
|
+
get("/projects/#{url_encode project}/packages/#{id}/package_files")
|
68
|
+
end
|
69
|
+
|
70
|
+
# Deletes a project package.
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# Gitlab.delete_project_package(5, 3)
|
74
|
+
#
|
75
|
+
# @param [Integer, String] project The ID or name of a project.
|
76
|
+
# @param [Integer] id ID of a package.
|
77
|
+
# @return [void] This API call returns an empty response body.
|
78
|
+
def delete_project_package(project, id)
|
79
|
+
delete("/projects/#{url_encode project}/packages/#{id}")
|
80
|
+
end
|
81
|
+
|
82
|
+
# Delete a package file.
|
83
|
+
#
|
84
|
+
# @example
|
85
|
+
# Gitlab.delete_project_file(5, 3, 1)
|
86
|
+
#
|
87
|
+
# @param [Integer, String] project The ID or name of a project.
|
88
|
+
# @param [Integer] package_id ID of a package.
|
89
|
+
# @param [Integer] file_id ID of a package file.
|
90
|
+
# @return [void] This API call returns an empty response body.
|
91
|
+
def delete_project_package_file(project, package_id, file_id)
|
92
|
+
delete("/projects/#{url_encode project}/packages/#{package_id}/package_files/#{file_id}")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -43,6 +43,18 @@ class Gitlab::Client
|
|
43
43
|
get("/projects/#{url_encode project}/pipelines/#{id}/test_report")
|
44
44
|
end
|
45
45
|
|
46
|
+
# Gets a single pipeline's variables.
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
# Gitlab.pipeline_variables(5, 36)
|
50
|
+
#
|
51
|
+
# @param [Integer, String] project The ID or name of a project.
|
52
|
+
# @param [Integer] id The ID of a pipeline.
|
53
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
54
|
+
def pipeline_variables(project, id)
|
55
|
+
get("/projects/#{url_encode project}/pipelines/#{id}/variables")
|
56
|
+
end
|
57
|
+
|
46
58
|
# Create a pipeline.
|
47
59
|
#
|
48
60
|
# @example
|
@@ -101,5 +113,18 @@ class Gitlab::Client
|
|
101
113
|
def delete_pipeline(project, id)
|
102
114
|
delete("/projects/#{url_encode project}/pipelines/#{id}")
|
103
115
|
end
|
116
|
+
|
117
|
+
# Update a pipeline metadata
|
118
|
+
#
|
119
|
+
# @example
|
120
|
+
# Gitlab.update_pipeline_metadata(5, 1, name: 'new name')
|
121
|
+
#
|
122
|
+
# @param [Integer, String] project The ID or name of a project.
|
123
|
+
# @param [Integer] id The ID of a pipeline.
|
124
|
+
# @option options [String] :name The new name of the pipeline.
|
125
|
+
# @return [Gitlab::ObjectifiedHash]
|
126
|
+
def update_pipeline_metadata(project, id, options = {})
|
127
|
+
put("/projects/#{url_encode project}/pipelines/#{id}/metadata", body: options)
|
128
|
+
end
|
104
129
|
end
|
105
130
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Gitlab::Client
|
4
|
+
# Defines methods related to project exports.
|
5
|
+
# @see https://docs.gitlab.com/ce/api/project_import_export.html
|
6
|
+
module ProjectExports
|
7
|
+
# Start a new export
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# Gitlab.export_project(2)
|
11
|
+
#
|
12
|
+
# @param [Integer, String] id The ID or path of a project.
|
13
|
+
# @param [Hash] options A customizable set of options.
|
14
|
+
# @option options [String] description(optional) Overrides the project description
|
15
|
+
# @option options [hash] upload(optional) Hash that contains the information to upload the exported project to a web server
|
16
|
+
# @option options [String] upload[url] TThe URL to upload the project
|
17
|
+
# @option options [String] upload[http_method](optional) The HTTP method to upload the exported project. Only PUT and POST methods allowed. Default is PUT
|
18
|
+
# @return [Gitlab::ObjectifiedHash]
|
19
|
+
def export_project(id, options = {})
|
20
|
+
post("/projects/#{url_encode id}/export", body: options)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get the status of export
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# Gitlab.export_project_status(2)
|
27
|
+
#
|
28
|
+
# @param [Integer, String] id The ID or path of a project.
|
29
|
+
# @return [Gitlab::ObjectifiedHash]
|
30
|
+
def export_project_status(id)
|
31
|
+
get("/projects/#{url_encode id}/export")
|
32
|
+
end
|
33
|
+
|
34
|
+
# Download the finished export
|
35
|
+
#
|
36
|
+
# @example
|
37
|
+
# Gitlab.exported_project_download(2)
|
38
|
+
#
|
39
|
+
# @param [Integer, String] id The ID or path of a project.
|
40
|
+
# @return [Gitlab::FileResponse]
|
41
|
+
def exported_project_download(id)
|
42
|
+
get("/projects/#{url_encode id}/export/download",
|
43
|
+
format: nil,
|
44
|
+
headers: { Accept: 'application/octet-stream' },
|
45
|
+
parser: proc { |body, _|
|
46
|
+
if body.encoding == Encoding::ASCII_8BIT # binary response
|
47
|
+
::Gitlab::FileResponse.new StringIO.new(body, 'rb+')
|
48
|
+
else # error with json response
|
49
|
+
::Gitlab::Request.parse(body)
|
50
|
+
end
|
51
|
+
})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -75,5 +75,16 @@ class Gitlab::Client
|
|
75
75
|
def delete_project_release(project, tag_name)
|
76
76
|
delete("/projects/#{url_encode project}/releases/#{tag_name}")
|
77
77
|
end
|
78
|
+
|
79
|
+
# Gets Latest Release
|
80
|
+
#
|
81
|
+
# @example
|
82
|
+
# Gitlab.project_latest_release(5)
|
83
|
+
#
|
84
|
+
# @param [Integer, String] project The ID or name of a project
|
85
|
+
# @return [Gitlab::ObjectifiedHash] Information about the release
|
86
|
+
def project_latest_release(project)
|
87
|
+
get("/projects/#{url_encode project}/releases/permalink/latest")
|
88
|
+
end
|
78
89
|
end
|
79
90
|
end
|
@@ -109,5 +109,22 @@ class Gitlab::Client
|
|
109
109
|
def generate_changelog(project, version, options = {})
|
110
110
|
post("/projects/#{url_encode project}/repository/changelog", body: options.merge(version: version))
|
111
111
|
end
|
112
|
+
|
113
|
+
# Get changelog data
|
114
|
+
#
|
115
|
+
# @example
|
116
|
+
# Gitlab.get_changelog(42, 'v1.0.0')
|
117
|
+
#
|
118
|
+
# @param [Integer, String] project The ID or name of a project
|
119
|
+
# @param [String] version The version to generate the changelog for
|
120
|
+
# @param [Hash] options A customizable set of options
|
121
|
+
# @option options [String] :from The start of the range of commits (SHA)
|
122
|
+
# @option options [String] :to The end of the range of commits (as a SHA) to use for the changelog
|
123
|
+
# @option options [String] :date The date and time of the release, defaults to the current time
|
124
|
+
# @option options [String] :trailer The Git trailer to use for including commits
|
125
|
+
# @return [Gitlab::ObjectifiedHash]
|
126
|
+
def get_changelog(project, version, options = {})
|
127
|
+
get("/projects/#{url_encode project}/repository/changelog", body: options.merge(version: version))
|
128
|
+
end
|
112
129
|
end
|
113
130
|
end
|
@@ -207,5 +207,72 @@ class Gitlab::Client
|
|
207
207
|
body = { token: token }
|
208
208
|
post('/runners/verify', body: body)
|
209
209
|
end
|
210
|
+
|
211
|
+
# Creates a new group runner with the new Gitlab approach (v16.0+) and returns the id/token information
|
212
|
+
# https://docs.gitlab.com/ee/api/users.html#create-a-runner
|
213
|
+
# You must use an access token with the create_runner scope
|
214
|
+
#
|
215
|
+
# @example
|
216
|
+
# Gitlab.create_group_runner(9, tag_list: ['one', 'two'])
|
217
|
+
# Gitlab.create_group_runner(9, paused: false, description: 'A note', run_untagged: true)
|
218
|
+
#
|
219
|
+
# @param [String] group(required) Group ID.
|
220
|
+
# @param [Hash] options A customizable set of options.
|
221
|
+
# @return <Gitlab::ObjectifiedHash> Response against runner registration
|
222
|
+
def create_group_runner(group, options = {})
|
223
|
+
create_runner({ runner_type: 'group_type', group_id: group }.merge(options))
|
224
|
+
end
|
225
|
+
|
226
|
+
# Creates a new project runner with the new Gitlab approach (v16.0+) and returns the id/token information
|
227
|
+
# https://docs.gitlab.com/ee/api/users.html#create-a-runner
|
228
|
+
# You must use an access token with the create_runner scope
|
229
|
+
#
|
230
|
+
# @example
|
231
|
+
# Gitlab.create_project_runner(12, tag_list: ['one', 'two'])
|
232
|
+
# Gitlab.create_project_runner(12, paused: false, description: 'A note', run_untagged: true)
|
233
|
+
#
|
234
|
+
# @param [String] project(required) Project ID.
|
235
|
+
# @param [Hash] options A customizable set of options.
|
236
|
+
# @return <Gitlab::ObjectifiedHash> Response against runner registration
|
237
|
+
def create_project_runner(project, options = {})
|
238
|
+
create_runner({ runner_type: 'project_type', project_id: project }.merge(options))
|
239
|
+
end
|
240
|
+
|
241
|
+
# Creates a new instance runner with the new Gitlab approach (v16.0+) and returns the id/token information
|
242
|
+
# You must be an administrator of the GitLab instance
|
243
|
+
# You must use an access token with the create_runner scope
|
244
|
+
# https://docs.gitlab.com/ee/api/users.html#create-a-runner
|
245
|
+
#
|
246
|
+
# @example
|
247
|
+
# Gitlab.create_instance_runner(tag_list: ['one', 'two'])
|
248
|
+
# Gitlab.create_instance_runner(paused: false, description: 'A note', run_untagged: true)
|
249
|
+
#
|
250
|
+
# @param [String] group(required) Project ID.
|
251
|
+
# @param [Hash] options A customizable set of options.
|
252
|
+
# @return <Gitlab::ObjectifiedHash> Response against runner registration
|
253
|
+
def create_instance_runner(options = {})
|
254
|
+
create_runner({ runner_type: 'instance_type' }.merge(options))
|
255
|
+
end
|
256
|
+
|
257
|
+
private
|
258
|
+
|
259
|
+
# Creates a runner linked to the current user.
|
260
|
+
# You must use an access token with the create_runner scope
|
261
|
+
# https://docs.gitlab.com/ee/api/users.html#create-a-runner
|
262
|
+
#
|
263
|
+
# @param [Hash] options(required) A customizable set of options.
|
264
|
+
# @option options [String] :description(optional) Runner description.
|
265
|
+
# @option options [Hash] :info(optional) Runner metadata.
|
266
|
+
# @option options [Boolean] :paused(optional) Whether the Runner ignores new jobs.
|
267
|
+
# @option options [Boolean] :locked(optional) Whether the Runner should be locked for current project.
|
268
|
+
# @option options [Boolean] :run_untagged(optional) Whether the Runner should handle untagged jobs.
|
269
|
+
# @option options [Array<String>] :tag_list(optional) List of Runner tags.
|
270
|
+
# @option options [String] :access_level(optional) Access level of the runner; not_protected or ref_protected.
|
271
|
+
# @option options [Integer] :maximum_timeout(optional) Maximum timeout set when this Runner will handle the job.
|
272
|
+
# @option options [String] :maintenance_note(optional) Free-form maintenance notes for the runner (1024 characters).
|
273
|
+
# @return <Gitlab::ObjectifiedHash> Response against runner registration {"id": 1, "token": foo "token_expires_at": null}
|
274
|
+
def create_runner(options)
|
275
|
+
post('/user/runners', body: options)
|
276
|
+
end
|
210
277
|
end
|
211
278
|
end
|
data/lib/gitlab/client/users.rb
CHANGED
@@ -58,6 +58,22 @@ class Gitlab::Client
|
|
58
58
|
post('/users', body: body)
|
59
59
|
end
|
60
60
|
|
61
|
+
# Creates a service account.
|
62
|
+
# Requires authentication from an admin account.
|
63
|
+
#
|
64
|
+
# @example
|
65
|
+
# Gitlab.create_service_account('service_account_6018816a18e515214e0c34c2b33523fc', 'Service account user')
|
66
|
+
#
|
67
|
+
# @param [String] name (required) The email of the service account.
|
68
|
+
# @param [String] username (required) The username of the service account.
|
69
|
+
# @return [Gitlab::ObjectifiedHash] Information about created service account.
|
70
|
+
def create_service_account(*args)
|
71
|
+
raise ArgumentError, 'Missing required parameters' unless args[1]
|
72
|
+
|
73
|
+
body = { name: args[0], username: args[1] }
|
74
|
+
post('/service_accounts', body: body)
|
75
|
+
end
|
76
|
+
|
61
77
|
# Updates a user.
|
62
78
|
#
|
63
79
|
# @example
|
@@ -110,6 +126,39 @@ class Gitlab::Client
|
|
110
126
|
post("/users/#{user_id}/unblock")
|
111
127
|
end
|
112
128
|
|
129
|
+
# Deactivates the specified user. Available only for admin.
|
130
|
+
#
|
131
|
+
# @example
|
132
|
+
# Gitlab.deactivate_user(15)
|
133
|
+
#
|
134
|
+
# @param [Integer] user_id The Id of user
|
135
|
+
# @return [Boolean] success or not
|
136
|
+
def deactivate_user(user_id)
|
137
|
+
post("/users/#{user_id}/deactivate")
|
138
|
+
end
|
139
|
+
|
140
|
+
# Activate the specified user. Available only for admin.
|
141
|
+
#
|
142
|
+
# @example
|
143
|
+
# Gitlab.activate_user(15)
|
144
|
+
#
|
145
|
+
# @param [Integer] user_id The Id of user
|
146
|
+
# @return [Boolean] success or not
|
147
|
+
def activate_user(user_id)
|
148
|
+
post("/users/#{user_id}/activate")
|
149
|
+
end
|
150
|
+
|
151
|
+
# Approves the specified user. Available only for admin.
|
152
|
+
#
|
153
|
+
# @example
|
154
|
+
# Gitlab.approve_user(15)
|
155
|
+
#
|
156
|
+
# @param [Integer] user_id The Id of user
|
157
|
+
# @return [Boolean] success or not
|
158
|
+
def approve_user(user_id)
|
159
|
+
post("/users/#{user_id}/approve")
|
160
|
+
end
|
161
|
+
|
113
162
|
# Creates a new user session.
|
114
163
|
#
|
115
164
|
# @example
|
@@ -265,7 +314,7 @@ class Gitlab::Client
|
|
265
314
|
delete(url)
|
266
315
|
end
|
267
316
|
|
268
|
-
# Search for
|
317
|
+
# Search for users by name
|
269
318
|
#
|
270
319
|
# @example
|
271
320
|
# Gitlab.user_search('gitlab')
|
@@ -280,6 +329,19 @@ class Gitlab::Client
|
|
280
329
|
get('/users', query: options)
|
281
330
|
end
|
282
331
|
|
332
|
+
# Get user by username
|
333
|
+
#
|
334
|
+
# @example
|
335
|
+
# Gitlab.user_by_username('gitlab')
|
336
|
+
#
|
337
|
+
# @param [String] username A username to get.
|
338
|
+
# @param [Hash] options A customizable set of options.
|
339
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
340
|
+
def user_by_username(username, options = {})
|
341
|
+
options[:username] = username
|
342
|
+
get('/users', query: options)
|
343
|
+
end
|
344
|
+
|
283
345
|
# Gets user custom_attributes.
|
284
346
|
#
|
285
347
|
# @example
|
@@ -371,6 +433,47 @@ class Gitlab::Client
|
|
371
433
|
post("/users/#{user_id}/impersonation_tokens", body: body)
|
372
434
|
end
|
373
435
|
|
436
|
+
# Get all personal access tokens for a user
|
437
|
+
#
|
438
|
+
# @example
|
439
|
+
# Gitlab.user_personal_access_tokens(1)
|
440
|
+
#
|
441
|
+
# @param [Integer] user_id The ID of the user.
|
442
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
443
|
+
def user_personal_access_tokens(user_id)
|
444
|
+
get("/personal_access_tokens?user_id=#{user_id}")
|
445
|
+
end
|
446
|
+
|
447
|
+
# Create personal access token
|
448
|
+
#
|
449
|
+
# @example
|
450
|
+
# Gitlab.create_personal_access_token(2, "token", ["api", "read_user"])
|
451
|
+
# Gitlab.create_personal_access_token(2, "token", ["api", "read_user"], "1970-01-01")
|
452
|
+
#
|
453
|
+
# @param [Integer] user_id The ID of the user.
|
454
|
+
# @param [String] name Name of the personal access token.
|
455
|
+
# @param [Array<String>] scopes Array of scopes for the impersonation token
|
456
|
+
# @param [String] expires_at Date for impersonation token expiration in ISO format.
|
457
|
+
# @return [Gitlab::ObjectifiedHash]
|
458
|
+
def create_personal_access_token(user_id, name, scopes, expires_at = nil)
|
459
|
+
body = { name: name, scopes: scopes }
|
460
|
+
body[:expires_at] = expires_at if expires_at
|
461
|
+
post("/users/#{user_id}/personal_access_tokens", body: body)
|
462
|
+
end
|
463
|
+
|
464
|
+
# Rotate a personal access token
|
465
|
+
#
|
466
|
+
# @example
|
467
|
+
# Gitlab.rotate_personal_access_token(1)
|
468
|
+
#
|
469
|
+
# @param [Integer] personal_access_token_id ID of the personal access token.
|
470
|
+
# @return [Gitlab::ObjectifiedHash]
|
471
|
+
def rotate_personal_access_token(personal_access_token_id, expires_at = nil)
|
472
|
+
body = {}
|
473
|
+
body[:expires_at] = expires_at if expires_at
|
474
|
+
post("/personal_access_tokens/#{personal_access_token_id}/rotate", body: body)
|
475
|
+
end
|
476
|
+
|
374
477
|
# Revoke an impersonation token
|
375
478
|
#
|
376
479
|
# @example
|
@@ -382,5 +485,37 @@ class Gitlab::Client
|
|
382
485
|
def revoke_user_impersonation_token(user_id, impersonation_token_id)
|
383
486
|
delete("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}")
|
384
487
|
end
|
488
|
+
|
489
|
+
# Lists all projects and groups a user is a member of
|
490
|
+
#
|
491
|
+
# @example
|
492
|
+
# Gitlab.memberships(2)
|
493
|
+
#
|
494
|
+
# @param [Integer] user_id The ID of the user.
|
495
|
+
def memberships(user_id)
|
496
|
+
get("/users/#{user_id}/memberships")
|
497
|
+
end
|
498
|
+
|
499
|
+
# Revoke a personal access token
|
500
|
+
#
|
501
|
+
# @example
|
502
|
+
# Gitlab.revoke_personal_access_token(1)
|
503
|
+
#
|
504
|
+
# @param [Integer] personal_access_token_id ID of the personal access token.
|
505
|
+
# @return [Gitlab::ObjectifiedHash]
|
506
|
+
def revoke_personal_access_token(personal_access_token_id)
|
507
|
+
delete("/personal_access_tokens/#{personal_access_token_id}")
|
508
|
+
end
|
509
|
+
|
510
|
+
# Disables two factor authentication (2FA) for the specified user.
|
511
|
+
#
|
512
|
+
# @example
|
513
|
+
# Gitlab.disable_two_factor(1)
|
514
|
+
#
|
515
|
+
# @param [Integer] id The ID of a user.
|
516
|
+
# @return [Gitlab::ObjectifiedHash]
|
517
|
+
def disable_two_factor(user_id)
|
518
|
+
patch("/users/#{user_id}/disable_two_factor")
|
519
|
+
end
|
385
520
|
end
|
386
521
|
end
|
data/lib/gitlab/client.rb
CHANGED
@@ -37,9 +37,11 @@ module Gitlab
|
|
37
37
|
include Markdown
|
38
38
|
include MergeRequestApprovals
|
39
39
|
include MergeRequests
|
40
|
+
include MergeTrains
|
40
41
|
include Milestones
|
41
42
|
include Namespaces
|
42
43
|
include Notes
|
44
|
+
include Packages
|
43
45
|
include PipelineSchedules
|
44
46
|
include PipelineTriggers
|
45
47
|
include Pipelines
|
@@ -89,7 +91,7 @@ module Gitlab
|
|
89
91
|
private
|
90
92
|
|
91
93
|
def only_show_last_four_chars(token)
|
92
|
-
"#{'*' * (token.size - 4)}#{token[-4
|
94
|
+
"#{'*' * (token.size - 4)}#{token[-4..]}"
|
93
95
|
end
|
94
96
|
end
|
95
97
|
end
|
data/lib/gitlab/error.rb
CHANGED
@@ -135,6 +135,9 @@ module Gitlab
|
|
135
135
|
# Raised when API endpoint returns the HTTP status code 503.
|
136
136
|
class ServiceUnavailable < ResponseError; end
|
137
137
|
|
138
|
+
# Raised when API endpoint returns the HTTP status code 522.
|
139
|
+
class ConnectionTimedOut < ResponseError; end
|
140
|
+
|
138
141
|
# HTTP status codes mapped to error classes.
|
139
142
|
STATUS_MAPPINGS = {
|
140
143
|
400 => BadRequest,
|
@@ -148,7 +151,20 @@ module Gitlab
|
|
148
151
|
429 => TooManyRequests,
|
149
152
|
500 => InternalServerError,
|
150
153
|
502 => BadGateway,
|
151
|
-
503 => ServiceUnavailable
|
154
|
+
503 => ServiceUnavailable,
|
155
|
+
522 => ConnectionTimedOut
|
152
156
|
}.freeze
|
157
|
+
|
158
|
+
# Returns error class that should be raised for this response. Returns nil
|
159
|
+
# if the response status code is not 4xx or 5xx.
|
160
|
+
#
|
161
|
+
# @param [HTTParty::Response] response The response object.
|
162
|
+
# @return [Class<Error::ResponseError>, nil]
|
163
|
+
def self.klass(response)
|
164
|
+
error_klass = STATUS_MAPPINGS[response.code]
|
165
|
+
return error_klass if error_klass
|
166
|
+
|
167
|
+
ResponseError if response.server_error? || response.client_error?
|
168
|
+
end
|
153
169
|
end
|
154
170
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gitlab
|
4
|
+
module Headers
|
5
|
+
# Parses link header.
|
6
|
+
#
|
7
|
+
# @private
|
8
|
+
class PageLinks
|
9
|
+
HEADER_LINK = 'Link'
|
10
|
+
DELIM_LINKS = ','
|
11
|
+
LINK_REGEX = /<([^>]+)>; rel="([^"]+)"/.freeze
|
12
|
+
METAS = %w[last next first prev].freeze
|
13
|
+
|
14
|
+
attr_accessor(*METAS)
|
15
|
+
|
16
|
+
def initialize(headers)
|
17
|
+
link_header = headers[HEADER_LINK]
|
18
|
+
|
19
|
+
extract_links(link_header) if link_header && link_header =~ /(next|first|last|prev)/
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def extract_links(header)
|
25
|
+
header.split(DELIM_LINKS).each do |link|
|
26
|
+
LINK_REGEX.match(link.strip) do |match|
|
27
|
+
url = match[1]
|
28
|
+
meta = match[2]
|
29
|
+
next if !url || !meta || METAS.index(meta).nil?
|
30
|
+
|
31
|
+
send("#{meta}=", url)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gitlab
|
4
|
+
module Headers
|
5
|
+
# Parses total header.
|
6
|
+
#
|
7
|
+
# @private
|
8
|
+
class Total
|
9
|
+
HEADER_TOTAL = 'x-total'
|
10
|
+
TOTAL_REGEX = /^\d+$/.freeze
|
11
|
+
|
12
|
+
attr_accessor :total
|
13
|
+
|
14
|
+
def initialize(headers)
|
15
|
+
header_total = headers[HEADER_TOTAL]
|
16
|
+
|
17
|
+
extract_total(header_total) if header_total
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def extract_total(header_total)
|
23
|
+
TOTAL_REGEX.match(header_total.strip) do |match|
|
24
|
+
@total = match[0]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -30,7 +30,8 @@ module Gitlab
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def parse_headers!(headers)
|
33
|
-
@links = PageLinks.new headers
|
33
|
+
@links = Headers::PageLinks.new headers
|
34
|
+
@total = Headers::Total.new headers
|
34
35
|
end
|
35
36
|
|
36
37
|
def each_page
|
@@ -58,6 +59,10 @@ module Gitlab
|
|
58
59
|
lazy_paginate.take(limit).each(&block)
|
59
60
|
end
|
60
61
|
|
62
|
+
def total
|
63
|
+
@total.total
|
64
|
+
end
|
65
|
+
|
61
66
|
def last_page?
|
62
67
|
!(@links.nil? || @links.last.nil?)
|
63
68
|
end
|
data/lib/gitlab/request.rb
CHANGED
@@ -38,7 +38,7 @@ module Gitlab
|
|
38
38
|
raise Error::Parsing, 'The response is not a valid JSON'
|
39
39
|
end
|
40
40
|
|
41
|
-
%w[get post put delete].each do |method|
|
41
|
+
%w[get post put patch delete].each do |method|
|
42
42
|
define_method method do |path, options = {}|
|
43
43
|
params = options.dup
|
44
44
|
|
@@ -67,7 +67,7 @@ module Gitlab
|
|
67
67
|
# Checks the response code for common errors.
|
68
68
|
# Returns parsed response for successful requests.
|
69
69
|
def validate(response)
|
70
|
-
error_klass = Error
|
70
|
+
error_klass = Error.klass(response)
|
71
71
|
raise error_klass, response if error_klass
|
72
72
|
|
73
73
|
parsed = response.parsed_response
|
data/lib/gitlab/version.rb
CHANGED
data/lib/gitlab.rb
CHANGED
@@ -4,7 +4,8 @@ require 'gitlab/version'
|
|
4
4
|
require 'gitlab/objectified_hash'
|
5
5
|
require 'gitlab/configuration'
|
6
6
|
require 'gitlab/error'
|
7
|
-
require 'gitlab/page_links'
|
7
|
+
require 'gitlab/headers/page_links'
|
8
|
+
require 'gitlab/headers/total'
|
8
9
|
require 'gitlab/paginated_response'
|
9
10
|
require 'gitlab/file_response'
|
10
11
|
require 'gitlab/request'
|
@@ -49,8 +50,10 @@ module Gitlab
|
|
49
50
|
#
|
50
51
|
# @return [Array<Symbol>]
|
51
52
|
def self.actions
|
53
|
+
# rubocop:disable Layout/LineLength
|
52
54
|
hidden =
|
53
|
-
/endpoint|private_token|auth_token|user_agent|sudo|get|post|put|\Adelete\z|validate\z|request_defaults|httparty/
|
55
|
+
/endpoint|private_token|auth_token|user_agent|sudo|get|post|put|patch|\Adelete\z|validate\z|request_defaults|httparty/
|
56
|
+
# rubocop:enable Layout/LineLength
|
54
57
|
(Gitlab::Client.instance_methods - Object.methods).reject { |e| e[hidden] }
|
55
58
|
end
|
56
59
|
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.
|
4
|
+
version: 4.20.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:
|
12
|
+
date: 2024-06-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '0.
|
20
|
+
version: '0.20'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '0.
|
27
|
+
version: '0.20'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: terminal-table
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,14 +130,17 @@ files:
|
|
130
130
|
- lib/gitlab/client/markdown.rb
|
131
131
|
- lib/gitlab/client/merge_request_approvals.rb
|
132
132
|
- lib/gitlab/client/merge_requests.rb
|
133
|
+
- lib/gitlab/client/merge_trains.rb
|
133
134
|
- lib/gitlab/client/milestones.rb
|
134
135
|
- lib/gitlab/client/namespaces.rb
|
135
136
|
- lib/gitlab/client/notes.rb
|
137
|
+
- lib/gitlab/client/packages.rb
|
136
138
|
- lib/gitlab/client/pipeline_schedules.rb
|
137
139
|
- lib/gitlab/client/pipeline_triggers.rb
|
138
140
|
- lib/gitlab/client/pipelines.rb
|
139
141
|
- lib/gitlab/client/project_badges.rb
|
140
142
|
- lib/gitlab/client/project_clusters.rb
|
143
|
+
- lib/gitlab/client/project_exports.rb
|
141
144
|
- lib/gitlab/client/project_release_links.rb
|
142
145
|
- lib/gitlab/client/project_releases.rb
|
143
146
|
- lib/gitlab/client/projects.rb
|
@@ -164,9 +167,10 @@ files:
|
|
164
167
|
- lib/gitlab/configuration.rb
|
165
168
|
- lib/gitlab/error.rb
|
166
169
|
- lib/gitlab/file_response.rb
|
170
|
+
- lib/gitlab/headers/page_links.rb
|
171
|
+
- lib/gitlab/headers/total.rb
|
167
172
|
- lib/gitlab/help.rb
|
168
173
|
- lib/gitlab/objectified_hash.rb
|
169
|
-
- lib/gitlab/page_links.rb
|
170
174
|
- lib/gitlab/paginated_response.rb
|
171
175
|
- lib/gitlab/request.rb
|
172
176
|
- lib/gitlab/shell.rb
|
@@ -175,7 +179,12 @@ files:
|
|
175
179
|
homepage: https://github.com/NARKOZ/gitlab
|
176
180
|
licenses:
|
177
181
|
- BSD-2-Clause
|
178
|
-
metadata:
|
182
|
+
metadata:
|
183
|
+
homepage_uri: https://github.com/NARKOZ/gitlab
|
184
|
+
source_code_uri: https://github.com/NARKOZ/gitlab
|
185
|
+
bug_tracker_uri: https://github.com/NARKOZ/gitlab/issues
|
186
|
+
changelog_uri: https://github.com/NARKOZ/gitlab/releases
|
187
|
+
funding_uri: https://github.com/NARKOZ/SponsorMe
|
179
188
|
post_install_message:
|
180
189
|
rdoc_options: []
|
181
190
|
require_paths:
|
@@ -184,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
184
193
|
requirements:
|
185
194
|
- - ">="
|
186
195
|
- !ruby/object:Gem::Version
|
187
|
-
version: '2.
|
196
|
+
version: '2.6'
|
188
197
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
198
|
requirements:
|
190
199
|
- - ">="
|
data/lib/gitlab/page_links.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Gitlab
|
4
|
-
# Parses link header.
|
5
|
-
#
|
6
|
-
# @private
|
7
|
-
class PageLinks
|
8
|
-
HEADER_LINK = 'Link'
|
9
|
-
DELIM_LINKS = ','
|
10
|
-
LINK_REGEX = /<([^>]+)>; rel="([^"]+)"/.freeze
|
11
|
-
METAS = %w[last next first prev].freeze
|
12
|
-
|
13
|
-
attr_accessor(*METAS)
|
14
|
-
|
15
|
-
def initialize(headers)
|
16
|
-
link_header = headers[HEADER_LINK]
|
17
|
-
|
18
|
-
extract_links(link_header) if link_header && link_header =~ /(next|first|last|prev)/
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def extract_links(header)
|
24
|
-
header.split(DELIM_LINKS).each do |link|
|
25
|
-
LINK_REGEX.match(link.strip) do |match|
|
26
|
-
url = match[1]
|
27
|
-
meta = match[2]
|
28
|
-
next if !url || !meta || METAS.index(meta).nil?
|
29
|
-
|
30
|
-
send("#{meta}=", url)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|