Коммит c9a12b1d создал по автору Josh Frye's avatar Josh Frye
Просмотр файлов

Start of MR confict resolver service

владелец bc7fd405
......@@ -321,6 +321,18 @@ def check_if_can_be_merged
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
......
......@@ -637,11 +637,11 @@ def tags_sorted_by(value)
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
......@@ -769,6 +769,39 @@ def can_be_merged?(source_sha, target_branch)
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)
......
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
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать