Skip to content

Commit 6f5d2f5

Browse files
authored
fix: Workflow path is enumerated, but does not exist any longer (#4)
* 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. * chore: Update .gitignore
1 parent c721146 commit 6f5d2f5

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
.venv
33
dist
4+
__pycache__

gha_cli/cli.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ def get_repo_workflow_names(self, repo_name: str) -> Dict[str, str]:
118118
workflow_paths = self._get_github_workflow_filenames(repo_name)
119119
res = dict()
120120
for path in workflow_paths:
121-
content = self._get_workflow_file_content(repo_name, path)
122-
yaml_content = yaml.load(content, Loader=yaml.CLoader)
123-
res[path] = yaml_content.get('name', path)
121+
try:
122+
content = self._get_workflow_file_content(repo_name, path)
123+
yaml_content = yaml.load(content, Loader=yaml.CLoader)
124+
res[path] = yaml_content.get('name', path)
125+
except FileNotFoundError as ex:
126+
logging.warning(ex)
124127
return res
125128

126129
def update_actions(
@@ -192,7 +195,10 @@ def _get_workflow_file_content(self, repo_name: str, workflow_path: str) -> Unio
192195
f'f{workflow_path} not found in workflows for repository {repo_name}, '
193196
f'possible values: {workflow_paths}', err=True)
194197
repo = self.client.get_repo(repo_name)
195-
workflow_content = repo.get_contents(workflow_path)
198+
try:
199+
workflow_content = repo.get_contents(workflow_path)
200+
except UnknownObjectException:
201+
raise FileNotFoundError(f'Workflow not found in repository: {repo_name}, path: {workflow_path}')
196202
return workflow_content.decoded_content
197203

198204

0 commit comments

Comments
 (0)