Class: Datadog::CI::Git::BaseBranchShaDetection::BranchMetric

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

Overview

Represents metrics for a git branch comparison including how far behind/ahead it is from a source branch and the common base commit SHA

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(branch_name:, behind:, ahead:, base_sha:) ⇒ BranchMetric

Returns a new instance of BranchMetric.



13
14
15
16
17
18
# File 'lib/datadog/ci/git/base_branch_sha_detection/branch_metric.rb', line 13

def initialize(branch_name:, behind:, ahead:, base_sha:)
  @branch_name = branch_name
  @behind = behind
  @ahead = ahead
  @base_sha = base_sha
end

Instance Attribute Details

#aheadObject (readonly)

Returns the value of attribute ahead.



11
12
13
# File 'lib/datadog/ci/git/base_branch_sha_detection/branch_metric.rb', line 11

def ahead
  @ahead
end

#base_shaObject (readonly)

Returns the value of attribute base_sha.



11
12
13
# File 'lib/datadog/ci/git/base_branch_sha_detection/branch_metric.rb', line 11

def base_sha
  @base_sha
end

#behindObject (readonly)

Returns the value of attribute behind.



11
12
13
# File 'lib/datadog/ci/git/base_branch_sha_detection/branch_metric.rb', line 11

def behind
  @behind
end

#branch_nameObject (readonly)

Returns the value of attribute branch_name.



11
12
13
# File 'lib/datadog/ci/git/base_branch_sha_detection/branch_metric.rb', line 11

def branch_name
  @branch_name
end

Instance Method Details

#divergence_scoreObject

Used for comparison when finding the best branch Lower divergence score is better



27
28
29
# File 'lib/datadog/ci/git/base_branch_sha_detection/branch_metric.rb', line 27

def divergence_score
  @ahead
end

#up_to_date?Boolean

Checks if the branch is up to date with the source branch

Returns:

  • (Boolean)


21
22
23
# File 'lib/datadog/ci/git/base_branch_sha_detection/branch_metric.rb', line 21

def up_to_date?
  @behind == 0 && @ahead == 0
end