Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: maintain dependabot config filename for existing configs #150

Merged
merged 8 commits into from
May 30, 2024
19 changes: 15 additions & 4 deletions evergreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ def main(): # pragma: no cover
continue
existing_config = None
filename_list = [".github/dependabot.yml", ".github/dependabot.yaml"]
dependabot_filename_to_use = None
for filename in filename_list:
existing_config = check_existing_config(repo, filename, update_existing)
if existing_config:
dependabot_filename_to_use = filename
break

if created_after_date and is_repo_created_date_before(
Expand Down Expand Up @@ -130,7 +132,9 @@ def main(): # pragma: no cover
body_issue = (
body
+ "\n\n```yaml\n"
+ "# .github/dependabot.yml\n"
+ "# "
+ dependabot_filename_to_use
+ "\n"
+ dependabot_file
+ "\n```"
)
Expand All @@ -151,7 +155,12 @@ def main(): # pragma: no cover
count_eligible += 1
try:
pull = commit_changes(
title, body, repo, dependabot_file, commit_message
title,
body,
repo,
dependabot_file,
commit_message,
dependabot_filename_to_use,
)
print("\tCreated pull request " + pull.html_url)
if project_id:
Expand Down Expand Up @@ -273,7 +282,9 @@ def check_pending_issues_for_duplicates(title, repo) -> bool:
return skip


def commit_changes(title, body, repo, dependabot_file, message):
def commit_changes(
title, body, repo, dependabot_file, message, dependabot_filename="dependabot.yml"
):
"""Commit the changes to the repo and open a pull reques and return the pull request object"""
default_branch = repo.default_branch
# Get latest commit sha from default branch
Expand All @@ -282,7 +293,7 @@ def commit_changes(title, body, repo, dependabot_file, message):
branch_name = "dependabot-" + str(uuid.uuid4())
repo.create_ref(front_matter + branch_name, default_branch_commit)
repo.create_file(
path=".github/dependabot.yaml",
path=".github/" + dependabot_filename,
zkoppert marked this conversation as resolved.
Show resolved Hide resolved
message=message,
content=dependabot_file.encode(), # Convert to bytes object
branch=branch_name,
Expand Down
14 changes: 11 additions & 3 deletions test_evergreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,28 @@ def test_commit_changes(self, mock_uuid):
mock_repo.create_ref.return_value = True
mock_repo.create_file.return_value = True
mock_repo.create_pull.return_value = "MockPullRequest"
dependabot_file_name = "dependabot.yml"

title = "Test Title"
body = "Test Body"
dependabot_file = 'dependencies:\n - package_manager: "python"\n directory: "/"\n update_schedule: "live"'
branch_name = "dependabot-12345678-1234-5678-1234-567812345678"
commit_message = "Create dependabot.yaml"
result = commit_changes(title, body, mock_repo, dependabot_file, commit_message)
commit_message = "Create " + dependabot_file_name
result = commit_changes(
title,
body,
mock_repo,
dependabot_file,
commit_message,
dependabot_file_name,
)

# Assert that the methods were called with the correct arguments
mock_repo.create_ref.assert_called_once_with(
f"refs/heads/{branch_name}", "abc123"
)
mock_repo.create_file.assert_called_once_with(
path=".github/dependabot.yaml",
path=".github/" + dependabot_file_name,
zkoppert marked this conversation as resolved.
Show resolved Hide resolved
message=commit_message,
content=dependabot_file.encode(),
branch=branch_name,
Expand Down