8000 get branch/commit from git/hg codecov/support#112 · Kami/codecov-python@8310207 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8310207

Browse files
committed
get branch/commit from git/hg codecov/support#112
1 parent 69fb2fe commit 8310207

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

codecov/__init__.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,7 @@ def main(*argv, **kwargs):
339339
query.update(dict(branch=os.getenv('DRONE_BRANCH'),
340340
service='drone.io',
341341
build=os.getenv('DRONE_BUILD_NUMBER'),
342-
build_url=os.getenv('DRONE_BUILD_URL'),
343-
commit=subprocess.check_output("git rev-parse HEAD || hg id -i --debug | tr -d '+'", shell=True)))
342+
build_url=os.getenv('DRONE_BUILD_URL')))
344343
root = os.getenv('DRONE_BUILD_DIR') or root
345344
write(' Drone Detected')
346345

@@ -421,19 +420,26 @@ def main(*argv, **kwargs):
421420
root = os.getenv('HOME') + '/' + os.getenv('CI_PROJECT_DIR')
422421
write(' Gitlab CI Detected')
423422

424-
# ---
425-
# git
426-
# ---
427-
else:
423+
# ------
424+
# git/hg
425+
# ------
426+
if not query.get('branch'):
428427
try:
429428
# find branch, commit, repo from git command
430-
branch = subprocess.check_output('git rev-parse --abbrev-ref HEAD || hg branch', shell=True)
431-
query.update(dict(branch=branch if branch != 'HEAD' else '',
432-
commit=subprocess.check_output("git rev-parse HEAD || hg id -i --debug | tr -d '+'", shell=True)))
433-
write(' No CI Detected. Using git/mercurial')
429+
branch = try_to_run('git rev-parse --abbrev-ref HEAD || hg branch')
430+
query['branch'] = branch if branch != 'HEAD' else ''
431+
write(' -> Got branch from git/hg')
432+
433+
except:
434+
write(' x> Failed to get branch from git/hg')
435+
436+
if not query.get('commit'):
437+
try:
438+
query['commit'] = try_to_run("git rev-parse HEAD || hg id -i --debug | tr -d '+'")
439+
write(' -> Got sha from git/hg')
440+
434441
except: # pragma: no cover
435-
# may not be in a git backed repo
436-
pass
442+
write(' x> Failed to get sha from git/hg')
437443

438444
# Update Query
439445
# ------------

0 commit comments

Comments
 (0)
0