Skip to content
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

Support Circle CI environment variables in Hatchet.git_branch #179

Closed
edmorley opened this issue Jan 26, 2021 · 2 comments · Fixed by #189
Closed

Support Circle CI environment variables in Hatchet.git_branch #179

edmorley opened this issue Jan 26, 2021 · 2 comments · Fixed by #189

Comments

@edmorley
Copy link
Member

Currently Hatchet.git_branch only recognises Travis CI environment variables, and for Circle CI has to fall back to querying Git:

hatchet/lib/hatchet.rb

Lines 28 to 38 in f97e6f5

def self.git_branch
# TRAVIS_BRANCH works fine unless the build is a pull-request. In that case, it will contain the target branch
# not the actual pull-request branch! TRAVIS_PULL_REQUEST_BRANCH contains the correct branch but will be empty
# for push builds. See: https://docs.travis-ci.com/user/environment-variables/
return ENV['TRAVIS_PULL_REQUEST_BRANCH'] if ENV['TRAVIS_PULL_REQUEST_BRANCH'] && !ENV['TRAVIS_PULL_REQUEST_BRANCH'].empty?
return ENV['TRAVIS_BRANCH'] if ENV['TRAVIS_BRANCH']
out = `git rev-parse --abbrev-ref HEAD`.strip
raise "Attempting to find current branch name. Error: Cannot describe git: #{out}" unless $?.success?
out
end

Circle sets the CIRCLE_BRANCH environment variable that could be used instead:
https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables

@schneems
Copy link
Contributor

I think the original reason for the travis code was that it stripped the git repo or branch info maybe? Not shelling out will be a tiny perf benefit. I'm not sure if there's other benefits.

@edmorley
Copy link
Member Author

I'm not sure if there's other benefits.

It avoids #180, though it's likely worth fixing that anyway for local use-cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants