merge_request.rb 848 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
# frozen_string_literal: true

module ReleaseTools
  class MergeRequest < Issuable
    def milestone
      self[:milestone] || nil
    end

    def source_branch
      self[:source_branch] || raise(ArgumentError, 'Please set a `source_branch`!')
    end

    def target_branch
      self[:target_branch] || 'master'
    end

    def create
      GitlabClient.create_merge_request(self, project)
    end

    def accept
      GitlabClient.accept_merge_request(self, project)
    end

    def approve
      GitlabClient.approve_merge_request(self, project)
    end

    def to_reference
      "#{project.path}!#{iid}"
    end

    def conflicts
      self[:conflicts] || nil
    end

    def conflicts?
      conflicts&.any?
    end

    def remote_issuable
      @remote_issuable ||= GitlabClient.find_merge_request(self, project)
    end
  end
end