diff --git a/tools/attention_list.py b/tools/attention_list.py index 40a06eb3..3cc0c32e 100644 --- a/tools/attention_list.py +++ b/tools/attention_list.py @@ -27,7 +27,7 @@ class FailedPR: self.target_url = target_url self.created_at = created_at self.updated_at = updated_at - + def to_json(self): return json.dumps(self.__dict__) @@ -76,7 +76,7 @@ def get_args(): help='Git hoster to be queried for failed Pull Requests.\n' 'Default: [github, gitea].' ) - return(parser.parse_args()) + return parser.parse_args() def get_gitea_repos(url, headers, gitea_org): repositories = [] @@ -84,7 +84,7 @@ def get_gitea_repos(url, headers, gitea_org): while True: try: - req_url = (url + 'orgs/' + gitea_org + + req_url = (url + 'orgs/' + gitea_org + '/repos?limit=50&page=' + str(i)) res = requests.request('GET', url=req_url, headers=headers) i+=1 @@ -96,16 +96,16 @@ def get_gitea_repos(url, headers, gitea_org): break except Exception as e: print("An error has occured: " + str(e)) - print("The request status is: " + str(res.status_code) + + print("The request status is: " + str(res.status_code) + " | " + str(res.reason)) break - return(repositories) + return repositories def get_gitea_prs(url, headers, gitea_org, repo): pullrequests = [] try: - req_url = (url + 'repos/' + gitea_org + '/' + req_url = (url + 'repos/' + gitea_org + '/' + repo + '/pulls?state=open') res = requests.request('GET', url=req_url, headers=headers) if res.json(): @@ -113,15 +113,15 @@ def get_gitea_prs(url, headers, gitea_org, repo): pullrequests.append(pr) except Exception as e: print("An error has occured: " + str(e)) - print("The request status is: " + str(res.status_code) + + print("The request status is: " + str(res.status_code) + " | " + str(res.reason)) exit() - return(pullrequests) + return pullrequests def get_failed_gitea_commits(pull, url, gitea_org, repo, headers): failed_commits = [] try: - req_url = (url + 'repos/' + gitea_org + '/' + repo['name'] + + req_url = (url + 'repos/' + gitea_org + '/' + repo['name'] + '/commits/' + pull['head']['ref'] + '/statuses?limit=1') res_sta = requests.request('GET', url=req_url, headers=headers) if res_sta.json(): @@ -138,11 +138,11 @@ def get_failed_gitea_commits(pull, url, gitea_org, repo, headers): except Exception as e: print("An error has occured: " + str(e)) - print("The request status is: " + str(res_sta.status_code) + + print("The request status is: " + str(res_sta.status_code) + " | " + str(res_sta.reason)) print(json.dumps(res_sta.json())) exit() - return(failed_commits) + return failed_commits def get_github_repos(url, headers, gh_org): repositories = [] @@ -161,10 +161,10 @@ def get_github_repos(url, headers, gh_org): break except Exception as e: print("An error has occured: " + str(e)) - print("The request status is: " + str(res.status_code) + + print("The request status is: " + str(res.status_code) + " | " + str(res.reason)) break - return(repositories) + return repositories def get_github_prs(url, headers, gh_org, repo): pullrequests = [] @@ -184,15 +184,15 @@ def get_github_prs(url, headers, gh_org, repo): break except Exception as e: print("An error has occured: " + str(e)) - print("The request status is: " + str(res.status_code) + + print("The request status is: " + str(res.status_code) + " | " + str(res.reason)) break - return(pullrequests) + return pullrequests def get_failed_gh_commits(pull, url, gh_org, repo, headers): failed_commits = [] try: - req_url = (url + 'repos/' + gh_org + '/' + repo['name'] + + req_url = (url + 'repos/' + gh_org + '/' + repo['name'] + '/commits/' + pull['head']['sha'] + '/check-runs') res_sta = requests.request('GET', url=req_url, headers=headers) if res_sta.json(): @@ -226,21 +226,18 @@ def get_failed_gh_commits(pull, url, gh_org, repo, headers): " | " + str(res_sta.reason)) print(json.dumps(res_sta.json())) exit() - return(failed_commits) - + return failed_commits def main(): - args = get_args() - failed_commits = [] if args.debug: logging.basicConfig(level=logging.DEBUG) - + for h in args.hoster: if h == 'gitea': - + headers = {} headers['accept'] = 'application/json' if not args.gitea_token: @@ -272,7 +269,7 @@ def main(): headers=headers ) failed_commits.extend(commits) - + elif h == 'github': url = 'https://api.github.com/' headers = {} @@ -309,4 +306,4 @@ def main(): print(o.to_json()) if __name__ == '__main__': - main() \ No newline at end of file + main()