From 6e240235f9dbc3235e053ff9f8dc4705d3157b73 Mon Sep 17 00:00:00 2001 From: jmeridth Date: Wed, 24 Apr 2024 22:26:47 -0500 Subject: [PATCH] chore(deps): update dependabot config to include pr prefixes Closes #104 Closes #105 Add commit-message.prefix config option to dependabot so that dependabot pull request titles pass our new PR Title Linting workflow - [x] include current dependency updates (black and mypy) - [x] setup test env to ignore .env local file contents (idempotent tests ftw) Signed-off-by: jmeridth --- .github/dependabot.yml | 6 +++++ env.py | 11 +++++---- requirements-test.txt | 4 ++-- test_env.py | 53 +++++++++++++++++++++--------------------- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 50ee96a..9db8279 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,11 +5,17 @@ updates: directory: "/" schedule: interval: "daily" + commit-message: + prefix: "chore(deps)" - package-ecosystem: "github-actions" directory: "/" schedule: interval: "daily" + commit-message: + prefix: "chore(deps)" - package-ecosystem: "docker" directory: "/" schedule: interval: "daily" + commit-message: + prefix: "chore(deps)" diff --git a/env.py b/env.py index aa8ac94..99f0c7c 100644 --- a/env.py +++ b/env.py @@ -43,7 +43,9 @@ def get_int_env_var(env_var_name: str) -> int | None: return None -def get_env_vars() -> tuple[ +def get_env_vars( + test: bool = False, +) -> tuple[ str | None, list[str], int | None, @@ -92,9 +94,10 @@ def get_env_vars() -> tuple[ enable_security_updates (bool): Whether to enable security updates in target repositories exempt_ecosystems_list (list[str]): A list of package ecosystems to exempt from the action """ - # Load from .env file if it exists - dotenv_path = join(dirname(__file__), ".env") - load_dotenv(dotenv_path) + if not test: + # Load from .env file if it exists + dotenv_path = join(dirname(__file__), ".env") + load_dotenv(dotenv_path) organization = os.getenv("ORGANIZATION") repositories_str = os.getenv("REPOSITORY") diff --git a/requirements-test.txt b/requirements-test.txt index 26b8c03..d0e4e85 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,6 +1,6 @@ -black==24.4.0 +black==24.4.1 flake8==7.0.0 -mypy==1.9.0 +mypy==1.10.0 mypy-extensions==1.0.0 pylint==3.1.0 pytest==8.1.1 diff --git a/test_env.py b/test_env.py index d00885b..40241bc 100644 --- a/test_env.py +++ b/test_env.py @@ -12,20 +12,21 @@ class TestEnv(unittest.TestCase): def setUp(self): env_keys = [ - "ORGANIZATION", + "BATCH_SIZE", + "BODY", + "COMMIT_MESSAGE", + "CREATED_AFTER_DATE", "EXEMPT_REPOS", "GH_APP_ID", "GH_APP_INSTALLATION_ID", "GH_APP_PRIVATE_KEY", "GH_TOKEN", "GH_ENTERPRISE_URL", - "TYPE", - "TITLE", - "BODY", - "CREATED_AFTER_DATE", - "COMMIT_MESSAGE", - "PROJECT_ID", "GROUP_DEPENDENCIES", + "ORGANIZATION", + "PROJECT_ID", + "TITLE", + "TYPE", ] for key in env_keys: if key in os.environ: @@ -70,7 +71,7 @@ def test_get_env_vars_with_org(self): True, # enable_security_updates [], # exempt_ecosystems ) - result = get_env_vars() + result = get_env_vars(True) self.assertEqual(result, expected_result) @patch.dict( @@ -114,7 +115,7 @@ def test_get_env_vars_with_repos(self): True, # enable_security_updates [], # exempt_ecosystems ) - result = get_env_vars() + result = get_env_vars(True) self.assertEqual(result, expected_result) @patch.dict( @@ -150,14 +151,14 @@ def test_get_env_vars_optional_values(self): True, # enable_security_updates [], # exempt_ecosystems ) - result = get_env_vars() + result = get_env_vars(True) self.assertEqual(result, expected_result) @patch.dict(os.environ, {}) def test_get_env_vars_missing_org_or_repo(self): """Test that an error is raised if required environment variables are not set""" with self.assertRaises(ValueError) as cm: - get_env_vars() + get_env_vars(True) the_exception = cm.exception self.assertEqual( str(the_exception), @@ -202,7 +203,7 @@ def test_get_env_vars_auth_with_github_app_installation(self): True, # enable_security_updates [], # exempt_ecosystems ) - result = get_env_vars() + result = get_env_vars(True) self.assertEqual(result, expected_result) @patch.dict( @@ -220,7 +221,7 @@ def test_get_env_vars_missing_at_least_one_auth(self): """Test that an error is raised if at least one type of authentication required environment variables are not set""" with self.assertRaises(ValueError) as cm: - get_env_vars() + get_env_vars(True) the_exception = cm.exception self.assertEqual( str(the_exception), @@ -262,7 +263,7 @@ def test_get_env_vars_with_repos_no_dry_run(self): True, # enable_security_updates [], # exempt_ecosystems ) - result = get_env_vars() + result = get_env_vars(True) self.assertEqual(result, expected_result) @patch.dict( @@ -300,7 +301,7 @@ def test_get_env_vars_with_repos_disabled_security_updates(self): False, # enable_security_updates [], # exempt_ecosystems ) - result = get_env_vars() + result = get_env_vars(True) self.assertEqual(result, expected_result) @patch.dict( @@ -339,7 +340,7 @@ def test_get_env_vars_with_repos_filter_visibility_multiple_values(self): False, # enable_security_updates [], # exempt_ecosystems ) - result = get_env_vars() + result = get_env_vars(True) self.assertEqual(result, expected_result) @patch.dict( @@ -378,7 +379,7 @@ def test_get_env_vars_with_repos_filter_visibility_single_value(self): False, # enable_security_updates [], # exempt_ecosystems ) - result = get_env_vars() + result = get_env_vars(True) self.assertEqual(result, expected_result) @patch.dict( @@ -394,7 +395,7 @@ def test_get_env_vars_with_repos_filter_visibility_single_value(self): def test_get_env_vars_with_repos_filter_visibility_invalid_single_value(self): """Test that filter_visibility throws an error when an invalid value is provided""" with self.assertRaises(ValueError): - get_env_vars() + get_env_vars(True) @patch.dict( os.environ, @@ -409,7 +410,7 @@ def test_get_env_vars_with_repos_filter_visibility_invalid_single_value(self): def test_get_env_vars_with_repos_filter_visibility_invalid_multiple_value(self): """Test that filter_visibility throws an error when an invalid value is provided""" with self.assertRaises(ValueError): - get_env_vars() + get_env_vars(True) @patch.dict( os.environ, @@ -447,7 +448,7 @@ def test_get_env_vars_with_repos_filter_visibility_no_duplicates(self): False, # enable_security_updates [], # exempt_ecosystems ) - result = get_env_vars() + result = get_env_vars(True) self.assertEqual(result, expected_result) @patch.dict( @@ -487,7 +488,7 @@ def test_get_env_vars_with_repos_exempt_ecosystems(self): False, # enable_security_updates ["gomod", "docker"], # exempt_ecosystems ) - result = get_env_vars() + result = get_env_vars(True) self.assertEqual(result, expected_result) @patch.dict( @@ -526,7 +527,7 @@ def test_get_env_vars_with_no_batch_size(self): False, # enable_security_updates [], # exempt_ecosystems ) - result = get_env_vars() + result = get_env_vars(True) self.assertEqual(result, expected_result) @patch.dict( @@ -566,7 +567,7 @@ def test_get_env_vars_with_batch_size(self): False, # enable_security_updates [], # exempt_ecosystems ) - result = get_env_vars() + result = get_env_vars(True) self.assertEqual(result, expected_result) @patch.dict( @@ -583,7 +584,7 @@ def test_get_env_vars_with_batch_size(self): def test_get_env_vars_with_invalid_batch_size_int(self): """Test that invalid batch size with negative 1 throws exception""" with self.assertRaises(ValueError): - get_env_vars() + get_env_vars(True) @patch.dict( os.environ, @@ -599,7 +600,7 @@ def test_get_env_vars_with_invalid_batch_size_int(self): def test_get_env_vars_with_invalid_batch_size_str(self): """Test that invalid batch size of string throws exception""" with self.assertRaises(ValueError): - get_env_vars() + get_env_vars(True) @patch.dict( os.environ, @@ -613,7 +614,7 @@ def test_get_env_vars_with_invalid_batch_size_str(self): def test_get_env_vars_with_badly_formatted_created_after_date(self): """Test that""" with self.assertRaises(ValueError) as context_manager: - get_env_vars() + get_env_vars(True) the_exception = context_manager.exception self.assertEqual( str(the_exception),