Skip to content

Commit

Permalink
feat: add test for dependabot extra configuration at env level
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardojdsilva87 committed Nov 18, 2024
1 parent 9b8c2fd commit c535ab6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ maven:
password: "${{secrets.password}}"
```
The principal key of each configuration need to match the package managers that the [script is looking for](https://github.com/github/evergreen/blob/main/dependabot_file.py#L78).
The principal key of each configuration need to match the package managers that the [script is looking for](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem).
The `dependabot.yaml` created file will look like the following with the `registries:` key added:

Expand Down
4 changes: 4 additions & 0 deletions env.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ def get_env_vars(
labels_list = [label.lower().strip() for label in labels_str.split(",")]

dependabot_config_file = os.getenv("DEPENDABOT_CONFIG_FILE")
if dependabot_config_file and not os.path.exists(dependabot_config_file):
raise ValueError(
f"No dependabot extra configuration found. Please create one in {dependabot_config_file}"
)

return (
organization,
Expand Down
20 changes: 20 additions & 0 deletions test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,26 @@ def test_get_env_vars_project_id_not_a_number(self):
"PROJECT_ID environment variable is not numeric",
)

@patch.dict(
os.environ,
{
"ORGANIZATION": "my_organization",
"GH_TOKEN": "my_token",
"SCHEDULE": "weekly",
"DEPENDABOT_CONFIG_FILE": "config.yaml",
},
clear=True,
)
def test_get_env_vars_with_dependabot_config_file_set_but_not_found(self):
"""Test that no dependabot file configuration is present and the DEPENDABOT_CONFIG_FILE is set"""
with self.assertRaises(ValueError) as context_manager:
get_env_vars(True)
the_exception = context_manager.exception
self.assertEqual(
str(the_exception),
"No dependabot extra configuration found. Please create one in config.yaml",
)


if __name__ == "__main__":
unittest.main()

0 comments on commit c535ab6

Please sign in to comment.