diff --git a/lib/code_climate/test_reporter/git.rb b/lib/code_climate/test_reporter/git.rb index ad8660f..bab0943 100644 --- a/lib/code_climate/test_reporter/git.rb +++ b/lib/code_climate/test_reporter/git.rb @@ -4,7 +4,7 @@ class Git class << self def info { - head: head, + head: head_from_git_or_ci, committed_at: committed_at_from_git_or_ci, branch: branch_from_git_or_ci, } @@ -34,8 +34,17 @@ def clean_git_branch private - def head - git("log -1 --pretty=format:'%H'") + def head_from_git_or_ci + head_from_git || head_from_ci + end + + def head_from_git + commit_hash = git("log -1 --pretty=format:'%H'") + !commit_hash.empty? ? commit_hash : nil + end + + def head_from_ci + Ci.service_data[:commit_sha] end def committed_at_from_ci