gitlab 4.12.0 → 4.13.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: 3b704b0067388d9f794505c41aff708ee8b6e3fc1a9d810a046bb9bfd9ef912c
4
- data.tar.gz: a550009e3cb5478f42088268c93b7e800339dcccf071b8d81c223ad4261fdcc5
3
+ metadata.gz: eea71e433b574497741d1e8f523d6a2a61c4fb423d821b7d3424a4cde6adadc3
4
+ data.tar.gz: ec2829e6dc0a9efa88568389bb11dba0290b4e7bec476d790203afa915e633f9
5
5
  SHA512:
6
- metadata.gz: 18d6a12ea3927fb06da8b86777288a48706b4fc5e1385293f0988485636caa41831bce320ed69fea92660f0dc6de2d70feafb22e5a57a7b10f08cf22e0d905ef
7
- data.tar.gz: ab8da4935f0f68c37e8529af7070f9e478e33cab037714b60035796070f143cdf154214be1516713475b044c81986d0e967ab6fae3497f2086e721d5f64e06da
6
+ metadata.gz: 14a2e907533256d02b6b1524c6cd25ced84dfe16ed8bed1298c85ae024adcf2c939548eedba23cd3a34865e435aaee8ed2de2cc05d6ad5e5aa9899ef01e81abc
7
+ data.tar.gz: 03ece4a5d5801a7e263c450c6164d260b0abd92f8973cf352f729e66740464f64b9836c85d3ad111a8234bb99ff3eea2738cc2f9e213d85dc8eada4f50852174
data/README.md CHANGED
@@ -40,7 +40,7 @@ Configuration example:
40
40
 
