-
Notifications
You must be signed in to change notification settings - Fork 15
/
request.py
29 lines (22 loc) · 1.09 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
# 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://api.codecov.io/api/v2/github/codecov/repos/java-standard/commits'
print("Waiting 60 seconds for report to upload before pinging API...")
# night night
time.sleep(60)
print("Pinging Codecov's API..")
#get latest coverage data
all_data = requests.get(link, params=payload).json()
commit_data = all_data['results'][0]
coverage_percentage = commit_data['totals']['coverage']
print("Ensuring coverage percentage is accurate...")
# result should return 85.71429 as its coverage metric
if(str(coverage_percentage) == os.environ['EXPECTED_COVERAGE']):
print("Success! Codecov's API returned the correct coverage percentage, " + os.environ['EXPECTED_COVERAGE'])
exit(0)
else:
print("Whoops, something is wrong D: Codecov did not return the correct coverage percentage. Coverage percentage should be " + os.environ['EXPECTED_COVERAGE']+" but Codecov returned "+ str(coverage_percentage))
exit(1)