8000 add -X s3 to disable direct to s3 · Kami/codecov-python@6591da4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6591da4

Browse files
committed
add -X s3 to disable direct to s3
1 parent 0452255 commit 6591da4

File tree

1 file changed

+45
-40
lines changed

1 file changed

+45
-40
lines changed

codecov/__init__.py

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -716,46 +716,51 @@ def main(*argv, **kwargs):
716716
trys = 0
717717
while trys < 3:
718718
trys += 1
719-
try:
720-
write(' Pinging Codecov...')
721-
res = requests.post('%s/upload/v4?%s' % (codecov.url, urlargs),
722-
verify=codecov.cacert,
723-
headers={'Accept': 'text/plain',
724-
'X-Reduced-Redundancy': 'false'})
725-
if res.status_code in (400, 406):
726-
raise Exception(res.text)
727-
728-
elif res.status_code < 500:
729-
assert res.status_code == 200
730-
res = res.text.strip().split()
731-
result, upload_url = res[0], res[1]
732-
733-
# Handle reports encoding for Python 2 and 3
734-
if not isinstance(reports, bytes):
735-
reports = reports.encode('utf-8')
736-
737-
write(' Uploading to S3...')
738-
s3 = requests.put(upload_url, data=reports,
739-
headers={'Content-Type': 'text/plain',
740-
'x-amz-acl': 'public-read'})
741-
s3.raise_for_status()
742-
assert s3.status_code == 200
743-
write(' ' + result)
744-
break
745-
746-
except AssertionError:
747-
write(' Direct to s3 failed. Using backup v2 endpoint.')
748-
write(' Uploading to Codecov...')
749-
# just incase, try traditional upload
750-
res = requests.post('%s/upload/v2?%s' % (codecov.url, urlargs),
751-
verify=codecov.cacert,
752-
data='\n'.join((reports, s3.reason if s3 else '', s3.text if s3 else '')),
753-
headers={"Accept": "text/plain"})
754-
if res.status_code < 500:
755-
write(' ' + res.text)
756-
res.raise_for_status()
757-
result = res.text
758-
return
719+
if 's3' not in codecov.disable:
720+
try:
721+
write(' Pinging Codecov...')
722+
res = requests.post('%s/upload/v4?%s' % (codecov.url, urlargs),
723+
verify=codecov.cacert,
724+
headers={'Accept': 'text/plain',
725+
'X-Reduced-Redundancy': 'false'})
726+
if res.status_code in (400, 406):
727+
raise Exception(res.text)
728+
729+
elif res.status_code < 500:
730+
assert res.status_code == 200
731+
res = res.text.strip().split()
732+
result, upload_url = res[0], res[1]
733+
734+
# Handle reports encoding for Python 2 and 3
735+
if not isinstance(reports, bytes):
736+
reports = reports.encode('utf-8')
737+
738+
write(' Uploading to S3...')
739+
s3 = requests.put(upload_url, data=reports,
740+
headers={'Content-Type': 'text/plain',
741+
'x-amz-acl': 'public-read'})
742+
s3.raise_for_status()
743+
assert s3.status_code == 200
744+
write(' ' + result)
745+
break
746+
else:
747+
# try again
748+
continue
749+
750+
except AssertionError:
751+
write(' Direct to s3 failed. Using backup v2 endpoint.')
752+
753+
write(' Uploading to Codecov...')
754+
# just incase, try traditional upload
755+
res = requests.post('%s/upload/v2?%s' % (codecov.url, urlargs),
756+
verify=codecov.cacert,
757+
data='\n'.join((reports, s3.reason if s3 else '', s3.text if s3 else '')),
758+
headers={"Accept": "text/plain"})
759+
if res.status_code < 500:
760+
write(' ' + res.text)
761+
res.raise_for_status()
762+
result = res.text
763+
return
759764

760765
write(' Retrying... in %ds' % (trys * 30))
761766
380F sleep(trys * 30)

0 commit comments

Comments
 (0)
0