Welcome to mirror list, hosted at ThFree Co, Russian Federation.

compare_service.rb « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d3d613661a6d588f28be2f6467cb435dd82a6e2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'securerandom'

# Compare 2 branches for one repo or between repositories
# and return Gitlab::Git::Compare object that responds to commits and diffs
class CompareService
  attr_reader :source_project, :source_branch_name

  def initialize(new_source_project, new_source_branch_name)
    @source_project = new_source_project
    @source_branch_name = new_source_branch_name
  end

  def execute(target_project, target_branch, straight: false)
    # If compare with other project we need to fetch ref first
    target_project.repository.with_repo_branch_commit(
      source_project.repository,
      source_branch_name) do |commit|
      break unless commit

      compare(commit.sha, target_project, target_branch, straight)
    end
  end

  private

  def compare(source_sha, target_project, target_branch, straight)
    raw_compare = Gitlab::Git::Compare.new(
      target_project.repository.raw_repository,
      target_branch,
      source_sha,
      straight
    )

    Compare.new(raw_compare, target_project, straight: straight)
  end
end