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 14
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 25
def clean_git_branch
  git_branch = String(branch_from_git)
  clean = git_branch.sub(/^origin\//, "") unless git_branch.start_with?("(")

  clean.size > 0 ? clean : nil
end
clean_service_branch() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 18
def clean_service_branch
  ci_branch = String(Ci.service_data[:branch])
  clean = ci_branch.strip.sub(/^origin\//, "")

  clean.size > 0 ? clean : nil
end
info() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 6
def info
  {
    head:         head,
    committed_at: committed_at,
    branch:       branch_from_git,
  }
end

Private Class Methods

branch_from_git() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 43
def branch_from_git
  git('rev-parse --abbrev-ref HEAD').chomp
end
committed_at() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 38
def committed_at
  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 56
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 47
def git(command)
  %xgit --git-dir=#{git_dir}/.git #{command}`
end
git_dir() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 51
def git_dir
  return configured_git_dir unless configured_git_dir.nil?
  rails_git_dir_present? ? Rails.root : '.'
end
head() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 34
def head
  git("log -1 --pretty=format:'%H'")
end
rails_git_dir_present?() click to toggle source
# File lib/code_climate/test_reporter/git.rb, line 60
def rails_git_dir_present?
  defined?(Rails) && !Rails.root.nil? &&
    File.directory?(File.expand_path('.git', Rails.root))
end