2018-07-05 10:18:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-11 12:33:31 +00:00
|
|
|
require 'securerandom'
|
|
|
|
|
2017-11-24 11:58:05 +00:00
|
|
|
# Compare 2 refs for one repo or between repositories
|
2019-04-14 14:26:03 +00:00
|
|
|
# and return Compare object that responds to commits and diffs
|
2014-07-29 09:11:16 +00:00
|
|
|
class CompareService
|
2017-11-24 11:58:05 +00:00
|
|
|
attr_reader :start_project, :start_ref_name
|
2015-09-18 19:02:01 +00:00
|
|
|
|
2017-11-24 11:58:05 +00:00
|
|
|
def initialize(new_start_project, new_start_ref_name)
|
2017-01-06 15:29:13 +00:00
|
|
|
@start_project = new_start_project
|
2017-11-24 11:58:05 +00:00
|
|
|
@start_ref_name = new_start_ref_name
|
2016-12-08 09:57:52 +00:00
|
|
|
end
|
2015-08-11 12:33:31 +00:00
|
|
|
|
2018-03-08 01:29:12 +00:00
|
|
|
def execute(target_project, target_ref, base_sha: nil, straight: false)
|
2017-11-24 11:58:05 +00:00
|
|
|
raw_compare = target_project.repository.compare_source_branch(target_ref, start_project.repository, start_ref_name, straight: straight)
|
2017-01-04 17:52:21 +00:00
|
|
|
|
2019-04-14 14:26:03 +00:00
|
|
|
return unless raw_compare && raw_compare.base && raw_compare.head
|
2018-03-08 01:29:12 +00:00
|
|
|
|
|
|
|
Compare.new(raw_compare,
|
2020-01-30 21:08:47 +00:00
|
|
|
start_project,
|
2018-03-08 01:29:12 +00:00
|
|
|
base_sha: base_sha,
|
|
|
|
straight: straight)
|
2014-07-29 09:11:16 +00:00
|
|
|
end
|
|
|
|
end
|