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: ensure existing dependabot configs without end of file newlines get processed properly #232

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dependabot_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def build_dependabot_file(
try:
if repo.file_contents(file):
package_managers_found[manager] = True
# If the last thing in the file is not a newline,
# add one before adding a new language config to the file
if dependabot_file and dependabot_file[-1] != "\n":
dependabot_file += "\n"
dependabot_file += make_dependabot_config(
manager, group_dependencies, indent, schedule, schedule_day
)
Expand Down
31 changes: 31 additions & 0 deletions test_dependabot_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@ def test_build_dependabot_file_with_2_space_indent_existing_config_bundler_with_
)
self.assertEqual(result, expected_result)

def test_build_dependabot_file_with_2_space_indent_existing_config_bundler_with_update_and_no_newline(
self,
):
"""Test that the dependabot.yml file is built correctly with bundler"""
repo = MagicMock()
repo.file_contents.side_effect = lambda f, filename="Gemfile": f == filename

# expected_result maintains existing ecosystem with custom configuration
# and adds new ecosystem
expected_result = """---
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "chore(deps)"
- package-ecosystem: 'bundler'
directory: '/'
schedule:
interval: 'weekly'
"""
existing_config = MagicMock()
existing_config.decoded = b'---\nversion: 2\nupdates:\n - package-ecosystem: "pip"\n directory: "/"\n\
schedule:\n interval: "weekly"\n commit-message:\n prefix: "chore(deps)"'
result = build_dependabot_file(
repo, False, [], {}, existing_config, "weekly", ""
)
self.assertEqual(result, expected_result)

def test_build_dependabot_file_with_weird_space_indent_existing_config_bundler_with_update(
self,
):
Expand Down
Loading