Created
February 9, 2024 18:23
-
-
Save AaronMT/1ddbe460680c6c51bc5b0d83e4525d7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN') | |
REPO_OWNER = "mozilla-mobile" | |
REPO_NAME = "firefox-android" | |
AUTHOR = "github-actions[bot]" | |
headers = { | |
"Authorization": f"token {GITHUB_TOKEN}", | |
"Accept": "application/vnd.github.v3+json" | |
} | |
def get_pull_requests_by_author(repo_owner, repo_name, author): | |
""" | |
Fetches pull requests from a GitHub repository filtered by the specified author | |
and checks for failed checks. | |
""" | |
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls" | |
response = requests.get(url, headers=headers) | |
if response.status_code == 200: | |
pull_requests = response.json() | |
for pr in pull_requests: | |
if pr['user']['login'].lower() == author.lower(): | |
# Get the status checks for the head commit of the pull request | |
check_runs_url = pr['head']['repo']['url'] + f"/commits/{pr['head']['sha']}/check-runs" | |
check_runs_response = requests.get(check_runs_url, headers=headers) | |
if check_runs_response.status_code == 200: | |
check_runs = check_runs_response.json()['check_runs'] | |
failed_checks = [check for check in check_runs if check['conclusion'] == 'failure'] | |
if failed_checks: | |
print(f"Pull Request by {author} with failed checks: {pr['html_url']}") | |
for check in failed_checks: | |
print(f"Failed Check: {check['name']} - {check['html_url']}") | |
else: | |
print(f"Failed to fetch pull requests. Status Code: {response.status_code}") | |
if __name__ == "__main__": | |
get_pull_requests_by_author(REPO_OWNER, REPO_NAME, AUTHOR) |
Author
AaronMT
commented
Feb 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment