Class: Datadog::CI::Git::BaseBranchShaDetection::Guesser

Inherits:
Base
  • Object
show all
Defined in:
lib/datadog/ci/git/base_branch_sha_detection/guesser.rb

Constant Summary collapse

POSSIBLE_BASE_BRANCHES =
%w[main master preprod prod dev development trunk].freeze
DEFAULT_LIKE_BRANCH_FILTER =
/^(#{POSSIBLE_BASE_BRANCHES.join("|")}|release\/.*|hotfix\/.*)$/.freeze

Instance Attribute Summary

Attributes inherited from Base

#remote_name, #source_branch

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Datadog::CI::Git::BaseBranchShaDetection::Base

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/datadog/ci/git/base_branch_sha_detection/guesser.rb', line 14

def call
  # Check and fetch base branches if they don't exist in local git repository
  check_and_fetch_base_branches(POSSIBLE_BASE_BRANCHES, remote_name)

  candidates = build_candidate_list(remote_name)

  if candidates.nil? || candidates.empty?
    Datadog.logger.debug { "No candidate branches found." }
    return nil
  end

  metrics = compute_branch_metrics(candidates, source_branch)
  Datadog.logger.debug { "Branch metrics: '#{metrics}'" }

  best_branch_sha = find_best_branch(metrics, remote_name)
  Datadog.logger.debug { "Best branch SHA: '#{best_branch_sha}'" }

  best_branch_sha
end