From 5466630a414480668ff12017db7bc99f583eac6a Mon Sep 17 00:00:00 2001 From: tischrei Date: Wed, 21 Sep 2022 12:46:33 +0000 Subject: [PATCH] first time successful run --- tools/attention_list.py | 56 +++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/tools/attention_list.py b/tools/attention_list.py index 353aaa38..3d559f9a 100644 --- a/tools/attention_list.py +++ b/tools/attention_list.py @@ -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() \ No newline at end of file