Skip to content

Commit 506c5d5

Browse files
authored
Merge pull request #488 from shuofengzhang/trim-exemption-whitespace
fix: Trim whitespace in repo-specific exemptions
2 parents 64b5c97 + 2a9edc4 commit 506c5d5

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

env.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ def parse_repo_specific_exemptions(repo_specific_exemptions_str: str) -> dict:
7171
): # Account for final ; in the repo_specific_exemptions_str
7272
continue
7373
repo, ecosystems = exemption.split(":")
74+
cleaned_ecosystems = []
7475
for ecosystem in ecosystems.split(","):
76+
ecosystem = ecosystem.strip()
7577
if ecosystem not in [
7678
"bundler",
7779
"cargo",
@@ -88,9 +90,8 @@ def parse_repo_specific_exemptions(repo_specific_exemptions_str: str) -> dict:
8890
raise ValueError(
8991
"REPO_SPECIFIC_EXEMPTIONS environment variable not formatted correctly. Unrecognized package-ecosystem."
9092
)
91-
exemptions_dict[repo.strip()] = [
92-
ecosystem.strip() for ecosystem in ecosystems.split(",")
93-
]
93+
cleaned_ecosystems.append(ecosystem)
94+
exemptions_dict[repo.strip()] = cleaned_ecosystems
9495
return exemptions_dict
9596

9697

test_env.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,61 @@ def test_get_env_vars_with_org_and_repo_specific_exemptions(self):
156156
result = get_env_vars(True)
157157
self.assertEqual(result, expected_result)
158158

159+
@patch.dict(
160+
os.environ,
161+
{
162+
"ORGANIZATION": "my_organization",
163+
"EXEMPT_REPOS": "repo4,repo5",
164+
"GH_TOKEN": "my_token",
165+
"TYPE": "issue",
166+
"TITLE": "Dependabot Alert custom title",
167+
"BODY": "Dependabot custom body",
168+
"CREATED_AFTER_DATE": "2020-01-01",
169+
"COMMIT_MESSAGE": "Create dependabot configuration",
170+
"PROJECT_ID": "123",
171+
"GROUP_DEPENDENCIES": "false",
172+
"REPO_SPECIFIC_EXEMPTIONS": "repo1:gomod, docker;",
173+
},
174+
clear=True,
175+
)
176+
def test_get_env_vars_repo_specific_exemptions_trims_whitespace(self):
177+
"""Test that REPO_SPECIFIC_EXEMPTIONS trims whitespace in ecosystems."""
178+
expected_result = (
179+
"my_organization",
180+
[],
181+
"", # search_query
182+
None,
183+
None,
184+
b"",
185+
False,
186+
"my_token",
187+
"",
188+
["repo4", "repo5"],
189+
"issue",
190+
"Dependabot Alert custom title",
191+
"Dependabot custom body",
192+
"2020-01-01",
193+
False,
194+
"Create dependabot configuration",
195+
"123",
196+
False,
197+
["internal", "private", "public"],
198+
None, # batch_size
199+
True, # enable_security_updates
200+
[], # exempt_ecosystems
201+
False, # update_existing
202+
{
203+
"repo1": ["gomod", "docker"],
204+
}, # repo_specific_exemptions
205+
"weekly", # schedule
206+
"", # schedule_day
207+
None, # team_name
208+
[], # labels
209+
None,
210+
)
211+
result = get_env_vars(True)
212+
self.assertEqual(result, expected_result)
213+
159214
@patch.dict(
160215
os.environ,
161216
{

0 commit comments

Comments
 (0)