gitlab 4.9.0 → 4.13.1

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.
@@ -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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Gitlab::Client
4
- # Defines methods related to labels.
4
+ # Defines methods related to project labels.
5
5
  # @see https://docs.gitlab.com/ce/api/labels.html
6
6
  module Labels
7
7
  # Gets a list of project's labels.
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to lint/validations.
5
+ # @see https://docs.gitlab.com/ce/api/lint.html
6
+ module Lint
7
+ # Checks if your .gitlab-ci.yml file is valid.
8
+ #
9
+ # @example
10
+ # Gitlab.validate_gitlab_ci_yml("{ \"image\": \"ruby:2.6\", \"services\": [\"postgres\"], \"before_script\": [\"bundle install\", \"bundle exec rake db:create\"], \"variables\": {\"DB_NAME\": \"postgres\"}, \"types\": [\"test\", \"deploy\", \"notify\"], \"rspec\": { \"script\": \"rake spec\", \"tags\": [\"ruby\", \"postgres\"], \"only\": [\"branches\"]}}")
11
+ #
12
+ # @param [String] content the .gitlab-ci.yaml content.
13
+ # @return <Gitlab::ObjectifiedHash> Returns information about validity of the yml.
14
+ def validate_gitlab_ci_yml(content)
15
+ body = { content: content }
16
+ post('/lint', body: body)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to markdown.
5
+ # @see https://docs.gitlab.com/ce/api/markdown.html
6
+ module Markdown
7
+ # Render an arbitrary Markdown document
8
+ #
9
+ # @example
10
+ # Gitlab.markdown('Hello world! :tada:')
11
+ # Gitlab.markdown('Hello world! :tada:', gfm: true, project: 'group_example/project_example')
12
+ #
13
+ # @param [String] text The markdown text to render.
14
+ # @param [Hash] options A customizable set of options.
15
+ # @option options [Boolean] :gfm(optional) Render text using GitLab Flavored Markdown. Default is false.
16
+ # @option options [String] :project(optional) Use project as a context when creating references using GitLab Flavored Markdown. Authentication is required if a project is not public.
17
+ # @return <Gitlab::ObjectifiedHash> Returns the rendered markdown as response
18
+ def markdown(text, options = {})
19
+ body = { text: text }.merge(options)
20
+ post('/markdown', body: body)
21
+ end
22
+ end
23
+ end
@@ -37,11 +37,11 @@ class Gitlab::Client
37
37
  # Gitlab.edit_project_approvers(1, {approver_ids: [5], approver_groups: [1]})
38
38
  #
39
39
  # @param [Integer] project(required) The ID of a project.
40
- # @option options [Array] :approver_ids(optional) An array of User IDs that can approve MRs
41
- # @option options [Array] :approver_group_ids(optional) An array of Group IDs whose members can approve MRs
40
+ # @option options [Array] :approver_ids(required, nil if none) An array of User IDs that can approve MRs
41
+ # @option options [Array] :approver_group_ids(required, nil if none) An array of Group IDs whose members can approve MRs
42
42
  # @return [Gitlab::ObjectifiedHash] MR approval configuration information about the project
43
43
  def edit_project_approvers(project, options = {})
44
- put("/projects/#{url_encode project}/approvals", body: options)
44
+ put("/projects/#{url_encode project}/approvers", body: options)
45
45
  end
46
46
 
47
47
  # Get Configuration for approvals on a specific Merge Request.
@@ -76,8 +76,8 @@ class Gitlab::Client
76
76
  #
77
77
  # @param [Integer] project(required) The ID of a project.
78
78
  # @param [Integer] merge_request(required) The IID of a merge_request.
79
- # @option options [Array] :approver_ids(optional) An array of User IDs that can approve MRs
80
- # @option options [Array] :approver_group_ids(optional) An array of Group IDs whose members can approve MRs
79
+ # @option options [Array] :approver_ids(required, nil if none) An array of User IDs that can approve MRs
80
+ # @option options [Array] :approver_group_ids(required, nil if none) An array of Group IDs whose members can approve MRs
81
81
  # @return [Gitlab::ObjectifiedHash] MR approval configuration information about the project
82
82
  def edit_merge_request_approvers(project, merge_request, options = {})
83
83
  put("/projects/#{url_encode project}/merge_requests/#{merge_request}/approvers", body: options)
@@ -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
@@ -55,6 +55,18 @@ class Gitlab::Client
55
55
  get("/projects/#{url_encode project}/merge_requests/#{id}/pipelines")
56
56
  end
57
57
 
58
+ # Get a list of merge request participants.
59
+ #
60
+ # @example
61
+ # Gitlab.merge_request_participants(5, 36)
62
+ #
63
+ # @param [Integer, String] project The ID or name of a project.
64
+ # @param [Integer] id The ID of a merge request.
65
+ # @return [Array<Gitlab::ObjectifiedHash>]
66
+ def merge_request_participants(project, id)
67
+ get("/projects/#{url_encode project}/merge_requests/#{id}/participants")
68
+ end
69
+
58
70
  # Creates a merge request.
