Skip to content

Instantly share code, notes, and snippets.

@AaronMT
Created February 9, 2024 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AaronMT/1ddbe460680c6c51bc5b0d83e4525d7b to your computer and use it in GitHub Desktop.
Save AaronMT/1ddbe460680c6c51bc5b0d83e4525d7b to your computer and use it in GitHub Desktop.
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)
@AaronMT
Copy link
Author

AaronMT commented Feb 9, 2024

Pull Request by github-actions[bot] with failed checks: https://github.com/mozilla-mobile/firefox-android/pull/5535
Failed Check: complete-push-3 - https://github.com/mozilla-mobile/firefox-android/runs/21409788667
Failed Check: complete-push - https://github.com/mozilla-mobile/firefox-android/runs/21409788642
Failed Check: ui-test-apk-fenix-arm-debug - https://github.com/mozilla-mobile/firefox-android/runs/21409788463

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment