Class: Circlemator::SelfMerger

Inherits:
Object
  • Object
show all
Defined in:
lib/circlemator/self_merger.rb

Constant Summary collapse

MESSAGE =
'Auto-merge by Circlemator!'

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ SelfMerger

Returns a new instance of SelfMerger.



8
9
10
11
12
13
14
15
# File 'lib/circlemator/self_merger.rb', line 8

def initialize(opts)
  github_repo = opts.fetch(:github_repo)
  raise "#{github_repo} is invalid" unless github_repo.is_a? GithubRepo

  @github_repo = github_repo
  @sha = opts.fetch(:sha)
  @opts = opts
end

Instance Method Details

#merge!Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/circlemator/self_merger.rb', line 17

def merge!
  pr_number, pr_url = PrFinder.new(@opts).find_pr
  return if pr_number.nil? || pr_url.nil?

  response = @github_repo.put "#{pr_url}/merge",
                              body: { commit_message: MESSAGE, sha: @sha }.to_json
  if response.code != 200
    body = JSON.parse(response.body)
    raise "Merge failed: #{body.fetch('message')}"
  end
end