59
71
  #
60
72
  # @example
@@ -276,7 +276,7 @@ class Gitlab::Client
276
276
  # in the 'else'.
277
277
  def note_content(body)
278
278
  if body.is_a?(Hash)
279
- STDERR.puts 'Passing the note body as a Hash is deprecated. You should just pass the String.'
279
+ warn 'Passing the note body as a Hash is deprecated. You should just pass the String.'
280
280
  body
281
281
  else
282
282
  { body: body }
@@ -67,7 +67,7 @@ class Gitlab::Client
67
67
  # @option options [Boolean] :issues_enabled The issues integration for a project (0 = false, 1 = true).
68
68
  # @option options [Boolean] :snippets_enabled The snippets integration for a project (0 = false, 1 = true).
69
69
  # @option options [Boolean] :merge_requests_enabled The merge requests functionality for a project (0 = false, 1 = true).
70
- # @option options [Boolean] :public The setting for making a project public (0 = false, 1 = true).
70
+ # @option options [String] :visibility The setting for making a project public ('private', 'internal', 'public').
71
71
  # @option options [Integer] :user_id The user/owner id of a project.
72
72
  # @return [Gitlab::ObjectifiedHash] Information about created project.
73
73
  def create_project(name, options = {})
@@ -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
@@ -570,5 +569,27 @@ class Gitlab::Client
570
569
  def project_template(project, type, key, options = {})
571
570
  get("/projects/#{url_encode project}/templates/#{type}/#{key}", query: options)
572
571
  end
572
+
573
+ # Archives a project.
574
+ #
575
+ # @example
576
+ # Gitlab.archive_project(4)
577
+ #
578
+ # @param [Integer, String] id The ID or path of a project.
579
+ # @return [Gitlab::ObjectifiedHash] Information about archived project.
580
+ def archive_project(id)
581
+ post("/projects/#{url_encode id}/archive")
582
+ end
583
+
584
+ # Unarchives a project.
585
+ #
586
+ # @example
587
+ # Gitlab.unarchive_project(4)
588
+ #
589
+ # @param [Integer, String] id The ID or path of a project.
590
+ # @return [Gitlab::ObjectifiedHash] Information about unarchived project.
591
+ def unarchive_project(id)
592
+ post("/projects/#{url_encode id}/unarchive")
593
+ end
573
594
  end
574
595
  end
@@ -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)
@@ -28,9 +29,10 @@ class Gitlab::Client
28
29
  #
29
30
  # @param [Integer, String] project The ID or name of a project.
30
31
  # @param [String] ref The commit sha, branch, or tag to download.
32
+ # @param [String] format The archive format. Options are: tar.gz (default), tar.bz2, tbz, tbz2, tb2, bz2, tar, and zip
31
33
  # @return [Gitlab::FileResponse]
