-
Notifications
You must be signed in to change notification settings - Fork 10
/
request.py
31 lines (23 loc) · 1.06 KB
/
request.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#Function: this is a python script that checks to see if coverage reported from the Codecov API is accurate
import requests
import time
import os
payload = {'token': os.environ['API_KEY']}
link = 'https://codecov.io/api/gh/codecov/cpp-11-standard'
print("Waiting 60 seconds for report to upload before pinging API...")
# Sleep 60 seconds
time.sleep(60)
print("Pinging Codecov's API..")
# Get latest coverage data
all_data = requests.get(link, params=payload).json()
commit_data = all_data['commits'][0]
coverage_percentage = commit_data['totals']['c']
print("Ensuring coverage percentage is accurate...")
# Result should return 62.50000 as its coverage metric
expected_coverage = os.environ['EXPECTED_COVERAGE']
if(coverage_percentage == expected_coverage):
print("Success! Codecov's API returned the correct coverage percentage, "+ expected_coverage)
exit(0)
else:
print("Whoops, something is wrong D: Codecov did not return the correct coverage percentage. Coverage percentage should be "+expected_coverage+" but Codecov returned "+coverage_percentage)
exit(1)