Class: Readiness::GitLab::Repositories
- Defined in:
- lib/support_readiness/gitlab/repositories.rb
Overview
Anything listed on docs.gitlab.com/ee/api/repositories.html not currently here
Defines the class Repositories within the module Readiness::GitLab.
Class Method Summary collapse
-
.commits(client, project, filters) ⇒ Array
Lists a repository’s commits.
-
.create_commit!(client, project, params) ⇒ Hash
Create a commit on a repository within GitLab.
-
.create_file!(client, project, path, params) ⇒ Array
Create a single file in a repository.
-
.create_tag!(client, project, tag) ⇒ Hash
Creates a repository tag.
-
.delete_file!(client, project, path, params) ⇒ Boolean
Deletes a single file in a repository.
-
.delete_tag!(client, project, tag_name) ⇒ Boolean
Deletes a repository tag.
-
.file(client, project, path, ref) ⇒ Array
Get information about a file in a repository.
-
.find_tag(client, project, tag_name) ⇒ Hash
Locates a repository tag.
-
.find_tag!(client, project, tag_name) ⇒ Hash
Locates a repository tag.
-
.raw_file(client, project, path, ref) ⇒ String
Get raw information about a file in a repository.
-
.tags(client, project, filters = []) ⇒ Array
Lists a repository’s tags.
-
.tree(client, project, filters = []) ⇒ Array
Lists a repository’s file tree.
-
.update_file!(client, project, path, params) ⇒ Array
Updates a single file in a repository.
-
.update_submodule!(client, project, path, params) ⇒ Hash
Updates a submodule’s reference in a project.
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Class Method Details
.commits(client, project, filters) ⇒ Array
Lists a repository’s commits. This method can take a long time to run depending on the parameters used.
286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 286 def self.commits(client, project, filters) array = [] page = 1 loop do response = client.connection.get "projects/#{project.id}/repository/commits?per_page=100&page=#{page}&#{to_param_string(filters)}" handle_request_error(0, 'GitLab', response.status) unless response.status == 200 body = Oj.load(response.body) array += body break if body.count < 100 page += 1 end array end |
.create_commit!(client, project, params) ⇒ Hash
Create a commit on a repository within GitLab. This will exit on error.
229 230 231 232 233 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 229 def self.create_commit!(client, project, params) response = client.connection.post "projects/#{project.id}/repository/commits", params.to_json handle_request_error(1, 'GitLab', response.status, { action: 'Create commit', id: "#{project.id}" }) unless response.status == 200 Oj.load(response.body) end |
.create_file!(client, project, path, params) ⇒ Array
Create a single file in a repository. This will exit on error. You might want to instead use create_commit!
128 129 130 131 132 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 128 def self.create_file!(client, project, path, params) response = client.connection.post "projects/#{project.id}/repository/files/#{ERB::Util.url_encode(path)}", params.to_json handle_request_error(1, 'GitLab', response.status, { action: 'Create file in repo', id: "#{project.id}" }) unless response.status == 200 Oj.load(response.body) end |
.create_tag!(client, project, tag) ⇒ Hash
Creates a repository tag. This will exit on error
409 410 411 412 413 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 409 def self.create_tag!(client, project, tag) response = client.connection.post "projects/#{project.id}/repository/tags", tag.to_json handle_request_error(1, 'GitLab', response.status, { action: 'Create tag', id: "projects/#{project.id}/repository/tags" }) unless response.status == 200 Oj.load(response.body) end |
.delete_file!(client, project, path, params) ⇒ Boolean
Deletes a single file in a repository. This will exit on error. You might want to instead use create_commit!
192 193 194 195 196 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 192 def self.delete_file!(client, project, path, params) response = client.connection.delete "projects/#{project.id}/repository/files/#{ERB::Util.url_encode(path)}", params handle_request_error(1, 'GitLab', response.status, { action: 'Delete file in repo', id: "#{project.id}" }) unless response.status == 204 true end |
.delete_tag!(client, project, tag_name) ⇒ Boolean
Deletes a repository tag. This will exit on error
434 435 436 437 438 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 434 def self.delete_tag!(client, project, tag_name) response = client.connection.delete "projects/#{project.id}/repository/tags/#{tag_name}" handle_request_error(1, 'GitLab', response.status, { action: 'Delete tag', id: "projects/#{project.id}/repository/tags/#{tag_name}" }) unless response.status == 200 true end |
.file(client, project, path, ref) ⇒ Array
Get information about a file in a repository.
69 70 71 72 73 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 69 def self.file(client, project, path, ref) response = client.connection.get "projects/#{project.id}/repository/files/#{ERB::Util.url_encode(path)}?ref=#{ref}" handle_request_error(0, 'GitLab', response.status) unless response.status == 200 Oj.load(response.body) end |
.find_tag(client, project, tag_name) ⇒ Hash
Locates a repository tag. This will not exit on error (except Authentication errors)
355 356 357 358 359 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 355 def self.find_tag(client, project, tag_name) response = client.connection.get "projects/#{project.id}/repository/tags/#{tag_name}" handle_request_error(0, 'GitLab', response.status, { action: 'get', id: "projects/#{project.id}/repository/tags/#{tag_name}" }) unless response.status == 200 Oj.load(response.body) end |
.find_tag!(client, project, tag_name) ⇒ Hash
Locates a repository tag. This will exit on error
380 381 382 383 384 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 380 def self.find_tag!(client, project, tag_name) response = client.connection.get("projects/#{project.id}/repository/tags/#{tag_name}") handle_request_error(1, 'GitLab', response.status, { action: 'Find tag', id: "projects/#{project.id}/repository/tags/#{tag_name}" }) unless response.status == 200 Oj.load(response.body) end |
.raw_file(client, project, path, ref) ⇒ String
Get raw information about a file in a repository.
95 96 97 98 99 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 95 def self.raw_file(client, project, path, ref) response = client.connection.get "projects/#{project.id}/repository/files/#{ERB::Util.url_encode(path)}/raw?ref=#{ref}" handle_request_error(0, 'GitLab', response.status) unless response.status == 200 response.body end |
.tags(client, project, filters = []) ⇒ Array
Lists a repository’s tags. This method can take a long time to run depending on the parameters used.
321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 321 def self.(client, project, filters = []) array = [] page = 1 loop do response = client.connection.get "projects/#{project.id}/repository/tags?per_page=100&page=#{page}&#{to_param_string(filters)}" handle_request_error(0, 'GitLab', response.status) unless response.status == 200 body = Oj.load(response.body) array += body break if body.count < 100 page += 1 end array end |
.tree(client, project, filters = []) ⇒ Array
Lists a repository’s file tree. This method can take a long time to run depending on the parameters used.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 34 def self.tree(client, project, filters = []) array = [] url = "projects/#{project.id}/repository/tree?per_page=100&pagination=keyset&order_by=id&sort=asc&id_after=0&#{to_param_string(filters)}" loop do response = client.connection.get url handle_request_error(0, 'GitLab', response.status) unless response.status == 200 body = Oj.load(response.body) array += body break if body.count < 100 url = "projects/#{project.id}/repository/tree?per_page=100&pagination=keyset&order_by=id&sort=asc&id_after=0&#{to_param_string(filters)}" end array end |
.update_file!(client, project, path, params) ⇒ Array
Updates a single file in a repository. This will exit on error. You might want to instead use create_commit!
161 162 163 164 165 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 161 def self.update_file!(client, project, path, params) response = client.connection.put "projects/#{project.id}/repository/files/#{ERB::Util.url_encode(path)}", params.to_json handle_request_error(1, 'GitLab', response.status, { action: 'Update file in repo', id: "#{project.id}" }) unless response.status == 200 Oj.load(response.body) end |
.update_submodule!(client, project, path, params) ⇒ Hash
Updates a submodule’s reference in a project. This will exit on error.
260 261 262 263 264 |
# File 'lib/support_readiness/gitlab/repositories.rb', line 260 def self.update_submodule!(client, project, path, params) response = client.connection.put "projects/#{project.id}/repository/submodules/#{ERB::Util.url_encode(path)}", params.to_json handle_request_error(1, 'GitLab', response.status, { action: 'Update submodule in repo', id: "#{project.id}" }) unless response.status == 200 Oj.load(response.body) end |