Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit 51c6c54

Browse files
committed
add yaml parsing
1 parent 8957e96 commit 51c6c54

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

codecov/__init__.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,6 @@ def main(*argv, **kwargs):
555555
query['token'] = fopen(opj(os.getcwd(), query['token'][1:])).strip()
556556

557557
assert query.get('commit') not in ('', None), "Commit sha is missing. Please specify via --commit=:sha"
558-
assert query.get('job') or query.get('token'), "Missing repository upload token"
559558

560559
# Build TOC
561560
# ---------
@@ -565,25 +564,31 @@ def main(*argv, **kwargs):
565564
try_to_run('hg locate') or '').strip())
566565

567566
# Detect codecov.yml location
568-
for _filename in toc.splitlines():
569-
if _filename in ('codecov.yml', '.codecov.yml') or _filename.endswith(('/codecov.yml', '/.codecov.yml')):
570-
query['yaml'] = _filename
571-
# from yaml import load
572-
# ccyaml = load(fopen(_filename)).get('codecov')
573-
# if ccyaml and type(ccyaml) is dict:
574-
# if ccyaml.get('token'):
575-
# write(' Set token from yaml')
576-
# query['token'] = ccyaml.get('token')
577-
578-
# if ccyaml.get('url'):
579-
# write(' Set url from yaml')
580-
# codecov.url = ccyaml.get('url')
581-
582-
# if ccyaml.get('slug'):
583-
# write(' Set slug from yaml')
584-
# codecov.slug = ccyaml.get('slug')
585-
586-
break
567+
yaml_location = re.search(
568+
r'\.?codecov\.ya?ml$',
569+
toc,
570+
re.M
571+
)
572+
if yaml_location:
573+
query['yaml'] = yaml_location.group()
574+
yaml = fopen(opj(os.getcwd(), query['yaml']))
575+
_token = re.search(
576+
r'token: (\'|\")?([0-9a-f]{8}(-?[0-9a-f]{4}){3}-?[0-9a-f]{12})',
577+
yaml,
578+
re.M
579+
)
580+
if _token:
581+
query['token'] = _token.groups()[1]
582+
583+
_slug = re.search(
584+
r'slug: (\'|\")?([\w\-\.\+]+\/[\w\-\.\+]+)',
585+
yaml,
586+
re.M
587+
)
588+
if _slug:
589+
query['slug'] = _slug.groups()[1]
590+
591+
assert query.get('job') or query.get('token'), "Missing repository upload token"
587592

588593
# Processing gcov
589594
# ---------------

0 commit comments

Comments
 (0)