41
41
  ```ruby
42
42
  Gitlab.configure do |config|
43
- config.endpoint = 'https://example.net/api/v4' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
43
+ config.endpoint = 'https://example.net/api/v4' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT'] and falls back to ENV['CI_API_V4_URL']
44
44
  config.private_token = 'qEsq1pt6HJPaNciie3MG' # user's private token or OAuth2 access token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
45
45
  # Optional
46
46
  # config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]'
@@ -72,8 +72,14 @@ ENV['GITLAB_API_HTTPARTY_OPTIONS'] = '{read_timeout: 60}'
72
72
  Gitlab.projects(per_page: 5)
73
73
  # => [#<Gitlab::ObjectifiedHash:0x000000023326e0 @data={"id"=>1, "code"=>"brute", "name"=>"Brute", "description"=>nil, "path"=>"brute", "default_branch"=>nil, "owner"=>#<Gitlab::ObjectifiedHash:0x00000002331600 @data={"id"=>1, "email"=>"john@example.com", "name"=>"John Smith", "blocked"=>false, "created_at"=>"2012-09-17T09:41:56Z"}>, "private"=>true, "issues_enabled"=>true, "merge_requests_enabled"=>true, "wall_enabled"=>true, "wiki_enabled"=>true, "created_at"=>"2012-09-17T09:41:56Z"}>, #<Gitlab::ObjectifiedHash:0x000000023450d8 @data={"id"=>2, "code"=>"mozart", "name"=>"Mozart", "description"=>nil, "path"=>"mozart", "default_branch"=>nil, "owner"=>#<Gitlab::ObjectifiedHash:0x00000002344ca0 @data={"id"=>1, "email"=>"john@example.com", "name"=>"John Smith", "blocked"=>false, "created_at"=>"2012-09-17T09:41:56Z"}>, "private"=>true, "issues_enabled"=>true, "merge_requests_enabled"=>true, "wall_enabled"=>true, "wiki_enabled"=>true, "created_at"=>"2012-09-17T09:41:57Z"}>, #<Gitlab::ObjectifiedHash:0x00000002344958 @data={"id"=>3, "code"=>"gitlab", "name"=>"Gitlab", "description"=>nil, "path"=>"gitlab", "default_branch"=>nil, "owner"=>#<Gitlab::ObjectifiedHash:0x000000023447a0 @data={"id"=>1, "email"=>"john@example.com", "name"=>"John Smith", "blocked"=>false, "created_at"=>"2012-09-17T09:41:56Z"}>, "private"=>true, "issues_enabled"=>true, "merge_requests_enabled"=>true, "wall_enabled"=>true, "wiki_enabled"=>true, "created_at"=>"2012-09-17T09:41:58Z"}>]
74
74
 
75
- # initialize a new client
76
- g = Gitlab.client(endpoint: 'https://api.example.com', private_token: 'qEsq1pt6HJPaNciie3MG')
75
+ # initialize a new client with custom headers
76
+ g = Gitlab.client(
77
+ endpoint: 'https://example.com/api/v4',
78
+ private_token: 'qEsq1pt6HJPaNciie3MG',
79
+ httparty: {
80
+ headers: { 'Cookie' => 'gitlab_canary=true' }
81
+ }
82
+ )
77
83
  # => #<Gitlab::Client:0x00000001e62408 @endpoint="https://api.example.com", @private_token="qEsq1pt6HJPaNciie3MG", @user_agent="Gitlab Ruby Gem 2.0.0">
78
84
 
79
85
  # get a user
@@ -19,12 +19,14 @@ module Gitlab
19
19
  include ContainerRegistry
20
20
  include Deployments
21
21
  include Environments
22
+ include Epics
22
23
  include Events
23
24
  include Features
24
25
  include GroupBoards
25
26
  include GroupLabels
26
27
  include GroupMilestones
27
28
  include Groups
29
+ include IssueLinks
28
30
  include Issues
29
31
  include Jobs
30
32
  include Keys
@@ -2,8 +2,8 @@
2
2
 
3
3
  class Gitlab::Client
4
4
  # Defines methods related to builds.
5
- # @see https://docs.gitlab.com/ce/api/build_variables.html
6
- # @see https://docs.gitlab.com/ee/api/group_level_variables.html
5
+ # @see https://docs.gitlab.com/ce/api/project_level_variables.html
6
+ # @see https://docs.gitlab.com/ce/api/group_level_variables.html
7
7
  module BuildVariables
8
8
  # Gets a list of the project's build variables
9
9
  #
@@ -36,9 +36,10 @@ class Gitlab::Client
36
36
  # @param [Integer, String] project The ID or name of a project.
37
37
  # @param [String] key The key of a variable; must have no more than 255 characters; only `A-Z`, `a-z`, `0-9` and `_` are allowed
38
38
  # @param [String] value The value of a variable
39
+ # @param [Hash] opts optional parameters
39
40
  # @return [Gitlab::ObjectifiedHash] The variable.
40
- def create_variable(project, key, value)
41
- post("/projects/#{url_encode project}/variables", body: { key: key, value: value })
41
+ def create_variable(project, key, value, **opts)
42
+ post("/projects/#{url_encode project}/variables", body: opts.merge(key: key, value: value))
42
43
  end
43
44
 
44
45
  # Update a project's build variable.
@@ -49,9 +50,10 @@ class Gitlab::Client
49
50
  # @param [Integer, String] project The ID or name of a project.
50
51
  # @param [String] key The key of a variable
51
52
  # @param [String] value The value of a variable
53
+ # @param [Hash] opts optional parameters
52
54
  # @return [Gitlab::ObjectifiedHash] The variable.
53
- def update_variable(project, key, value)
54
- put("/projects/#{url_encode project}/variables/#{key}", body: { value: value })
55
+ def update_variable(project, key, value, **opts)
56
+ put("/projects/#{url_encode project}/variables/#{key}", body: opts.merge(value: value))
55
57
  end
56
58
 
57
59
  # Remove a project's build variable.
@@ -97,9 +99,10 @@ class Gitlab::Client
97
99
  # @param [Integer, String] group The ID or name of a group.
98
100
  # @param [String] key The key of a variable; must have no more than 255 characters; only `A-Z`, `a-z`, `0-9` and `_` are allowed
99
101
  # @param [String] value The value of a variable
102
+ # @param [Hash] opts optional parameters
100
103
  # @return [Gitlab::ObjectifiedHash] The variable.
101
- def create_group_variable(group, key, value)
102
- post("/groups/#{url_encode group}/variables", body: { key: key, value: value })
104
+ def create_group_variable(group, key, value, **opts)
105
+ post("/groups/#{url_encode group}/variables", body: opts.merge(key: key, value: value))
103
106
  end
104
107
 
105
108
  # Update a group's build variable.
@@ -110,9 +113,10 @@ class Gitlab::Client
110
113
  # @param [Integer, String] group The ID or name of a group.
111
114
  # @param [String] key The key of a variable
112
115
  # @param [String] value The value of a variable
116
+ # @param [Hash] opts optional parameters
113
117
  # @return [Gitlab::ObjectifiedHash] The variable.
114
- def update_group_variable(group, key, value)
115
- put("/groups/#{url_encode group}/variables/#{key}", body: { value: value })
118
+ def update_group_variable(group, key, value, **opts)
119
+ put("/groups/#{url_encode group}/variables/#{key}", body: opts.merge(value: value))
116
120
  end
117
121
 
118
122
  # Remove a group's build variable.
@@ -8,11 +8,11 @@ class Gitlab::Client
8
8
  #
9
9
  # @example
10
10
  # Gitlab.commits('viking')
11
- # Gitlab.repo_commits('gitlab', { ref_name: 'api' })
11
+ # Gitlab.repo_commits('gitlab', { ref: 'api' })
12
12
  #
13
13
  # @param [Integer, String] project The ID or name of a project.
14
14
  # @param [Hash] options A customizable set of options.
15
- # @option options [String] :ref_name The branch or tag name of a project repository.
15
+ # @option options [String] :ref The branch or tag name of a project repository.
16
16
  # @option options [Integer] :page The page number.
17
17
  # @option options [Integer] :per_page The number of results per page.
18
18
  # @return [Array<Gitlab::ObjectifiedHash>]
@@ -35,6 +35,22 @@ class Gitlab::Client
35
35
  end
36
36
  alias repo_commit commit
37
37
 
38
+ # Get all references (from branches or tags) a commit is pushed to.
39
+ #
40
+ # @example
41
+ # Gitlab.commit_refs(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
42
+ #
43
+ # @param [Integer, String] project The ID or name of a project.
44
+ # @param [String] sha The commit hash
45
+ # @param [Hash] options A customizable set of options.
46
+ # @option options [String] :type The scope of commits. Possible values `branch`, `tag`, `all`. Default is `all`.
47
+ # @option options [Integer] :page The page number.
48
+ # @option options [Integer] :per_page The number of results per page.
49
+ # @return [Gitlab::ObjectifiedHash]
50
+ def commit_refs(project, sha, options = {})
51
+ get("/projects/#{url_encode project}/repository/commits/#{sha}/refs", query: options)
52
+ end
53
+
38
54
  # Cherry picks a commit to a given branch.
39
55
  #
40
56
  # @example
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to Epics.
5
+ # @see https://docs.gitlab.com/ee/api/epics.html
6
+ module Epics
7
+ # Gets a list of epics.
8
+ #
9
+ # @example
10
+ # Gitlab.epics(123)
11
+ # Gitlab.epics(123, { per_page: 40, page: 2 })
12
+ #
13
+ # @param [Integer] group_id The ID of a group.
14
+ # @param [Hash] options A customizable set of options.
15
+ # @option options [Integer] :page The page number.
16
+ # @option options [Integer] :per_page The number of results per page.
17
+ # @return [Array<Gitlab::ObjectifiedHash>]
18
+ def epics(group_id, options = {})
19
+ get("/groups/#{group_id}/epics", query: options)
20
+ end
21
+
22
+ # Gets a single epic.
23
+ #
24
+ # @example
25
+ # Gitlab.epic(123, 1)
26
+ #
27
+ # @param [Integer] group_id The ID of a group.
28
+ # @param [Integer] epic_iid The ID of a epic.
29
+ # @param [Hash] options A customizable set of options.
30
+ # @return [Gitlab::ObjectifiedHash]
31
+ def epic(group_id, epic_iid, options = {})
32
+ get("/groups/#{group_id}/epics/#{epic_iid}", query: options)
33
+ end
34
+
35
+ # Creates a new epic.
36
+ #
37
+ # @example
38
+ # Gitlab.create_epic(123, "My new epic title")
39
+ #
40
+ # @param [Integer] group_id The ID of a group.
41
+ # @param [String] title
42
+ # @param [Hash] options A customizable set of options.
43
+ # @return [Gitlab::ObjectifiedHash] Information about created epic.
44
+ def create_epic(group_id, title, options = {})
45
+ body = options.merge(title: title)
46
+ post("/groups/#{group_id}/epics", body: body)
47
+ end
48
+
49
+ # Deletes an epic.
50
+ #
51
+ # @example
52
+ # Gitlab.delete_epic(42, 123)
53
+ # @param [Integer] group_id The ID of a group.
54
+ # @param [Integer] epic_iid The IID of an epic.
55
+ def delete_epic(group_id, epic_iid)
56
+ delete("/groups/#{group_id}/epics/#{epic_iid}")
57
+ end
58
+
59
+ # Updates an existing epic.
60
+ #
61
+ # @example
62
+ # Gitlab.edit_epic(42)
63
+ # Gitlab.edit_epic(42, 123, { title: 'New epic title' })
64
+ #
65
+ # @param [Integer] group_id The ID.
66
+ # @param [Integer] epic_iid The IID of an epic.
67
+ # @param [Hash] options A customizable set of options
68
+ # @return [Gitlab::ObjectifiedHash] Information about the edited epic.
69
+ def edit_epic(group_id, epic_iid, options = {})
70
+ put("/groups/#{group_id}/epics/#{epic_iid}", body: options)
71
+ end
72
+ end
73
+ end
@@ -24,9 +24,12 @@ class Gitlab::Client
24
24
  # Gitlab.group(42)
25
25
  #
26
26
  # @param [Integer] id The ID of a group.
27
+ # @param [Hash] options A customizable set of options.
28
+ # @option options [Boolean] :with_custom_attributes Include custom attributes in response (admins only)
29
+ # @option options [Boolean] :with_projects Include details about group projects (default: true)
27
30
  # @return [Gitlab::ObjectifiedHash]
28
- def group(id)
29
- get("/groups/#{url_encode id}")
31
+ def group(id, options = {})
32
+ get("/groups/#{url_encode id}", query: options)
30
33
  end
31
34
 
32
35
  # Creates a new group.
@@ -80,6 +83,18 @@ class Gitlab::Client
80
83
  get("/groups/#{url_encode team_id}/members/#{user_id}")
81
84
  end
82
85
 
86
+ # Gets a list of merge requests of a group.
87
+ #
88
+ # @example
89
+ # Gitlab.group_merge_requests(5)
90
+ #
91
+ # @param [Integer, String] group_id The ID or name of a group.
92
+ # @param [Hash] options A customizable set of options.
93
+ # @return [Array<Gitlab::ObjectifiedHash>]
94
+ def group_merge_requests(group, options = {})
95
+ get("/groups/#{group}/merge_requests", query: options)
96
+ end
97
+
83
98
  # Adds a user to group.
84
99
  #
85
100
  # @example
@@ -203,5 +218,42 @@ class Gitlab::Client
203
218
  def group_issues(group, options = {})
204
219
  get("/groups/#{group}/issues", query: options)
205
220
  end
221
+
222
+ # Sync group with LDAP
223
+ #
224
+ # @example
225
+ # Gitlab.sync_ldap_group(1)
226
+ #
227
+ # @param [Integer] id The ID or name of a group.
228
+ # @return [Array<Gitlab::ObjectifiedHash>]
229
+ def sync_ldap_group(id)
230
+ post("/groups/#{url_encode id}/ldap_sync")
231
+ end
232
+
233
+ # Add LDAP group link
234
+ #
235
+ # @example
236
+ # Gitlab.add_ldap_group_links(1, 'all', 50, 'ldap')
237
+ #
238
+ # @param [Integer] id The ID of a group
239
+ # @param [String] cn The CN of a LDAP group
240
+ # @param [Integer] group_access Minimum access level for members of the LDAP group.
241
+ # @param [String] provider LDAP provider for the LDAP group
242
+ # @return [Gitlab::ObjectifiedHash] Information about added ldap group link
243
+ def add_ldap_group_links(id, commonname, group_access, provider)
244
+ post("/groups/#{url_encode id}/ldap_group_links", body: { cn: commonname, group_access: group_access, provider: provider })
245
+ end
246
+
247
+ # Delete LDAP group link
248
+ #
249
+ # @example
250
+ # Gitlab.delete_ldap_group_links(1, 'all')
251
+ #
252
+ # @param [Integer] id The ID of a group
253
+ # @param [String] cn The CN of a LDAP group
254
+ # @return [Gitlab::ObjectifiedHash] Empty hash
255
+ def delete_ldap_group_links(id, commonname, provider)
256
+ delete("/groups/#{url_encode id}/ldap_group_links/#{url_encode provider}/#{url_encode commonname}")
257
+ end
206
258
  end
207
259
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to issue links.
5
+ # @see https://docs.gitlab.com/ee/api/issue_links.html
6
+ module IssueLinks
7
+ # Gets a list of links for a issue.
8
+ #
9
+ # @example
10
+ # Gitlab.issue_links(5, 10)
11
+ #
12
+ # @param [Integer] project The ID of a project.
13
+ # @param [Integer] issue The ID of an issue.
14
+ # @option options [Integer] :page The page number.
15
+ # @option options [Integer] :per_page The number of results per page.
16
+ # @return [Array<Gitlab::ObjectifiedHash>]
17
+ def issue_links(project, issue, options = {})
18
+ get("/projects/#{url_encode project}/issues/#{issue}/links", query: options)
19
+ end
20
+
21
+ # Creates a new issue link.
22
+ #
23
+ # @example
24
+ # Gitlab.create_issue_link(6, 1, 6, 2)
25
+ #
26
+ # @param [Integer, String] project The ID or name of a project.
27
+ # @param [Integer] issue The ID of an issue.
28
+ # @param [Integer] target_project_id Project ID the target issue is located in.
29
+ # @param [Integer] target_issue_iid The ID of the target issue.
30
+ # @return [Gitlab::ObjectifiedHash] Information about created link.
31
+ def create_issue_link(project, issue, target_project_id, target_issue_iid)
32
+ post("/projects/#{url_encode project}/issues/#{issue}/links", body: { target_project_id: target_project_id, target_issue_iid: target_issue_iid })
33
+ end
34
+
35
+ # Deletes an issue link.
36
+ #
37
+ # @example
38
+ # Gitlab.delete_issue_link(5, 10, 123)
39
+ #
40
+ # @param [Integer] project The ID of a project.
41
+ # @param [Integer] issue The ID of an issue.
42
+ # @param [Integer] id The ID of a link.
43
+ # @return [Gitlab::ObjectifiedHash]
44
+ def delete_issue_link(project, issue, id)
45
+ delete("/projects/#{url_encode project}/issues/#{issue}/links/#{id}")
46
+ end
47
+ end
48
+ end
@@ -104,9 +104,10 @@ class Gitlab::Client
104
104
  #
105
105
  # @param [Integer] project(required) The ID of a project.
106
106
  # @param [Integer] merge_request(required) The IID of a merge request.
107
+ # @option options [String] :sudo(optional) The username of the user you want to remove the approval for
107
108
  # @return [void] This API call returns an empty response body.
108
- def unapprove_merge_request(project, merge_request)
109
- post("/projects/#{url_encode project}/merge_requests/#{merge_request}/unapprove")
109
+ def unapprove_merge_request(project, merge_request, options = {})
110
+ post("/projects/#{url_encode project}/merge_requests/#{merge_request}/unapprove", body: options)
110
111
  end
111
112
  end
112
113
  end
@@ -529,14 +529,13 @@ class Gitlab::Client
529
529
  # @see https://docs.gitlab.com/ee/api/projects.html#upload-a-file
530
530
  #
531
531
  # @example
532
- # Gitlab.upload_file(1, File.open(File::NULL, 'r'))
533
- # File.open('myfile') { |file| Gitlab.upload_file(1, file) }
532
+ # Gitlab.upload_file(1, '/full/path/to/avatar.jpg')
534
533
  #
535
534
  # @param [Integer, String] id The ID or path of a project.
536
- # @param [File] The file you are interested to upload.
535
+ # @param [String] file_fullpath The fullpath of the file you are interested to upload.
537
536
  # @return [Gitlab::ObjectifiedHash]
538
- def upload_file(id, file)
539
- post("/projects/#{url_encode id}/uploads", body: { file: file })
537
+ def upload_file(id, file_fullpath)
538
+ post("/projects/#{url_encode id}/uploads", body: { file: File.open(file_fullpath, 'r') })
540
539
  end
541
540
 
542
541
  # Get all project templates of a particular type
@@ -13,7 +13,8 @@ class Gitlab::Client
13
13
  # @param [Integer, String] project The ID or name of a project.
14
14
  # @param [Hash] options A customizable set of options.
15
15
  # @option options [String] :path The path inside repository.
16
- # @option options [String] :ref_name The name of a repository branch or tag.
16
+ # @option options [String] :ref The name of a repository branch or tag.
17
+ # @option options [Integer] :per_page Number of results to show per page (default = 20)
17
18
  # @return [Gitlab::ObjectifiedHash]
18
19
  def tree(project, options = {})
19
20
  get("/projects/#{url_encode project}/repository/tree", query: options)
@@ -25,6 +25,22 @@ class Gitlab::Client
25
25
  end
26
26
  alias repo_file_contents file_contents
27
27
 
28
+ # Get file blame from repository
29
+ #
30
+ # @example
31
+ # Gitlab.get_file_blame(42, "README.md", "master")
32
+ #
33
+ # @param [Integer, String] project The ID or name of a project.
34
+ # @param [String] file_path The full path of the file.
35
+ # @param [String] ref The name of branch, tag or commit.
36
+ # @return [Gitlab::ObjectifiedHash]
37
+ #
38
+ def get_file_blame(project, file_path, ref)
39
+ get("/projects/#{url_encode project}/repository/files/#{url_encode file_path}/blame", query: {
40
+ ref: ref
41
+ })
42
+ end
43
+
28
44
  # Gets a repository file.
29
45
  #
30
46
  # @example
@@ -54,8 +54,12 @@ class Gitlab::Client
54
54
  # @param [String] scope The scope to search in. Currently these scopes are supported: issues, merge_requests, milestones, notes, wiki_blobs, commits, blobs.
55
55
  # @param [String] search The search query.
56
56
  # @return [Array<Gitlab::ObjectifiedHash>] Returns a list of responses depending on the requested scope.
57
- def search_in_project(project, scope, search)
57
+ def search_in_project(project, scope, search, ref = nil)
58
58
  options = { scope: scope, search: search }
59
+
60
+ # Add ref filter if provided - backward compatible with main project
61
+ options[:ref] = ref unless ref.nil?
62
+
59
63
  get("/projects/#{url_encode project}/search", query: options)
60
64
  end
61
65
  end
@@ -37,11 +37,11 @@ class Gitlab::Client
37
37
  # @example
38
38
  # Gitlab.create_user('joe@foo.org', 'secret', 'joe', { name: 'Joe Smith' })
39
39
  # or
40
- # Gitlab.create_user('joe@foo.org', 'secret')
40
+ # Gitlab.create_user('joe@foo.org', 'secret', 'joe')
41
41
  #
42
- # @param [String] email The email of a user.
43
- # @param [String] password The password of a user.
44
- # @param [String] username The username of a user.
42
+ # @param [String] email(required) The email of a user.
43
+ # @param [String] password(required) The password of a user.
44
+ # @param [String] username(required) The username of a user.
45
45
  # @param [Hash] options A customizable set of options.
46
46
  # @option options [String] :name The name of a user. Defaults to email.
47
47
  # @option options [String] :skype The skype of a user.
@@ -51,11 +51,9 @@ class Gitlab::Client
51
51
  # @return [Gitlab::ObjectifiedHash] Information about created user.
52
52
  def create_user(*args)
53
53
  options = args.last.is_a?(Hash) ? args.pop : {}
54
- body = if args[2]
55
- { email: args[0], password: args[1], username: args[2] }
56
- else
57
- { email: args[0], password: args[1], name: args[0] }
58
- end
54
+ raise ArgumentError, 'Missing required parameters' unless args[2]
55
+
56
+ body = { email: args[0], password: args[1], username: args[2], name: args[0] }
59
57
  body.merge!(options)
60
58
  post('/users', body: body)
61
59
  end
@@ -35,7 +35,7 @@ module Gitlab
35
35
 
36
36
  # Resets all configuration options to the defaults.
37
37
  def reset
38
- self.endpoint = ENV['GITLAB_API_ENDPOINT']
38
+ self.endpoint = ENV['GITLAB_API_ENDPOINT'] || ENV['CI_API_V4_URL']
39
39
  self.private_token = ENV['GITLAB_API_PRIVATE_TOKEN'] || ENV['GITLAB_API_AUTH_TOKEN']
40
40
  self.httparty = get_httparty_config(ENV['GITLAB_API_HTTPARTY_OPTIONS'])
41
41
  self.sudo = nil
@@ -78,6 +78,18 @@ module Gitlab
78
78
  message
79
79
  end
80
80
  end
81
+
82
+ def method_missing(method, *args, &block)
83
+ if @response.parsed_response.key?(method)
84
+ @response.parsed_response[method]
85
+ else
86
+ super
87
+ end
88
+ end
89
+
90
+ def respond_to_missing?(method, include_private = false)
91
+ super || @response.parsed_response.key?(method, include_private)
92
+ end
81
93
  end
82
94
 
83
95
  # Raised when API endpoint returns the HTTP status code 400.
@@ -42,7 +42,12 @@ module Gitlab
42
42
  %w[get post put delete].each do |method|
43
43
  define_method method do |path, options = {}|
44
44
  httparty_config(options)
45
- authorization_header(options)
45
+
46
+ unless options[:unauthenticated]
47
+ options[:headers] ||= {}
48
+ options[:headers].merge!(authorization_header)
49
+ end
50
+
46
51
  validate self.class.send(method, @endpoint + path, options)
47
52
  end
48
53
  end
@@ -62,28 +67,25 @@ module Gitlab
62
67
  # Sets a base_uri and default_params for requests.
63
68
  # @raise [Error::MissingCredentials] if endpoint not set.
64
69
  def request_defaults(sudo = nil)
65
- self.class.default_params sudo: sudo
66
70
  raise Error::MissingCredentials, 'Please set an endpoint to API' unless @endpoint
67
71
 
72
+ self.class.default_params sudo: sudo
68
73
  self.class.default_params.delete(:sudo) if sudo.nil?
69
74
  end
70
75
 
71
76
  private
72
77
 
73
- # Sets a PRIVATE-TOKEN or Authorization header for requests.
78
+ # Returns an Authorization header hash
74
79
  #
75
- # @param [Hash] options A customizable set of options.
76
- # @option options [Boolean] :unauthenticated true if the API call does not require user authentication.
77
80
  # @raise [Error::MissingCredentials] if private_token and auth_token are not set.
78
- def authorization_header(options)
79
- return if options[:unauthenticated]
81
+ def authorization_header
80
82
  raise Error::MissingCredentials, 'Please provide a private_token or auth_token for user' unless @private_token
81
83
 
82
- options[:headers] = if @private_token.size < 21
83
- { 'PRIVATE-TOKEN' => @private_token }
84
- else
85
- { 'Authorization' => "Bearer #{@private_token}" }
86
- end
84
+ if @private_token.size < 21
85
+ { 'PRIVATE-TOKEN' => @private_token }
86
+ else
87
+ { 'Authorization' => "Bearer #{@private_token}" }
88
+ end
87
89
  end
88
90
 
89
91
  # Set HTTParty configuration
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitlab
4
- VERSION = '4.12.0'
4
+ VERSION = '4.13.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.12.0
4
+ version: 4.13.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: 2019-07-11 00:00:00.000000000 Z
12
+ date: 2019-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -152,12 +152,14 @@ files:
152
152
  - lib/gitlab/client/container_registry.rb
153
153
  - lib/gitlab/client/deployments.rb
154
154
  - lib/gitlab/client/environments.rb
155
+ - lib/gitlab/client/epics.rb
155
156
  - lib/gitlab/client/events.rb
156
157
  - lib/gitlab/client/features.rb
157
158
  - lib/gitlab/client/group_boards.rb
158
159
  - lib/gitlab/client/group_labels.rb
159
160
  - lib/gitlab/client/group_milestones.rb
160
161
  - lib/gitlab/client/groups.rb
162
+ - lib/gitlab/client/issue_links.rb
161
163
  - lib/gitlab/client/issues.rb
162
164
  - lib/gitlab/client/jobs.rb
163
165
  - lib/gitlab/client/keys.rb
@@ -224,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
226
  - !ruby/object:Gem::Version
225
227
  version: '0'
226
228
  requirements: []
227
- rubygems_version: 3.0.4
229
+ rubygems_version: 3.0.6
228
230
  signing_key:
229
231
  specification_version: 4
230
232
  summary: A Ruby wrapper and CLI for the GitLab API