Skip to content

Commit

Permalink
feat(github): push coverage info from tags (TheKevJames#284)
Browse files Browse the repository at this point in the history
Modify the logic of getting the branch information to also be able
to parse out the tag name when dealing with a tag push event on
Github Actions.
  • Loading branch information
flacjacket authored and andy-maier committed Dec 23, 2022
1 parent ceb349e commit 085862d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion coveralls/git.py
Expand Up @@ -32,7 +32,10 @@ def git_branch():
branch = None
if os.environ.get('GITHUB_ACTIONS'):
github_ref = os.environ.get('GITHUB_REF')
if github_ref.startswith('refs/heads/'):
if (
github_ref.startswith('refs/heads/')
or github_ref.startswith('refs/tags/')
):
# E.g. in push events.
branch = github_ref.split('/', 2)[-1]
else:
Expand Down
12 changes: 11 additions & 1 deletion tests/git_test.py
Expand Up @@ -125,6 +125,16 @@ def test_gitinfo_github_pr(self):
'GITHUB_SHA': 'bb0e00166b28f49db04d6a8b8cb4bddb5afa529f',
'GITHUB_HEAD_REF': ''
}, clear=True)
def test_gitinfo_github_nopr(self):
def test_gitinfo_github_branch(self):
git_info = coveralls.git.git_info()
assert git_info['git']['branch'] == 'master'

@mock.patch.dict(os.environ, {
'GITHUB_ACTIONS': 'true',
'GITHUB_REF': 'refs/tags/v1.0',
'GITHUB_SHA': 'bb0e00166b28f49db04d6a8b8cb4bddb5afa529f',
'GITHUB_HEAD_REF': ''
}, clear=True)
def test_gitinfo_github_tag(self):
git_info = coveralls.git.git_info()
assert git_info['git']['branch'] == 'v1.0'

0 comments on commit 085862d

Please sign in to comment.