Skip to content

Commit

Permalink
chore: consolidate repetition into function
Browse files Browse the repository at this point in the history
Signed-off-by: Zack Koppert <[email protected]>
  • Loading branch information
zkoppert committed May 26, 2024
1 parent 43e40b3 commit 386e781
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions evergreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,11 @@ def main(): # pragma: no cover
print("Skipping " + repo.full_name + " (visibility-filtered)")
continue
existing_config = None
try:
existing_config = repo.file_contents(".github/dependabot.yml")
if existing_config.size > 0:
if not update_existing:
print(
"Skipping "
+ repo.full_name
+ " (dependabot file already exists)"
)
continue
except github3.exceptions.NotFoundError:
pass
try:
existing_config = repo.file_contents(".github/dependabot.yaml")
if existing_config.size > 0:
if not update_existing:
print(
"Skipping "
+ repo.full_name
+ " (dependabot file already exists)"
)
continue
except github3.exceptions.NotFoundError:
pass
filename_list = [".github/dependabot.yml", ".github/dependabot.yaml"]
for filename in filename_list:
existing_config = check_existing_config(repo, filename, update_existing)
if existing_config:
break

if created_after_date and is_repo_created_date_before(
repo.created_at, created_after_date
Expand Down Expand Up @@ -211,6 +192,24 @@ def is_dependabot_security_updates_enabled(owner, repo, access_token):
return False


def check_existing_config(repo, filename, update_existing):
"""
Check if the dependabot file already exists in the
repository and return the existing config if it does
"""
try:
existing_config = repo.file_contents(filename)
if existing_config.size > 0:
if not update_existing:
print(
"Skipping " + repo.full_name + " (dependabot file already exists)"
)
return None
except github3.exceptions.NotFoundError:
pass
return existing_config


def enable_dependabot_security_updates(owner, repo, access_token):
"""Enable Dependabot security updates at the /repos/:owner/:repo/automated-security-fixes endpoint using the requests library"""
url = f"https://api.github.com/repos/{owner}/{repo}/automated-security-fixes"
Expand Down

0 comments on commit 386e781

Please sign in to comment.