Skip to content
Snippets Groups Projects
Commit c9a12b1d authored by Josh Frye's avatar Josh Frye
Browse files

Start of MR confict resolver service

parent bc7fd405
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -321,6 +321,18 @@ class MergeRequest < ActiveRecord::Base
end
end
 
def conflicts?
project.repository.conflicts?(diff_head_sha, target_branch)
end
def conflicts
project.repository.conflicts(diff_head_sha, target_branch)
end
def conflict_diff(conflict)
project.repository.conflict_diff(diff_head_sha, target_branch, conflict[:ancestor][:path])
end
def merge_event
@merge_event ||= target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::MERGED).last
end
Loading
Loading
Loading
Loading
@@ -637,11 +637,11 @@ class Repository
def contributors
commits = self.commits(nil, limit: 2000, offset: 0, skip_merges: true)
 
commits.group_by(&:author_email).map do |email, commits|
commits.group_by(&:author_email).map do |author_email, author_commits|
contributor = Gitlab::Contributor.new
contributor.email = email
contributor.email = author_email
 
commits.each do |commit|
author_commits.each do |commit|
if contributor.name.blank?
contributor.name = commit.author_name
end
Loading
Loading
@@ -769,6 +769,39 @@ class Repository
end
end
 
def conflicts?(source_sha, target_branch)
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha)
if our_commit && their_commit
rugged.merge_commits(our_commit, their_commit).conflicts?
else
false
end
end
def conflicts(source_sha, target_branch)
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha)
if our_commit && their_commit
rugged.merge_commits(our_commit, their_commit).conflicts
else
[]
end
end
def conflict_diff(source_sha, target_branch, path)
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha)
if our_commit && their_commit && path
rugged.diff(our_commit, their_commit, { paths: [path], context_lines: 3 })
else
[]
end
end
def merge(user, source_sha, target_branch, options = {})
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha)
Loading
Loading
module MergeRequests
module Conflicts
class FormatterService
attr_accessor :rugged_input
def initialize(rugged_input)
@rugged_input = rugged_input
end
def format_from_rugged
# TODO: format!
@rugged_input
end
end
end
end
module MergeRequests
module Conflicts
class ResolverService
attr_accessor :merge_request
def initialize(merge_request)
@merge_request = merge_request
end
def conflicts
return [] unless @merge_request.conflicts?
diff_lines = []
@merge_request.conflicts.each do |c|
diff_lines.push(
Gitlab::Diff::Parser.new.parse(
@merge_request.conflict_diff(c).each_line.collect { |el| el.content }
).to_a
)
end
diff_lines
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment