Skip to content

Commit 8d70331

Browse files
authored
Merge pull request #378 from github/copilot/fix-377
fix: Fix registries deletion when adding new ecosystems to dependabot.yml
2 parents 4229a2d + 3e09c1c commit 8d70331

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

dependabot_file.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# Define data structure for dependabot.yaml
1212
data = {
1313
"version": 2,
14-
"registries": {},
1514
"updates": [],
1615
}
1716

@@ -60,8 +59,6 @@ def make_dependabot_config(
6059
dependabot_config["updates"][-1].update(
6160
{"registries": [SingleQuotedScalarString(ecosystem)]}
6261
)
63-
else:
64-
dependabot_config.pop("registries", None)
6562

6663
if schedule_day:
6764
dependabot_config["updates"][-1].update(

test_dependabot_file.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,56 @@ def test_build_dependabot_file_with_labels(self):
819819
)
820820
self.assertEqual(result, expected_result)
821821

822+
def test_build_dependabot_file_preserves_existing_registries(self):
823+
"""Test that existing registries are preserved when adding new ecosystems"""
824+
repo = MagicMock()
825+
repo.file_contents.side_effect = lambda filename: filename == "Gemfile"
826+
827+
# Create existing config with registries but no bundler ecosystem
828+
existing_config = MagicMock()
829+
existing_config.content = base64.b64encode(
830+
b"""
831+
version: 2
832+
registries:
833+
gradle-artifactory:
834+
type: maven-repository
835+
url: https://acme.jfrog.io/artifactory/my-gradle-registry
836+
username: octocat
837+
password: ${{secrets.MY_ARTIFACTORY_PASSWORD}}
838+
updates:
839+
- package-ecosystem: "npm"
840+
directory: "/"
841+
schedule:
842+
interval: "weekly"
843+
"""
844+
)
845+
846+
expected_result = yaml.load(
847+
b"""
848+
version: 2
849+
registries:
850+
gradle-artifactory:
851+
type: maven-repository
852+
url: https://acme.jfrog.io/artifactory/my-gradle-registry
853+
username: octocat
854+
password: ${{secrets.MY_ARTIFACTORY_PASSWORD}}
855+
updates:
856+
- package-ecosystem: "npm"
857+
directory: "/"
858+
schedule:
859+
interval: "weekly"
860+
- package-ecosystem: 'bundler'
861+
directory: '/'
862+
schedule:
863+
interval: 'weekly'
864+
"""
865+
)
866+
867+
result = build_dependabot_file(
868+
repo, False, [], {}, existing_config, "weekly", "", [], None
869+
)
870+
self.assertEqual(result, expected_result)
871+
822872

823873
if __name__ == "__main__":
824874
unittest.main()

0 commit comments

Comments
 (0)