class FaHarnessTools::CheckBranchProtection

Check if the sha being deployed belongs to the given branch.

Public Class Methods

new(client:, context:, branch:) click to toggle source
# File lib/fa-harness-tools/check_branch_protection.rb, line 4
def initialize(client:, context:, branch:)
  @client = client
  @context = context
  @branch = branch
  @logger = CheckLogger.new(
    name: "Check branch protection",
    description: "Only allow commits on the #{@branch} branch to be deployed",
  )
end

Public Instance Methods

verify?() click to toggle source
# File lib/fa-harness-tools/check_branch_protection.rb, line 14
def verify?
  @logger.start
  @logger.context_info(@client, @context)

  new_sha = @context.new_commit_sha

  @logger.info("checking if #{@branch} branch contains the commit")
  if @client.branch_contains?(@branch, new_sha)
    @logger.pass "#{@branch} contains #{new_sha}"
  else
    @logger.fail "#{@branch} does not contain #{new_sha}"
  end
end