Skip to content

Commit 9e1ea3a

Browse files
committed
fix: update_existing logic
Signed-off-by: Zack Koppert <[email protected]>
1 parent ff2f3ff commit 9e1ea3a

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

evergreen.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,19 @@ def main(): # pragma: no cover
8383
filename_list = [".github/dependabot.yaml", ".github/dependabot.yml"]
8484
dependabot_filename_to_use = filename_list[0] # Default to the first filename
8585
for filename in filename_list:
86-
existing_config = check_existing_config(repo, filename, update_existing)
86+
existing_config = check_existing_config(repo, filename)
8787
if existing_config:
8888
dependabot_filename_to_use = filename
8989
break
9090

91+
if existing_config and not update_existing:
92+
print(
93+
"Skipping "
94+
+ repo.full_name
95+
+ " (dependabot file already exists and update_existing is False)"
96+
)
97+
continue
98+
9199
if created_after_date and is_repo_created_date_before(
92100
repo.created_at, created_after_date
93101
):
@@ -207,15 +215,14 @@ def is_dependabot_security_updates_enabled(owner, repo, access_token):
207215
return False
208216

209217

210-
def check_existing_config(repo, filename, update_existing):
218+
def check_existing_config(repo, filename):
211219
"""
212220
Check if the dependabot file already exists in the
213221
repository and return the existing config if it does
214222
215223
Args:
216224
repo (github3.repos.repo.Repository): The repository to check
217225
filename (str): The dependabot configuration filename to check
218-
update_existing (bool): Whether to update existing dependabot configuration files
219226
220227
Returns:
221228
github3.repos.contents.Contents | None: The existing config if it exists, otherwise None
@@ -224,14 +231,10 @@ def check_existing_config(repo, filename, update_existing):
224231
try:
225232
existing_config = repo.file_contents(filename)
226233
if existing_config.size > 0:
227-
if not update_existing:
228-
print(
229-
"Skipping " + repo.full_name + " (dependabot file already exists)"
230-
)
231-
return None
234+
return existing_config
232235
except github3.exceptions.NotFoundError:
233236
pass
234-
return existing_config
237+
return None
235238

236239

237240
def enable_dependabot_security_updates(owner, repo, access_token):

test_evergreen.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ def test_check_existing_config_with_existing_config(self):
662662
filename = "dependabot.yaml"
663663
mock_repo.file_contents.return_value.size = 5
664664

665-
result = check_existing_config(mock_repo, filename, True)
665+
result = check_existing_config(mock_repo, filename)
666666

667667
self.assertIsNotNone(result)
668668

@@ -676,21 +676,7 @@ def test_check_existing_config_without_existing_config(self):
676676
mock_response
677677
)
678678

679-
result = check_existing_config(mock_repo, "dependabot.yml", True)
680-
681-
self.assertIsNone(result)
682-
683-
def test_check_existing_config_with_existing_config_without_update_existing_set(
684-
self,
685-
):
686-
"""
687-
Test the case where there is an existing configuration but UPDATE_EXISTING is False
688-
"""
689-
mock_repo = MagicMock()
690-
filename = "dependabot.yaml"
691-
mock_repo.file_contents.return_value.size = 5
692-
693-
result = check_existing_config(mock_repo, filename, False)
679+
result = check_existing_config(mock_repo, "dependabot.yml")
694680

695681
self.assertIsNone(result)
696682

0 commit comments

Comments
 (0)