gitlab-akerl 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.prospectus +11 -0
  4. data/.travis.yml +8 -0
  5. data/CHANGELOG.md +229 -0
  6. data/CONTRIBUTING.md +195 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +24 -0
  9. data/README.md +192 -0
  10. data/Rakefile +9 -0
  11. data/bin/console +10 -0
  12. data/bin/setup +6 -0
  13. data/exe/gitlab +7 -0
  14. data/gitlab-akerl.gemspec +31 -0
  15. data/lib/gitlab.rb +45 -0
  16. data/lib/gitlab/api.rb +19 -0
  17. data/lib/gitlab/cli.rb +89 -0
  18. data/lib/gitlab/cli_helpers.rb +241 -0
  19. data/lib/gitlab/client.rb +48 -0
  20. data/lib/gitlab/client/branches.rb +91 -0
  21. data/lib/gitlab/client/build_triggers.rb +51 -0
  22. data/lib/gitlab/client/build_variables.rb +66 -0
  23. data/lib/gitlab/client/builds.rb +106 -0
  24. data/lib/gitlab/client/commits.rb +121 -0
  25. data/lib/gitlab/client/groups.rb +144 -0
  26. data/lib/gitlab/client/issues.rb +113 -0
  27. data/lib/gitlab/client/labels.rb +57 -0
  28. data/lib/gitlab/client/merge_requests.rb +168 -0
  29. data/lib/gitlab/client/milestones.rb +78 -0
  30. data/lib/gitlab/client/namespaces.rb +20 -0
  31. data/lib/gitlab/client/notes.rb +161 -0
  32. data/lib/gitlab/client/pipelines.rb +68 -0
  33. data/lib/gitlab/client/projects.rb +471 -0
  34. data/lib/gitlab/client/repositories.rb +78 -0
  35. data/lib/gitlab/client/repository_files.rb +88 -0
  36. data/lib/gitlab/client/runners.rb +115 -0
  37. data/lib/gitlab/client/services.rb +50 -0
  38. data/lib/gitlab/client/snippets.rb +91 -0
  39. data/lib/gitlab/client/system_hooks.rb +59 -0
  40. data/lib/gitlab/client/tags.rb +96 -0
  41. data/lib/gitlab/client/users.rb +250 -0
  42. data/lib/gitlab/configuration.rb +55 -0
  43. data/lib/gitlab/error.rb +85 -0
  44. data/lib/gitlab/file_response.rb +46 -0
  45. data/lib/gitlab/help.rb +95 -0
  46. data/lib/gitlab/objectified_hash.rb +34 -0
  47. data/lib/gitlab/page_links.rb +33 -0
  48. data/lib/gitlab/paginated_response.rb +97 -0
  49. data/lib/gitlab/request.rb +117 -0
  50. data/lib/gitlab/shell.rb +84 -0
  51. data/lib/gitlab/shell_history.rb +59 -0
  52. data/lib/gitlab/version.rb +3 -0
  53. data/spec/fixtures/branch.json +1 -0
  54. data/spec/fixtures/branch_delete.json +3 -0
  55. data/spec/fixtures/branches.json +1 -0
  56. data/spec/fixtures/build.json +38 -0
  57. data/spec/fixtures/build_artifacts.json +0 -0
  58. data/spec/fixtures/build_cancel.json +24 -0
  59. data/spec/fixtures/build_erase.json +24 -0
  60. data/spec/fixtures/build_retry.json +24 -0
  61. data/spec/fixtures/builds.json +78 -0
  62. data/spec/fixtures/builds_commits.json +64 -0
  63. data/spec/fixtures/compare_merge_request_diff.json +31 -0
  64. data/spec/fixtures/error_already_exists.json +1 -0
  65. data/spec/fixtures/error_project_not_found.json +1 -0
  66. data/spec/fixtures/get_repository_file.json +1 -0
  67. data/spec/fixtures/git_hook.json +1 -0
  68. data/spec/fixtures/group.json +60 -0
  69. data/spec/fixtures/group_create.json +1 -0
  70. data/spec/fixtures/group_create_with_description.json +1 -0
  71. data/spec/fixtures/group_delete.json +1 -0
  72. data/spec/fixtures/group_member.json +1 -0
  73. data/spec/fixtures/group_member_delete.json +1 -0
  74. data/spec/fixtures/group_member_edit.json +1 -0
  75. data/spec/fixtures/group_members.json +1 -0
  76. data/spec/fixtures/group_projects.json +44 -0
  77. data/spec/fixtures/group_search.json +2 -0
  78. data/spec/fixtures/groups.json +2 -0
  79. data/spec/fixtures/issue.json +1 -0
  80. data/spec/fixtures/issues.json +1 -0
  81. data/spec/fixtures/key.json +1 -0
  82. data/spec/fixtures/keys.json +1 -0
  83. data/spec/fixtures/label.json +1 -0
  84. data/spec/fixtures/labels.json +1 -0
  85. data/spec/fixtures/merge_request.json +1 -0
  86. data/spec/fixtures/merge_request_changes.json +1 -0
  87. data/spec/fixtures/merge_request_comment.json +1 -0
  88. data/spec/fixtures/merge_request_comments.json +1 -0
  89. data/spec/fixtures/merge_request_commits.json +1 -0
  90. data/spec/fixtures/merge_requests.json +1 -0
  91. data/spec/fixtures/milestone.json +1 -0
  92. data/spec/fixtures/milestone_issues.json +1 -0
  93. data/spec/fixtures/milestones.json +1 -0
  94. data/spec/fixtures/namespaces.json +1 -0
  95. data/spec/fixtures/note.json +1 -0
  96. data/spec/fixtures/notes.json +1 -0
  97. data/spec/fixtures/pipeline.json +23 -0
  98. data/spec/fixtures/pipeline_cancel.json +23 -0
  99. data/spec/fixtures/pipeline_create.json +23 -0
  100. data/spec/fixtures/pipeline_retry.json +23 -0
  101. data/spec/fixtures/pipelines.json +48 -0
  102. data/spec/fixtures/project.json +1 -0
  103. data/spec/fixtures/project_commit.json +13 -0
  104. data/spec/fixtures/project_commit_comment.json +1 -0
  105. data/spec/fixtures/project_commit_comments.json +1 -0
  106. data/spec/fixtures/project_commit_diff.json +10 -0
  107. data/spec/fixtures/project_commit_status.json +42 -0
  108. data/spec/fixtures/project_commits.json +1 -0
  109. data/spec/fixtures/project_edit.json +21 -0
  110. data/spec/fixtures/project_events.json +1 -0
  111. data/spec/fixtures/project_for_user.json +1 -0
  112. data/spec/fixtures/project_fork.json +50 -0
  113. data/spec/fixtures/project_fork_link.json +1 -0
  114. data/spec/fixtures/project_forked_for_user.json +50 -0
  115. data/spec/fixtures/project_hook.json +1 -0
  116. data/spec/fixtures/project_hooks.json +1 -0
  117. data/spec/fixtures/project_issues.json +1 -0
  118. data/spec/fixtures/project_key.json +6 -0
  119. data/spec/fixtures/project_keys.json +6 -0
  120. data/spec/fixtures/project_runner_enable.json +7 -0
  121. data/spec/fixtures/project_runners.json +16 -0
  122. data/spec/fixtures/project_search.json +1 -0
  123. data/spec/fixtures/project_star.json +44 -0
  124. data/spec/fixtures/project_tag_annotated.json +1 -0
  125. data/spec/fixtures/project_tag_lightweight.json +1 -0
  126. data/spec/fixtures/project_tags.json +1 -0
  127. data/spec/fixtures/project_unstar.json +44 -0
  128. data/spec/fixtures/project_update_commit_status.json +20 -0
  129. data/spec/fixtures/projects.json +1 -0
  130. data/spec/fixtures/raw_file.json +2 -0
  131. data/spec/fixtures/release_create.json +1 -0
  132. data/spec/fixtures/release_update.json +1 -0
  133. data/spec/fixtures/repository_file.json +1 -0
  134. data/spec/fixtures/runner.json +26 -0
  135. data/spec/fixtures/runner_delete.json +7 -0
  136. data/spec/fixtures/runner_edit.json +26 -0
  137. data/spec/fixtures/runners.json +16 -0
  138. data/spec/fixtures/runners_all.json +30 -0
  139. data/spec/fixtures/service.json +1 -0
  140. data/spec/fixtures/session.json +1 -0
  141. data/spec/fixtures/shell_history.json +2 -0
  142. data/spec/fixtures/snippet.json +1 -0
  143. data/spec/fixtures/snippet_content.json +3 -0
  144. data/spec/fixtures/snippets.json +1 -0
  145. data/spec/fixtures/system_hook.json +1 -0
  146. data/spec/fixtures/system_hooks.json +1 -0
  147. data/spec/fixtures/tag.json +1 -0
  148. data/spec/fixtures/tag_create.json +1 -0
  149. data/spec/fixtures/tag_create_with_description.json +1 -0
  150. data/spec/fixtures/tag_delete.json +1 -0
  151. data/spec/fixtures/tags.json +1 -0
  152. data/spec/fixtures/team_member.json +1 -0
  153. data/spec/fixtures/team_members.json +1 -0
  154. data/spec/fixtures/tree.json +1 -0
  155. data/spec/fixtures/trigger.json +7 -0
  156. data/spec/fixtures/triggers.json +16 -0
  157. data/spec/fixtures/user.json +1 -0
  158. data/spec/fixtures/user_block_unblock.json +1 -0
  159. data/spec/fixtures/user_email.json +1 -0
  160. data/spec/fixtures/user_emails.json +1 -0
  161. data/spec/fixtures/user_search.json +1 -0
  162. data/spec/fixtures/users.json +1 -0
  163. data/spec/fixtures/variable.json +4 -0
  164. data/spec/fixtures/variables.json +10 -0
  165. data/spec/gitlab/cli_helpers_spec.rb +57 -0
  166. data/spec/gitlab/cli_spec.rb +110 -0
  167. data/spec/gitlab/client/branches_spec.rb +99 -0
  168. data/spec/gitlab/client/build_triggers_spec.rb +67 -0
  169. data/spec/gitlab/client/build_variables_spec.rb +86 -0
  170. data/spec/gitlab/client/builds_spec.rb +148 -0
  171. data/spec/gitlab/client/client_spec.rb +11 -0
  172. data/spec/gitlab/client/commits_spec.rb +137 -0
  173. data/spec/gitlab/client/groups_spec.rb +197 -0
  174. data/spec/gitlab/client/issues_spec.rb +138 -0
  175. data/spec/gitlab/client/labels_spec.rb +68 -0
  176. data/spec/gitlab/client/merge_requests_spec.rb +177 -0
  177. data/spec/gitlab/client/milestones_spec.rb +82 -0
  178. data/spec/gitlab/client/namespaces_spec.rb +22 -0
  179. data/spec/gitlab/client/notes_spec.rb +205 -0
  180. data/spec/gitlab/client/pipelines_spec.rb +95 -0
  181. data/spec/gitlab/client/projects_spec.rb +603 -0
  182. data/spec/gitlab/client/repositories_spec.rb +109 -0
  183. data/spec/gitlab/client/repository_files_spec.rb +62 -0
  184. data/spec/gitlab/client/runners_spec.rb +185 -0
  185. data/spec/gitlab/client/services_spec.rb +55 -0
  186. data/spec/gitlab/client/snippets_spec.rb +100 -0
  187. data/spec/gitlab/client/system_hooks_spec.rb +69 -0
  188. data/spec/gitlab/client/tags_spec.rb +109 -0
  189. data/spec/gitlab/client/users_spec.rb +418 -0
  190. data/spec/gitlab/error_spec.rb +45 -0
  191. data/spec/gitlab/file_response_spec.rb +33 -0
  192. data/spec/gitlab/help_spec.rb +46 -0
  193. data/spec/gitlab/objectified_hash_spec.rb +48 -0
  194. data/spec/gitlab/page_links_spec.rb +16 -0
  195. data/spec/gitlab/paginated_response_spec.rb +60 -0
  196. data/spec/gitlab/request_spec.rb +73 -0
  197. data/spec/gitlab/shell_history_spec.rb +53 -0
  198. data/spec/gitlab/shell_spec.rb +80 -0
  199. data/spec/gitlab_spec.rb +97 -0
  200. data/spec/spec_helper.rb +74 -0
  201. metadata +476 -0
