Skip to content

Get commit hash from CI if failed to get it from Git #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/code_climate/test_reporter/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down