Skip to content

Commit

Permalink
Merge pull request #505 from dropkitchen/feat/add-git-info
Browse files Browse the repository at this point in the history
Bitrise Coveralls support
  • Loading branch information
ksuther authored Oct 10, 2021
2 parents 571b1e2 + 9195c86 commit 034ab35
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
63 changes: 55 additions & 8 deletions lib/slather/coverage_service/coveralls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ def github_job_id
end
private :github_job_id

def bitrise_job_id
ENV['BITRISE_BUILD_NUMBER']
end
private :bitrise_job_id

def bitrise_pull_request
ENV['BITRISE_PULL_REQUEST']
end
private :bitrise_pull_request

def github_pull_request
ENV['CI_PULL_REQUEST'] || ""
end
Expand Down Expand Up @@ -71,6 +81,11 @@ def github_branch_name
end
private :github_branch_name

def bitrise_branch_name
ENV['BITRISE_GIT_BRANCH'] || `git ls-remote --heads origin | grep $(git rev-parse HEAD) | cut -d / -f 3-`.chomp
end
private :bitrise_branch_name

def buildkite_job_id
ENV['BUILDKITE_BUILD_NUMBER']
end
Expand Down Expand Up @@ -151,6 +166,19 @@ def github_git_info
end
private :github_git_info

def bitrise_git_info
{
:head => {
:id => ENV['BITRISE_GIT_COMMIT'],
:committer_name => (ENV['GIT_CLONE_COMMIT_AUTHOR_NAME'] || `git log --format=%an -n 1 HEAD`.chomp || ""),
:committer_email => (ENV['GIT_CLONE_COMMIT_AUTHOR_EMAIL'] || `git log --format=%ae -n 1 HEAD`.chomp || ""),
:message => (ENV['BITRISE_GIT_MESSAGE'] || `git log --format=%s -n 1 HEAD`.chomp || "")
},
:branch => bitrise_branch_name
}
end
private :bitrise_git_info

def github_build_url
"https://github.com/" + ENV['GITHUB_REPOSITORY'] + "/actions/runs/" + ENV['GITHUB_RUN_ID']
end
Expand Down Expand Up @@ -263,16 +291,35 @@ def coveralls_coverage_data
else
raise StandardError, "Environment variable `GITHUB_RUN_ID` not set. Is this running on github build?"
end
elsif ci_service == :bitrise
{
:service_job_id => bitrise_job_id,
:service_name => 'bitrise',
:repo_token => coverage_access_token,
:source_files => coverage_files.map(&:as_json),
:service_pull_request => bitrise_pull_request,
:service_branch => bitrise_branch_name,
:git => bitrise_git_info
}.to_json
else
{
:service_job_id => ENV['CI_BUILD_NUMBER'],
:service_name => ENV['CI_NAME'] ? ENV['CI_NAME'] : 'other',
:repo_token => coverage_access_token,
:source_files => coverage_files.map(&:as_json),
:service_build_url => ENV['CI_BUILD_URL'],
:service_pull_request => ENV['CI_PULL_REQUEST'],
:service_branch => ENV['CI_BRANCH']
}.to_json
:service_job_id => ENV['CI_BUILD_NUMBER'],
:service_name => ENV['CI_NAME'] || ci_service,
:repo_token => coverage_access_token,
:source_files => coverage_files.map(&:as_json),
:service_build_url => ENV['CI_BUILD_URL'],
:service_pull_request => ENV['CI_PULL_REQUEST'],
:service_branch => ENV['CI_BRANCH'],
:git => {
:head => {
:id => ENV['CI_COMMIT'],
:committer_name => (`git log --format=%an -n 1 HEAD`.chomp || ""),
:committer_email => (`git log --format=%ae -n 1 HEAD`.chomp || ""),
:message => (`git log --format=%s -n 1 HEAD`.chomp || "")
},
:branch => ENV['CI_BRANCH']
}
}.to_json
end
end
private :coveralls_coverage_data
Expand Down
2 changes: 1 addition & 1 deletion lib/slather/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def configure_ignore_list
end

def configure_ci_service
self.ci_service ||= (self.class.yml["ci_service"] || :unknown)
self.ci_service ||= (ENV["CI_SERVICE"] || self.class.yml["ci_service"] || :other)
end

def configure_input_format
Expand Down

0 comments on commit 034ab35

Please sign in to comment.