Skip to content

Commit

Permalink
Merge pull request #232 from github/no-newline-in-existing-config
Browse files Browse the repository at this point in the history
fix: ensure existing dependabot configs without end of file newlines get processed properly
  • Loading branch information
zkoppert authored Sep 26, 2024
2 parents 105daf8 + ed2fb73 commit b50bd41
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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

0 comments on commit b50bd41

Please sign in to comment.