first time successful run
This commit is contained in:
@ -161,11 +161,47 @@ def get_github_prs(url, headers, org, repo):
|
||||
break
|
||||
return(pullrequests)
|
||||
|
||||
def get_failed_gh_commits(pulls, url, org, repo, headers):
|
||||
failed_commits = []
|
||||
for pull in pulls:
|
||||
try:
|
||||
req_url = url + 'repos/' + org + '/' + repo['name'] + '/commits/' + pull['head']['sha'] + '/check-runs'
|
||||
res_sta = requests.request('GET', url=req_url, headers=headers)
|
||||
if res_sta.json():
|
||||
if len(res_sta.json()['check_runs']) != 0:
|
||||
if res_sta.json()['check_runs'][0]['conclusion'] == 'failure':
|
||||
failed_commits.append({
|
||||
'url': pull['html_url'],
|
||||
'status': res_sta.json()['check_runs'][0]['conclusion'],
|
||||
'target_url': res_sta.json()['check_runs'][0]['details_url'],
|
||||
'created_at': pull['created_at'],
|
||||
'updated_at': res_sta.json()['check_runs'][0]['completed_at']
|
||||
})
|
||||
continue
|
||||
else:
|
||||
failed_commits.append({
|
||||
'url': pull['html_url'],
|
||||
'status': 'undefined',
|
||||
'target_url': 'undefined',
|
||||
'created_at': pull['created_at'],
|
||||
'updated_at': pull['updated_at']
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
print("An error has occured: " + str(e))
|
||||
print("The request status is: " + str(res_sta.status_code) + " | " + str(res_sta.reason))
|
||||
print(json.dumps(res_sta.json()))
|
||||
exit()
|
||||
break
|
||||
return(failed_commits)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
args = get_args()
|
||||
|
||||
failed_commits = []
|
||||
|
||||
if args.debug:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
@ -185,21 +221,21 @@ def main():
|
||||
headers['accept'] = 'application/json'
|
||||
headers['Authorization'] = 'Bearer ' + args.token
|
||||
|
||||
|
||||
for org in args.orgs:
|
||||
repos = get_github_repos(url, headers, org)
|
||||
pulls = []
|
||||
for repo in repos:
|
||||
pulls.extend(get_github_prs(url, headers, org, repo['name']))
|
||||
# print(pulls)
|
||||
print(len(pulls))
|
||||
|
||||
|
||||
pulls = get_github_prs(url, headers, org, repo['name'])
|
||||
if pulls:
|
||||
commits = get_failed_gh_commits(
|
||||
pulls=pulls,
|
||||
url=url,
|
||||
org=org,
|
||||
repo=repo,
|
||||
headers=headers)
|
||||
failed_commits.extend(commits)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
print(json.dumps(failed_commits))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user