@@ -0,0 +1,241 @@
1
+ require 'yaml'
2
+ require 'json'
3
+ require 'base64'
4
+
5
+ class Gitlab::CLI
6
+ # Defines methods related to CLI output and formatting.
7
+ module Helpers
8
+ extend self
9
+
10
+ # Returns actions available to CLI & Shell
11
+ #
12
+ # @return [Array]
13
+ def actions
14
+ @actions ||= Gitlab.actions
15
+ end
16
+
17
+ # Returns Gitlab::Client instance
18
+ #
19
+ # @return [Gitlab::Client]
20
+ def client
21
+ @client ||= Gitlab::Client.new(endpoint: (Gitlab.endpoint || ''))
22
+ end
23
+
24
+ # Returns method names and their owners
25
+ #
26
+ # @return [Array<Hash>]
27
+ def method_owners
28
+ @method_owners ||= actions.map do |action|
29
+ {
30
+ name: action.to_s,
31
+ owner: client.method(action).owner.to_s
32
+ }
33
+ end
34
+ end
35
+
36
+ # Returns filtered required fields.
37
+ #
38
+ # @return [Array]
39
+ def required_fields(args)
40
+ if args.any? && args.last.is_a?(String) && args.last.start_with?('--only=')
41
+ args.last.gsub('--only=', '').split(',')
42
+ else
43
+ []
44
+ end
45
+ end
46
+
47
+ # Returns filtered excluded fields.
48
+ #
49
+ # @return [Array]
50
+ def excluded_fields(args)
51
+ if args.any? && args.last.is_a?(String) && args.last.start_with?('--except=')
52
+ args.last.gsub('--except=', '').split(',')
53
+ else
54
+ []
55
+ end
56
+ end
57
+
58
+ # Confirms command is valid.
59
+ #
60
+ # @return [Boolean]
61
+ def valid_command?(cmd)
62
+ command = cmd.is_a?(Symbol) ? cmd : cmd.to_sym
63
+ Gitlab.actions.include?(command)
64
+ end
65
+
66
+ # Confirms command with a desctructive action.
67
+ #
68
+ # @return [String]
69
+ def confirm_command(cmd)
70
+ if cmd.start_with?('remove_') || cmd.start_with?('delete_')
71
+ puts "Are you sure? (y/n)"
72
+ if %w(y yes).include?($stdin.gets.to_s.strip.downcase)
73
+ puts 'Proceeding..'
74
+ else
75
+ puts 'Command aborted.'
76
+ exit(1)
77
+ end
78
+ end
79
+ end
80
+
81
+ # Gets defined help for a specific command/action.
82
+ #
83
+ # @return [String]
84
+ def help(cmd=nil, &block)
85
+ if cmd.nil? || Gitlab::Help.help_map.key?(cmd)
86
+ Gitlab::Help.actions_table(cmd)
87
+ else
88
+ Gitlab::Help.get_help(cmd, &block)
89
+ end
90
+ end
91
+
92
+ # Outputs a nicely formatted table or error msg.
93
+ def output_table(cmd, args, data)
94
+ case data
95
+ when Gitlab::ObjectifiedHash, Gitlab::FileResponse
96
+ puts record_table([data], cmd, args)
97
+ when Gitlab::PaginatedResponse
98
+ puts record_table(data, cmd, args)
99
+ else # probably just an error msg
100
+ puts data
101
+ end
102
+ end
103
+
104
+ def output_json(cmd, args, data)
105
+ if data.empty?
106
+ puts '{}'
107
+ else
108
+ hash_result = case data
109
+ when Gitlab::ObjectifiedHash,Gitlab::FileResponse
110
+ record_hash([data], cmd, args, true)
111
+ when Gitlab::PaginatedResponse
112
+ record_hash(data, cmd, args)
113
+ else
114
+ { cmd: cmd, data: data, args: args }
115
+ end
116
+ puts JSON.pretty_generate(hash_result)
117
+ end
118
+ end
119
+
120
+ # Table to display records.
121
+ #
122
+ # @return [Terminal::Table]
123
+ def record_table(data, cmd, args)
124
+ return 'No data' if data.empty?
125
+
126
+ arr, keys = get_keys(args, data)
127
+
128
+ table do |t|
129
+ t.title = "Gitlab.#{cmd} #{args.join(', ')}"
130
+ t.headings = keys
131
+
132
+ arr.each_with_index do |hash, index|
133
+ values = []
134
+
135
+ keys.each do |key|
136
+ case value = hash[key]
137
+ when Hash
138
+ value = value.has_key?('id') ? value['id'] : 'Hash'
139
+ when StringIO
140
+ value = 'File'
141
+ when nil
142
+ value = 'null'
143
+ end
144
+
145
+ values << value
146
+ end
147
+
148
+ t.add_row values
149
+ t.add_separator unless arr.size - 1 == index
150
+ end
151
+ end
152
+ end
153
+
154
+ # Renders the result of given commands and arguments into a Hash
155
+ #
156
+ # @param [Array] data Resultset from the API call
157
+ # @param [String] cmd The command passed to the API
158
+ # @param [Array] args Options passed to the API call
159
+ # @param [bool] single_value If set to true, a single result should be returned
160
+ # @return [Hash] Result hash
161
+ def record_hash(data, cmd, args, single_value=false)
162
+ if data.empty?
163
+ result = nil
164
+ else
165
+ arr, keys = get_keys(args, data)
166
+ result = []
167
+ arr.each do |hash|
168
+ row = {}
169
+
170
+ keys.each do |key|
171
+ case hash[key]
172
+ when Hash
173
+ row[key] = 'Hash'
174
+ when StringIO
175
+ row[key] = Base64.encode64(hash[key].read)
176
+ when nil
177
+ row[key] = nil
178
+ else
179
+ row[key] = hash[key]
180
+ end
181
+ end
182
+
183
+ result.push row
184
+ end
185
+ result = result[0] if single_value && result.count > 0
186
+ end
187
+
188
+ {
189
+ cmd: "Gitlab.#{cmd} #{args.join(', ')}".strip,
190
+ result: result
191
+ }
192
+ end
193
+
194
+ # Helper function to get rows and keys from data returned from API call
195
+ def get_keys(args, data)
196
+ arr = data.map(&:to_h)
197
+ keys = arr.first.keys.sort { |x, y| x.to_s <=> y.to_s }
198
+ keys &= required_fields(args) if required_fields(args).any?
199
+ keys -= excluded_fields(args)
200
+ [arr, keys]
201
+ end
202
+
203
+ # Helper function to call Gitlab commands with args.
204
+ def gitlab_helper(cmd, args=[])
205
+ begin
206
+ data = args.any? ? Gitlab.send(cmd, *args) : Gitlab.send(cmd)
207
+ rescue => e
208
+ puts e.message
209
+ yield if block_given?
210
+ end
211
+
212
+ data
213
+ end
214
+
215
+ # Convert a hash (recursively) to use symbol hash keys
216
+ # @return [Hash]
217
+ def symbolize_keys(hash)
218
+ if hash.is_a?(Hash)
219
+ hash = hash.each_with_object({}) do |(key, value), newhash|
220
+ begin
221
+ newhash[key.to_sym] = symbolize_keys(value)
222
+ rescue NoMethodError
223
+ raise "error: cannot convert hash key to symbol: #{key}"
224
+ end
225
+ end
226
+ end
227
+
228
+ hash
229
+ end
230
+
231
+ # YAML::load on a single argument
232
+ def yaml_load(arg)
233
+ begin
234
+ yaml = YAML.load(arg)
235
+ rescue Psych::SyntaxError
236
+ raise "error: Argument is not valid YAML syntax: #{arg}"
237
+ end
238
+ yaml
239
+ end
240
+ end
241
+ end
@@ -0,0 +1,48 @@
1
+ module Gitlab
2
+ # Wrapper for the Gitlab REST API.
3
+ class Client < API
4
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f }
5
+
6
+ include Branches
7
+ include Builds
8
+ include BuildTriggers
9
+ include BuildVariables
10
+ include Commits
11
+ include Groups
12
+ include Issues
13
+ include Labels
14
+ include MergeRequests
15
+ include Milestones
16
+ include Namespaces
17
+ include Notes
18
+ include Pipelines
19
+ include Projects
20
+ include Repositories
21
+ include RepositoryFiles
22
+ include Runners
23
+ include Services
24
+ include Snippets
25
+ include SystemHooks
26
+ include Tags
27
+ include Users
28
+
29
+ # Text representation of the client, masking private token.
30
+ #
31
+ # @return [String]
32
+ def inspect
33
+ inspected = super
34
+
35
+ if @private_token
36
+ inspected = inspected.sub! @private_token, only_show_last_four_chars(@private_token)
37
+ end
38
+
39
+ inspected
40
+ end
41
+
42
+ private
43
+
44
+ def only_show_last_four_chars(token)
45
+ "#{'*'*(token.size - 4)}#{token[-4..-1]}"
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,91 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to repositories.
3
+ # @see https://docs.gitlab.com/ce/api/branches.html
4
+ module Branches
5
+ # Gets a list of project repositiory branches.
6
+ #
7
+ # @example
8
+ # Gitlab.branches(42)
9
+ #
10
+ # @param [Integer] project The ID of a project.
11
+ # @param [Hash] options A customizable set of options.
12
+ # @option options [Integer] :page The page number.
13
+ # @option options [Integer] :per_page The number of results per page.
14
+ # @return [Array<Gitlab::ObjectifiedHash>]
15
+ def branches(project, options={})
16
+ get("/projects/#{project}/repository/branches", query: options)
17
+ end
18
+ alias_method :repo_branches, :branches
19
+
20
+ # Gets information about a repository branch.
21
+ #
22
+ # @example
23
+ # Gitlab.branch(3, 'api')
24
+ # Gitlab.repo_branch(5, 'master')
25
+ #
26
+ # @param [Integer] project The ID of a project.
27
+ # @param [String] branch The name of the branch.
28
+ # @return [Gitlab::ObjectifiedHash]
29
+ def branch(project, branch)
30
+ get("/projects/#{project}/repository/branches/#{branch}")
31
+ end
32
+ alias_method :repo_branch, :branch
33
+
34
+ # Protects a repository branch.
35
+ #
36
+ # @example
37
+ # Gitlab.protect_branch(3, 'api')
38
+ # Gitlab.repo_protect_branch(5, 'master')
39
+ #
40
+ # @param [Integer] project The ID of a project.
41
+ # @param [String] branch The name of the branch.
42
+ # @return [Gitlab::ObjectifiedHash]
43
+ def protect_branch(project, branch)
44
+ put("/projects/#{project}/repository/branches/#{branch}/protect")
45
+ end
46
+ alias_method :repo_protect_branch, :protect_branch
47
+
48
+ # Unprotects a repository branch.
49
+ #
50
+ # @example
51
+ # Gitlab.unprotect_branch(3, 'api')
52
+ # Gitlab.repo_unprotect_branch(5, 'master')
53
+ #
54
+ # @param [Integer] project The ID of a project.
55
+ # @param [String] branch The name of the branch.
56
+ # @return [Gitlab::ObjectifiedHash]
57
+ def unprotect_branch(project, branch)
58
+ put("/projects/#{project}/repository/branches/#{branch}/unprotect")
59
+ end
60
+ alias_method :repo_unprotect_branch, :unprotect_branch
61
+
62
+ # Creates a repository branch. Requires Gitlab >= 6.8.x
63
+ #
64
+ # @example
65
+ # Gitlab.create_branch(3, 'api')
66
+ # Gitlab.repo_create_branch(5, 'master')
67
+ #
68
+ # @param [Integer] project The ID of a project.
69
+ # @param [String] branch The name of the new branch.
70
+ # @param [String] ref Create branch from commit sha or existing branch
71
+ # @return [Gitlab::ObjectifiedHash]
72
+ def create_branch(project, branch, ref)
73
+ post("/projects/#{project}/repository/branches", body: { branch_name: branch, ref: ref })
74
+ end
75
+ alias_method :repo_create_branch, :create_branch
76
+
77
+ # Deletes a repository branch. Requires Gitlab >= 6.8.x
78
+ #
79
+ # @example
80
+ # Gitlab.delete_branch(3, 'api')
81
+ # Gitlab.repo_delete_branch(5, 'master')
82
+ #
83
+ # @param [Integer] project The ID of a project.
84
+ # @param [String] branch The name of the branch to delete
85
+ # @return [Gitlab::ObjectifiedHash]
86
+ def delete_branch(project, branch)
87
+ delete("/projects/#{project}/repository/branches/#{branch}")
88
+ end
89
+ alias_method :repo_delete_branch, :delete_branch
90
+ end
91
+ end
@@ -0,0 +1,51 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to builds.
3
+ # @see https://docs.gitlab.com/ce/api/build_triggers.html
4
+ module BuildTriggers
5
+ # Gets a list of the project's build triggers
6
+ #
7
+ # @example
8
+ # Gitlab.triggers(5)
9
+ #
10
+ # @param [Integer] project The ID of a project.
11
+ # @return [Array<Gitlab::ObjectifiedHash>] The list of triggers.
12
+ def triggers(project)
13
+ get("/projects/#{project}/triggers")
14
+ end
15
+
16
+ # Gets details of project's build trigger.
17
+ #
18
+ # @example
19
+ # Gitlab.trigger(5, '7b9148c158980bbd9bcea92c17522d')
20
+ #
21
+ # @param [Integer] project The ID of a project.
22
+ # @param [String] token The token of a trigger.
23
+ # @return [Gitlab::ObjectifiedHash] The trigger.
24
+ def trigger(project, token)
25
+ get("/projects/#{project}/triggers/#{token}")
26
+ end
27
+
28
+ # Create a build trigger for a project.
29
+ #
30
+ # @example
31
+ # Gitlab.create_trigger(5)
32
+ #
33
+ # @param [Integer] project The ID of a project.
34
+ # @return [Gitlab::ObjectifiedHash] The trigger.
35
+ def create_trigger(project)
36
+ post("/projects/#{project}/triggers")
37
+ end
38
+
39
+ # Remove a project's build trigger.
40
+ #
41
+ # @example
42
+ # Gitlab.remove_trigger(5, '7b9148c158980bbd9bcea92c17522d')
43
+ #
44
+ # @param [Integer] project The ID of a project.
45
+ # @param [String] token The token of a trigger.
46
+ # @return [Gitlab::ObjectifiedHash] The trigger.
47
+ def remove_trigger(project, token)
48
+ delete("/projects/#{project}/triggers/#{token}")
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,66 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to builds.
3
+ # @see https://docs.gitlab.com/ce/api/build_variables.html
4
+ module BuildVariables
5
+ # Gets a list of the project's build variables
6
+ #
7
+ # @example
8
+ # Gitlab.variables(5)
9
+ #
10
+ # @param [Integer] project The ID of a project.
11
+ # @return [Array<Gitlab::ObjectifiedHash>] The list of variables.
12
+ def variables(project)
13
+ get("/projects/#{project}/variables")
14
+ end
15
+
16
+ # Gets details of a project's specific build variable.
17
+ #
18
+ # @example
19
+ # Gitlab.build(5, "TEST_VARIABLE_1")
20
+ #
21
+ # @param [Integer] project The ID of a project.
22
+ # @param [String] key The key of a variable.
23
+ # @return [Gitlab::ObjectifiedHash] The variable.
24
+ def variable(project, key)
25
+ get("/projects/#{project}/variables/#{key}")
26
+ end
27
+
28
+ # Create a build variable for a project.
29
+ #
30
+ # @example
31
+ # Gitlab.create_variable(5, "NEW_VARIABLE", "new value")
32
+ #
33
+ # @param [Integer] project The ID of a project.
34
+ # @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
35
+ # @param [String] value The value of a variable
36
+ # @return [Gitlab::ObjectifiedHash] The variable.
37
+ def create_variable(project, key, value)
38
+ post("/projects/#{project}/variables", body: { key: key, value: value })
39
+ end
40
+
41
+ # Update a project's build variable.
42
+ #
43
+ # @example
44
+ # Gitlab.create_variable(5, "NEW_VARIABLE", "updated value")
45
+ #
46
+ # @param [Integer] project The ID of a project.
47
+ # @param [String] key The key of a variable
48
+ # @param [String] value The value of a variable
49
+ # @return [Gitlab::ObjectifiedHash] The variable.
50
+ def update_variable(project, key, value)
51
+ put("/projects/#{project}/variables/#{key}", body: { value: value })
52
+ end
53
+
54
+ # Remove a project's build variable.
55
+ #
56
+ # @example
57
+ # Gitlab.remove_variable(5, "VARIABLE_1")
58
+ #
59
+ # @param [Integer] project The ID of a project.
60
+ # @param [String] key The key of a variable.
61
+ # @return [Gitlab::ObjectifiedHash] The variable.
62
+ def remove_variable(project, key)
63
+ delete("/projects/#{project}/variables/#{key}")
64
+ end
65
+ end
66
+ end