From eb391855966588af4a0eb8989315d30ef777d270 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sat, 7 Dec 2024 02:51:41 +0100 Subject: [PATCH 1/2] fix: Workflow path is enumerated, but does not exist any longer When workflow definition files are deleted, but had runs in the past, the GitHub API still enumerates them as if they would exist. In reality, however, they are gone. This detail, however, only becomes apparent when accessing the workflow, so this patch compensates for corresponding 404 errors returned by the API. --- gha_cli/cli.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gha_cli/cli.py b/gha_cli/cli.py index 6320747..baf9c96 100755 --- a/gha_cli/cli.py +++ b/gha_cli/cli.py @@ -118,9 +118,12 @@ def get_repo_workflow_names(self, repo_name: str) -> Dict[str, str]: workflow_paths = self._get_github_workflow_filenames(repo_name) res = dict() for path in workflow_paths: - content = self._get_workflow_file_content(repo_name, path) - yaml_content = yaml.load(content, Loader=yaml.CLoader) - res[path] = yaml_content.get('name', path) + try: + content = self._get_workflow_file_content(repo_name, path) + yaml_content = yaml.load(content, Loader=yaml.CLoader) + res[path] = yaml_content.get('name', path) + except FileNotFoundError as ex: + logging.warning(ex) return res def update_actions( @@ -192,7 +195,10 @@ def _get_workflow_file_content(self, repo_name: str, workflow_path: str) -> Unio f'f{workflow_path} not found in workflows for repository {repo_name}, ' f'possible values: {workflow_paths}', err=True) repo = self.client.get_repo(repo_name) - workflow_content = repo.get_contents(workflow_path) + try: + workflow_content = repo.get_contents(workflow_path) + except UnknownObjectException: + raise FileNotFoundError(f'Workflow not found in repository: {repo_name}, path: {workflow_path}') return workflow_content.decoded_content From 62ccb227859fa4bd5a23d24c6bb8da99b147e825 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sat, 7 Dec 2024 02:51:50 +0100 Subject: [PATCH 2/2] chore: Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0d006d4..c19c627 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea .venv dist +__pycache__