Skip to content

Commit

Permalink
Generate a valid empty index when none is found (#389)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Goerens <mgoerens@redhat.com>
  • Loading branch information
mgoerens authored Oct 1, 2024
1 parent 5f24f4f commit 1126fc6
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 @@ -575,15 +575,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 not 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 1126fc6

Please sign in to comment.