Module: Datadog::CI::Git::BaseBranchShaDetector
- Defined in:
- lib/datadog/ci/git/base_branch_sha_detector.rb
Class Method Summary collapse
Class Method Details
.base_branch_sha(base_branch) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/datadog/ci/git/base_branch_sha_detector.rb', line 10 def self.base_branch_sha(base_branch) Datadog.logger.debug { "Base branch: '#{base_branch}'" } remote_name = LocalRepository.get_remote_name Datadog.logger.debug { "Remote name: '#{remote_name}'" } source_branch = get_source_branch return nil if source_branch.nil? Datadog.logger.debug { "Source branch: '#{source_branch}'" } strategy = if base_branch.nil? BaseBranchShaDetection::Guesser.new(remote_name, source_branch) else BaseBranchShaDetection::MergeBaseExtractor.new(remote_name, source_branch, base_branch) end strategy.call end |
.get_source_branch ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/datadog/ci/git/base_branch_sha_detector.rb', line 30 def self.get_source_branch source_branch = CLI.exec_git_command(["rev-parse", "--abbrev-ref", "HEAD"]) if source_branch.nil? Datadog.logger.debug { "Could not get current branch" } return nil end # Verify the branch exists begin CLI.exec_git_command(["rev-parse", "--verify", "--quiet", source_branch]) rescue CLI::GitCommandExecutionError # Branch verification failed return nil end source_branch end |