Class: FightClub::Comparer

Inherits:
Object
  • Object
show all
Defined in:
lib/fight_club/comparer.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_pull, pr, git) ⇒ Comparer

Returns a new instance of Comparer.



3
4
5
6
7
# File 'lib/fight_club/comparer.rb', line 3

def initialize(base_pull, pr, git)
  @base_pull = base_pull
  @pr = pr
  @git = git
end

Instance Method Details

#attempt_to_merge_both_prs(branch) ⇒ Object



28
29
30
31
32
# File 'lib/fight_club/comparer.rb', line 28

def attempt_to_merge_both_prs(branch)
  result = git.merge("origin/#{branch}")

  !(result.include? 'CONFLICT')
end

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fight_club/comparer.rb', line 9

def execute
  Logger.new(STDOUT).info "Trying to merge #{pr.head.ref} into #{base_pull["head"]["ref"]}..."
  return unless pr.base.ref == FightClub.config.master_branch
  return if pr.head.ref == base_pull["head"]["ref"]

  git.reset_hard("origin/#{base_pull["head"]["ref"]}")
  git.checkout(pr.head.ref)
  return unless Merger.attempt_merge(pr, git)

  git.checkout(base_pull["head"]["ref"])

  Merger.attempt_merge(base_pull, git)

  unless attempt_to_merge_both_prs(pr.head.ref)
    Commenter.comment(pr, "Your branch currently conflicts with another open pull request: #{base_pull["_links"]["html"]["href"]}")
    Commenter.comment(base_pull, "Your branch currently conflicts with another open pull request: #{pr._links.html.href}")
  end
end