Commit e50e88b8 authored by Sean McGivern's avatar Sean McGivern Committed by Fatih Acet

Add blob_path to conflict file JSON

parent 3cc07e7e
module Gitlab
module Conflict
class File
include Gitlab::Routing.url_helpers
class MissingResolution < StandardError
end
CONTEXT_LINES = 3
attr_reader :merge_file_result, :their_path, :our_path, :repository
attr_reader :merge_file_result, :their_path, :our_path, :merge_request, :repository
def initialize(merge_file_result, conflict, repository:)
def initialize(merge_file_result, conflict, merge_request:)
@merge_file_result = merge_file_result
@their_path = conflict[:theirs][:path]
@our_path = conflict[:ours][:path]
@repository = repository
@merge_request = merge_request
@repository = merge_request.project.repository
end
# Array of Gitlab::Diff::Line objects
......@@ -147,6 +150,9 @@ module Gitlab
{
old_path: their_path,
new_path: our_path,
blob_path: namespace_project_blob_path(merge_request.project.namespace,
merge_request.project,
::File.join(merge_request.diff_refs.head_sha, our_path)),
sections: sections
}
end
......
......@@ -47,7 +47,7 @@ module Gitlab
Gitlab::Conflict::File.new(merge_index.merge_file(conflict[:ours][:path]),
conflict,
repository: repository)
merge_request: merge_request)
end
end
......
......@@ -6,10 +6,11 @@ describe Gitlab::Conflict::File, lib: true do
let(:rugged) { repository.rugged }
let(:their_commit) { rugged.branches['conflict-a'].target }
let(:our_commit) { rugged.branches['conflict-b'].target }
let(:merge_request) { create(:merge_request, source_branch: 'conflict-b', target_branch: 'conflict-a', source_project: project) }
let(:index) { rugged.merge_commits(our_commit, their_commit) }
let(:conflict) { index.conflicts.last }
let(:merge_file_result) { index.merge_file('files/ruby/regex.rb') }
let(:conflict_file) { Gitlab::Conflict::File.new(merge_file_result, conflict, repository: repository) }
let(:conflict_file) { Gitlab::Conflict::File.new(merge_file_result, conflict, merge_request: merge_request) }
describe '#resolve_lines' do
let(:section_keys) { conflict_file.sections.map { |section| section[:id] }.compact }
......@@ -141,4 +142,11 @@ describe Gitlab::Conflict::File, lib: true do
expect(section_ids.uniq).to eq(section_ids)
end
end
describe '#as_json' do
it 'includes the blob path for the file' do
expect(conflict_file.as_json[:blob_path]).
to eq("/#{project.namespace.to_param}/#{merge_request.project.to_param}/blob/#{our_commit.oid}/files/ruby/regex.rb")
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment