debian-mirror-gitlab/app/services/compare_service.rb

37 lines
1 KiB
Ruby
Raw Normal View History

2015-09-25 12:07:36 +05:30
require 'securerandom'
2014-09-02 18:07:02 +05:30
# Compare 2 branches for one repo or between repositories
2016-06-02 11:05:42 +05:30
# and return Gitlab::Git::Compare object that responds to commits and diffs
2014-09-02 18:07:02 +05:30
class CompareService
2017-08-17 22:00:37 +05:30
attr_reader :start_project, :start_branch_name
2015-09-25 12:07:36 +05:30
2017-08-17 22:00:37 +05:30
def initialize(new_start_project, new_start_branch_name)
@start_project = new_start_project
@start_branch_name = new_start_branch_name
end
2015-09-25 12:07:36 +05:30
2017-08-17 22:00:37 +05:30
def execute(target_project, target_branch, straight: false)
2015-09-25 12:07:36 +05:30
# If compare with other project we need to fetch ref first
2017-08-17 22:00:37 +05:30
target_project.repository.with_repo_branch_commit(
start_project.repository,
start_branch_name) do |commit|
break unless commit
2015-09-25 12:07:36 +05:30
2017-09-10 17:25:29 +05:30
compare(commit.sha, target_project, target_branch, straight: straight)
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
end
private
2015-09-25 12:07:36 +05:30
2017-09-10 17:25:29 +05:30
def compare(source_sha, target_project, target_branch, straight:)
2016-09-13 17:45:13 +05:30
raw_compare = Gitlab::Git::Compare.new(
2016-06-02 11:05:42 +05:30
target_project.repository.raw_repository,
target_branch,
2016-11-03 12:29:30 +05:30
source_sha,
2017-09-10 17:25:29 +05:30
straight: straight
2015-09-25 12:07:36 +05:30
)
2016-09-13 17:45:13 +05:30
2016-11-03 12:29:30 +05:30
Compare.new(raw_compare, target_project, straight: straight)
2014-09-02 18:07:02 +05:30
end
end