Class: RoboPigeon::GitLab::MergeRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/robopigeon/gitlab/merge_request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(merge_request) ⇒ MergeRequest

Returns a new instance of MergeRequest.



4
5
6
# File 'lib/robopigeon/gitlab/merge_request.rb', line 4

def initialize(merge_request)
  self.merge_request = merge_request
end

Instance Attribute Details

#merge_requestObject

Returns the value of attribute merge_request.



3
4
5
# File 'lib/robopigeon/gitlab/merge_request.rb', line 3

def merge_request
  @merge_request
end

Class Method Details

.create!(source, target, title) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/robopigeon/gitlab/merge_request.rb', line 8

def self.create!(source, target, title)
  RoboPigeon::GitLab::MergeRequest.new(RoboPigeon::GitLab::Client.client.create_merge_request(
                                         RoboPigeon::GitLab::Client.project,
                                         title,
                                         source_branch: source,
                                         target_branch: target
                                       ))
end

.find(source, target) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/robopigeon/gitlab/merge_request.rb', line 17

def self.find(source, target)
  RoboPigeon::GitLab::MergeRequest.new(
    RoboPigeon::GitLab::Client.client.merge_requests(
      RoboPigeon::GitLab::Client.project,
      state: 'opened',
      source_branch: source,
      target_branch: target
    ).first
  )
end

Instance Method Details

#clientObject



32
33
34
# File 'lib/robopigeon/gitlab/merge_request.rb', line 32

def client
  gitlab.client
end

#comment!(text) ⇒ Object



36
37
38
# File 'lib/robopigeon/gitlab/merge_request.rb', line 36

def comment!(text)
  client.create_merge_request_note(RoboPigeon::GitLab::Client.project, merge_request.iid, body: text)
end

#gitlabObject



28
29
30
# File 'lib/robopigeon/gitlab/merge_request.rb', line 28

def gitlab
  RoboPigeon::GitLab::Client
end

#merge!Object



40
41
42
43
44
45
46
47
# File 'lib/robopigeon/gitlab/merge_request.rb', line 40

def merge!
  return if already_up_to_date

  return if merge_merge_request!

  close_merge_request!
  raise 'Merge request could not be merged'
end