class CodeClimate::TestReporter::Git

Public Class Methods

branch_from_git_or_ci() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 17
def branch_from_git_or_ci
  clean_service_branch || clean_git_branch || "master"
end
clean_git_branch() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 32
def clean_git_branch
  git_branch = String(branch_from_git)
  clean = git_branch.sub(%r{^origin/}, "") unless git_branch.start_with?("(")

  !clean.empty? ? clean : nil
end
clean_service_branch() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 25
def clean_service_branch
  ci_branch = String(Ci.service_data[:branch])
  clean = ci_branch.strip.sub(%r{^origin/}, "")

  !clean.empty? ? clean : nil
end
committed_at_from_git_or_ci() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 21
def committed_at_from_git_or_ci
  committed_at_from_git || committed_at_from_ci
end
head_from_git_or_ci() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 13
def head_from_git_or_ci
  head_from_git || head_from_ci
end
info() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 5
def info
  {
    head:         head_from_git_or_ci,
    committed_at: committed_at_from_git_or_ci,
    branch:       branch_from_git_or_ci,
  }
end

Private Class Methods

branch_from_git() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 61
def branch_from_git
  git("rev-parse --abbrev-ref HEAD").chomp
end
committed_at_from_ci() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 50
def committed_at_from_ci
  if (value = Ci.service_data[:committed_at])
    value.to_i
  end
end
committed_at_from_git() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 56
def committed_at_from_git
  committed_at = git("log -1 --pretty=format:%ct")
  committed_at.to_i.zero? ? nil : committed_at.to_i
end
configured_git_dir() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 74
def configured_git_dir
  CodeClimate::TestReporter.configuration.git_dir
end
git(command) click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 65
def git(command)
  `git --git-dir="#{git_dir}/.git" #{command}`
end
git_dir() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 69
def git_dir
  return configured_git_dir unless configured_git_dir.nil?
  rails_git_dir_present? ? Rails.root : "."
end
head_from_ci() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 46
def head_from_ci
  Ci.service_data[:commit_sha]
end
head_from_git() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 41
def head_from_git
  commit_hash = git("log -1 --pretty=format:'%H'")
  !commit_hash.empty? ? commit_hash : nil
end
rails_git_dir_present?() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 78
def rails_git_dir_present?
  const_defined?(:Rails) && Rails.respond_to?(:root) && !Rails.root.nil? &&
    File.directory?(File.expand_path(".git", Rails.root))
end