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: 6d6075628af89a0c113a2f637af5b728f3009d60 (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
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
  def execute(source_project, source_branch, target_project, target_branch)
    source_commit = source_project.commit(source_branch)
    return unless source_commit

    source_sha = source_commit.sha

    # If compare with other project we need to fetch ref first
    unless target_project == source_project
      random_string = SecureRandom.hex

      target_project.repository.fetch_ref(
        source_project.repository.path_to_repo,
        "refs/heads/#{source_branch}",
        "refs/tmp/#{random_string}/head"
      )
    end

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

    Compare.new(raw_compare, target_project)
  end
end