32
- def repo_archive(project, ref = 'master')
33
- get("/projects/#{url_encode project}/repository/archive",
34
+ def repo_archive(project, ref = 'master', format = 'tar.gz')
35
+ get("/projects/#{url_encode project}/repository/archive.#{format}",
34
36
  format: nil,
35
37
  headers: { Accept: 'application/octet-stream' },
36
38
  query: { sha: ref },
@@ -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
@@ -79,9 +79,11 @@ class Gitlab::Client
79
79
  # Gitlab.runner_jobs(1)
80
80
  #
81
81
  # @param [Integer] id The ID of a runner.
82
+ # @param [Hash] options A customizable set of options.
83
+ # @option options [String] :status Status of the job; one of: running, success, failed, canceled
82
84
  # @return [Array<Gitlab::ObjectifiedHash>]
83
- def runner_jobs(runner_id)
84
- get("/runners/#{url_encode runner_id}/jobs")
85
+ def runner_jobs(runner_id, options = {})
86
+ get("/runners/#{url_encode runner_id}/jobs", query: options)
85
87
  end
86
88
 
87
89
  # List all runners (specific and shared) available in the project. Shared runners are listed if at least one shared runner is defined and shared runners usage is enabled in the project's settings.
@@ -122,5 +124,50 @@ class Gitlab::Client
122
124
  def project_disable_runner(id, runner_id)
123
125
  delete("/projects/#{url_encode id}/runners/#{runner_id}")
124
126
  end
127
+
128
+ # Register a new Runner for the instance.
129
+ #
130
+ # @example
131
+ # Gitlab.register_runner('9142c16ea169eaaea3d752313a434a6e')
132
+ # Gitlab.register_runner('9142c16ea169eaaea3d752313a434a6e', description: 'Some Description', active: true, locked: false)
133
+ #
134
+ # @param [String] token Registration token.
135
+ # @param [Hash] options A customizable set of options.
136
+ # @option options [String] :description Runner description.
137
+ # @option options [Hash] :info Runner metadata.
138
+ # @option options [Boolean] :active Whether the Runner is active.
139
+ # @option options [Boolean] :locked Whether the Runner should be locked for current project.
140
+ # @option options [Boolean] :run_untagged Whether the Runner should handle untagged jobs.
141
+ # @option options [Array<String>] :tag_list List of Runner tags.
142
+ # @option options [Integer] :maximum_timeout Maximum timeout set when this Runner will handle the job.
143
+ # @return <Gitlab::ObjectifiedHash> Response against runner registration
144
+ def register_runner(token, options = {})
145
+ body = { token: token }.merge(options)
146
+ post('/runners', body: body)
147
+ end
148
+
149
+ # Deletes a registed Runner.
150
+ #
151
+ # @example
152
+ # Gitlab.delete_registered_runner('9142c16ea169eaaea3d752313a434a6e')
153
+ #
154
+ # @param [String] token Runner authentication token.
155
+ # @return [nil] This API call returns an empty response body.
156
+ def delete_registered_runner(token)
157
+ body = { token: token }
158
+ delete('/runners', body: body)
159
+ end
160
+
161
+ # Validates authentication credentials for a registered Runner.
162
+ #
163
+ # @example
164
+ # Gitlab.verify_auth_registered_runner('9142c16ea169eaaea3d752313a434a6e')
165
+ #
166
+ # @param [String] token Runner authentication token.
167
+ # @return [nil] This API call returns an empty response body.
168
+ def verify_auth_registered_runner(token)
169
+ body = { token: token }
170
+ post('/runners/verify', body: body)
171
+ end
125
172
  end
126
173
  end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to global searches, searching in projects and searching in groups.
5
+ # @see https://docs.gitlab.com/ce/api/search.html
6
+ module Search
7
+ # Search globally across the GitLab instance.
8
+ #
9
+ # @example
10
+ # Gitlab.search_globally('projects', 'gitlab')
11
+ # Gitlab.search_globally('issues', 'gitlab')
12
+ # Gitlab.search_globally('merge_requests', 'gitlab')
13
+ # Gitlab.search_globally('milestones', 'gitlab')
14
+ # Gitlab.search_globally('snippet_titles', 'gitlab')
15
+ # Gitlab.search_globally('snippet_blobs', 'gitlab')
16
+ #
17
+ # @param [String] scope The scope to search in. Currently these scopes are supported: projects, issues, merge_requests, milestones, snippet_titles, snippet_blobs.
18
+ # @param [String] search The search query.
19
+ # @return [Array<Gitlab::ObjectifiedHash>] Returns a list of responses depending on the requested scope.
20
+ def search_globally(scope, search)
21
+ options = { scope: scope, search: search }
22
+ get('/search', query: options)
23
+ end
24
+
25
+ # Search within the specified group.
26
+ #
27
+ # @example
28
+ # Gitlab.search_in_group(1, 'projects', 'gitlab')
29
+ # Gitlab.search_in_group(1, 'issues', 'gitlab')
30
+ # Gitlab.search_in_group(1, 'merge_requests', 'gitlab')
31
+ # Gitlab.search_in_group(1, 'milestones', 'gitlab')
32
+ #
33
+ # @param [Integer, String] group The ID or name of a group.
34
+ # @param [String] scope The scope to search in. Currently these scopes are supported: projects, issues, merge_requests, milestones.
35
+ # @param [String] search The search query.
36
+ # @return [Array<Gitlab::ObjectifiedHash>] Returns a list of responses depending on the requested scope.
37
+ def search_in_group(group, scope, search)
38
+ options = { scope: scope, search: search }
39
+ get("/groups/#{url_encode group}/search", query: options)
40
+ end
41
+
42
+ # Search within the specified project.
43
+ #
44
+ # @example
45
+ # Gitlab.search_in_project(1, 'issues', 'gitlab')
46
+ # Gitlab.search_in_project(1, 'merge_requests', 'gitlab')
47
+ # Gitlab.search_in_project(1, 'milestones', 'gitlab')
48
+ # Gitlab.search_in_project(1, 'notes', 'gitlab')
49
+ # Gitlab.search_in_project(1, 'wiki_blobs', 'gitlab')
50
+ # Gitlab.search_in_project(1, 'commits', 'gitlab')
51
+ # Gitlab.search_in_project(1, 'blobs', 'gitlab')
52
+ #
53
+ # @param [Integer, String] project The ID or name of a project.
54
+ # @param [String] scope The scope to search in. Currently these scopes are supported: issues, merge_requests, milestones, notes, wiki_blobs, commits, blobs.
55
+ # @param [String] search The search query.
56
+ # @return [Array<Gitlab::ObjectifiedHash>] Returns a list of responses depending on the requested scope.
57
+ def search_in_project(project, scope, search, ref = nil)
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
+
63
+ get("/projects/#{url_encode project}/search", query: options)
64
+ end
65
+ end
66
+ 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