Class: Readiness::GitLab::MergeRequests

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/gitlab/merge_requests.rb

Overview

Defines the class MergeRequests within the module Readiness::GitLab.

Author:

  • Jason Colyer

Since:

  • 1.0.12

Class Method Summary collapse

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

.comments(client, project, iid) ⇒ Array

Get all comments on a project merge request within GitLab.

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 5)
comments = Readiness::GitLab::MergeRequests.comments(client, project, 123)
pp comments.first['updated_at']
 # => "2013-10-02T09:56:03Z"

Parameters:

  • client (Object)

    An instance of Client

  • project (Object)

    An instance of Projects

  • iid (Integer)

    The IID of the merge request

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.12



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/support_readiness/gitlab/merge_requests.rb', line 81

def self.comments(client, project, iid)
  array = []
  page = 1
  loop do
    response = client.connection.get "projects/#{project.id}/merge_requests/#{iid}/notes?per_page=100&page=#{page}"
    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_comment!(client, project, iid, params) ⇒ Hash

Create a comment on a project merge request within GitLab.

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 5)
comment_params = {
  body: 'My name is Jason and I approve this comment',
  internal: true
}
comment = Readiness::GitLab::MergeRequests.create_comment(client, project, 123, comment_params)
pp comment['updated_at']
 # => "2024-09-23T15:42:13Z"

Parameters:

  • client (Object)

    An instance of Client

  • project (Object)

    An instance of Projects

  • iid (Integer)

    The IID of the merge request

  • params (Hash)

    The parameters to use in creating the comment

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.12



120
121
122
123
124
# File 'lib/support_readiness/gitlab/merge_requests.rb', line 120

def self.create_comment!(client, project, iid, params)
  response = client.connection.post "projects/#{project.id}/merge_requests/#{iid}/notes", params.to_json
  handle_request_error(1, 'GitLab', response.status, { action: 'Create MR comment', id: "projects/#{project.id}/merge_requests/#{iid}" }) unless response.status == 200
  Oj.load(response.body)
end

.find(client, project, iid) ⇒ Hash

Locates a project merge request within GitLab. This will not exit on error (except Authentication errors)

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
issue = Readiness::GitLab::MergeRequests.find(client, project, 5)
puts issues.web_url
# => "https://gitlab.com/gitlab-com/support/support-team-meta/-/merge_requests/5"

Parameters:

  • client (Object)

    An instance of Client

  • project (Object)

    An instance of Projects

  • iid (Integer)

    The issue ID to find

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.12



32
33
34
35
# File 'lib/support_readiness/gitlab/merge_requests.rb', line 32

def self.find(client, project, iid)
  response = client.connection.get "projects/#{project.id}/merge_requests/#{iid}"
  Oj.load(response.body)
end

.find!(client, project, iid) ⇒ Hash

Locates a project merge request within GitLab. This will exit on error

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
issue = Readiness::GitLab::MergeRequests.find!(client, project, 5)
puts issues.web_url
# => "https://gitlab.com/gitlab-com/support/support-team-meta/-/merge_requests/5"

Parameters:

  • client (Object)

    An instance of Client

  • project (Object)

    An instance of Projects

  • iid (Integer)

    The issue ID to find

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.12



56
57
58
59
60
# File 'lib/support_readiness/gitlab/merge_requests.rb', line 56

def self.find!(client, project, iid)
  response = client.connection.get "projects/#{project.id}/merge_requests/#{iid}"
  handle_request_error(1, 'GitLab', response.status, { action: 'Find MR', id: "projects/#{project.id}/merge_requests/#{iid}" }) unless response.status == 200
  Oj.load(response.body)
end