Skip to content

Commit

Permalink
Add redhat prefix check
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoerens committed Jul 10, 2024
1 parent 1b16c7f commit 34bd501
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions scripts/src/precheck/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class ReleaseTagError(SubmissionError):
pass


class ChartError(Exception):
pass


@dataclass
class Chart:
"""Represents a Helm Chart
Expand Down Expand Up @@ -80,6 +84,17 @@ def register_chart_info(self, category, organization, name, version):
)
raise VersionError(msg)

# Red Hat charts must carry the Red Hat prefix.
if organization == "redhat":
if not name.startswith("redhat-"):
msg = f"[ERROR] Charts provided by Red Hat must have their name begin with the redhat- prefix. I.e. redhat-{name}"
raise ChartError(msg)

# Non Red Hat charts must not carry the Red Hat prefix.
if organization != "redhat" and name.startswith("redhat-"):
msg = f"[ERROR] The redhat- prefix is reserved for charts provided by Red Hat. Your chart: {name}"
raise ChartError(msg)

self.category = category
self.organization = organization
self.name = name
Expand Down
16 changes: 16 additions & 0 deletions scripts/src/precheck/submission_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,22 @@ class SubmissionInitScenario:
],
excepted_exception=pytest.raises(submission.VersionError),
),
# Invalid PR references a Chart from redhat without the "redhat-" prefix
SubmissionInitScenario(
api_url="https://api.github.com/repos/openshift-helm-charts/charts/pulls/103",
modified_files=[
f"charts/{expected_category}/redhat/{expected_name}/{expected_version}/report.yaml"
],
excepted_exception=pytest.raises(submission.ChartError),
),
# Invalid PR references a Chart with the "redhat-" prefix from another organization
SubmissionInitScenario(
api_url="https://api.github.com/repos/openshift-helm-charts/charts/pulls/103",
modified_files=[
f"charts/{expected_category}/{expected_organization}/redhat-{expected_name}/{expected_version}/report.yaml"
],
excepted_exception=pytest.raises(submission.ChartError),
),
]


Expand Down

0 comments on commit 34bd501

Please sign in to comment.