diff --git a/tools/auto_release_test_dashboard.py b/tools/auto_release_test_dashboard.py index 192a24b851c0..c65740bfab61 100644 --- a/tools/auto_release_test_dashboard.py +++ b/tools/auto_release_test_dashboard.py @@ -1,9 +1,13 @@ import json +import logging import os import pandas as pd import streamlit as st -from github import Github, Auth + +from oar.core.github_app import GitHubApp + +logger = logging.getLogger(__name__) # Define the github access variables repository_owner = 'openshift' @@ -11,15 +15,25 @@ directory_path = '_releases' branch_name = 'record' -# Read the GitHub token from a system environment variable -github_token = os.environ.get('GITHUB_TOKEN') -if not github_token: - st.warning("Oops, ENV VAR GITHUB_TOKEN NOT FOUND") +# Read the GitHub App credentials from environment variables +github_app_id = os.environ.get('GITHUB_APP_WRITER_ID') +github_app_private_key = os.environ.get('GITHUB_APP_WRITER_PRIVATE_KEY') +if not github_app_id or not github_app_private_key: + st.warning("Oops, ENV VAR GITHUB_APP_WRITER_ID or GITHUB_APP_WRITER_PRIVATE_KEY NOT FOUND") st.stop() - -# Create a GitHub instance with the token -gh = Github(auth=Auth.Token(github_token)) +# Create a GitHub instance with the App installation token +try: + gh = GitHubApp(github_app_id, github_app_private_key).client_for_repo( + repository_owner, repository_name) +except Exception: + logger.exception("Failed to initialize GitHub App client") + st.error( + "Failed to initialize GitHub App client. " + "Please check `GITHUB_APP_WRITER_ID` and `GITHUB_APP_WRITER_PRIVATE_KEY` " + "and verify the app is installed on `openshift/release-tests`." + ) + st.stop() # Get the repository object repo = gh.get_repo(f'{repository_owner}/{repository_name}')