Skip to content

Commit

Permalink
Generate a valid empty index when none is found
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Goerens <[email protected]>
  • Loading branch information
mgoerens authored and github-actions[bot] committed Sep 27, 2024
1 parent 3ac6de4 commit 1aefc2a
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions scripts/src/submission/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,37 @@ def get_file_type(file_path):
return "unknwown", None


def download_index_data(repository, branch="gh_pages"):
"""Download the helm repository index"""
r = requests.get(
f"https://raw.githubusercontent.com/{repository}/{branch}/index.yaml"
)
def download_index_data(
repository: str, branch: str = "gh-pages", ignore_missing: bool = False
) -> dict:
"""Download the helm repository index
Args:
repository (str): Name of the GitHub repository to download the index file from.
(e.g. "openshift-helm-charts/charts")
branch (str): GitHub branch to download the index file from. Defaults to "gh-pages".
ignore_missing (bool): Set to True to return a valid empty index, in the case the
download of index.yaml fails.
Returns:
dict: The helm repository index
Raise:
HelmIndexError if the download fails. If not on the production repository, doesn't raise
and returns an empty index file instead.
HelmIndexError if the index file is not valid YAML.
"""
index_url = f"https://raw.githubusercontent.com/{repository}/{branch}/index.yaml"
r = requests.get(index_url)

if r.status_code == 200:
data = yaml.load(r.text, Loader=Loader)
data = {"apiVersion": "v1", "entries": {}}
if r.status_code != 200 and ignore_missing:
raise HelmIndexError(f"Error retrieving index file at {index_url}")
else:
data = {}
try:
data = yaml.load(r.text, Loader=Loader)
except yaml.YAMLError as e:
raise HelmIndexError(f"Error parsing index file at {index_url}") from e

return data

0 comments on commit 1aefc2a

Please sign in to comment.