Skip to content

Commit

Permalink
fix: error handling for unsupported package ecosystem and a test to c…
Browse files Browse the repository at this point in the history
…over it

Signed-off-by: Zack Koppert <[email protected]>
  • Loading branch information
zkoppert committed May 31, 2024
1 parent 8fcccd2 commit 92c8ef0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions env.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ def parse_repo_specific_exemptions(repo_specific_exemptions_str: str) -> dict:
): # Account for final ; in the repo_specific_exemptions_str
continue
repo, ecosystems = exemption.split(":")
for ecosystem in ecosystems.split(","):
if ecosystem not in [
"bundler",
"npm",
"pip",
"cargo",
"docker",
"gomod",
"composer",
"mix",
"github-actions",
"nuget",
"terraform",
]:
raise ValueError(
"REPO_SPECIFIC_EXEMPTIONS environment variable not formatted correctly. Unrecognized package-ecosystem."
)
exemptions_dict[repo.strip()] = [
ecosystem.strip() for ecosystem in ecosystems.split(",")
]
Expand Down
28 changes: 28 additions & 0 deletions test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,34 @@ def test_get_env_vars_repo_specific_exemptions_improper_format(self):
"REPO_SPECIFIC_EXEMPTIONS environment variable not formatted correctly",
)

@patch.dict(
os.environ,
{
"REPOSITORY": "org/repo1,org2/repo2",
"GH_TOKEN": "my_token",
"EXEMPT_REPOS": "repo4,repo5",
"TYPE": "pull",
"TITLE": "Dependabot Alert custom title",
"BODY": "Dependabot custom body",
"CREATED_AFTER_DATE": "2023-01-01",
"DRY_RUN": "true",
"COMMIT_MESSAGE": "Create dependabot configuration",
"PROJECT_ID": "123",
"GROUP_DEPENDENCIES": "false",
"REPO_SPECIFIC_EXEMPTIONS": "org1/repo1:snap;org2/repo2:docker",
},
clear=True,
)
def test_get_env_vars_repo_specific_exemptions_unsupported_ecosystem(self):
"""Test that REPO_SPECIFIC_EXEMPTIONS is handled correctly when unsupported ecosystem is provided"""
with self.assertRaises(ValueError) as cm:
get_env_vars(True)
the_exception = cm.exception
self.assertEqual(
str(the_exception),
"REPO_SPECIFIC_EXEMPTIONS environment variable not formatted correctly. Unrecognized package-ecosystem.",
)

@patch.dict(
os.environ,
{
Expand Down

0 comments on commit 92c8ef0

Please sign in to comment.