Skip to content

Commit 92f4c63

Browse files
committed
feat(update): for a given blueprint name only update the one with the higher index in the list
1 parent f3c9e06 commit 92f4c63

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/ops2deb/updater.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,23 @@ async def _find_latest_versions(
210210

211211
def find_latest_releases(
212212
configuration: Configuration,
213-
blueprints: list[Blueprint],
214213
fetcher: Fetcher,
215214
skip_names: list[str] | None,
216215
only_names: list[str] | None,
217216
) -> Tuple[list[LatestRelease], list[Ops2debError]]:
218-
blueprints = [b for b in blueprints if b.fetch is not None]
217+
blueprints = [b for b in configuration.blueprints if b.fetch is not None]
219218
if skip_names:
220219
blueprints = [b for b in blueprints if b.name not in skip_names]
221220
if only_names:
222221
blueprints = [b for b in blueprints if b.name in only_names]
223222

223+
# when multiple blueprints have the same name, only look for new releases for the
224+
# last one in the list
225+
blueprints_by_name: dict[str, Blueprint] = {}
226+
for blueprint in blueprints:
227+
blueprints_by_name[blueprint.name] = blueprint
228+
blueprints = list(blueprints_by_name.values())
229+
224230
# find new releases for the selected list of blueprints
225231
releases, errors = asyncio.run(_find_latest_versions(blueprints))
226232

@@ -303,9 +309,8 @@ def update(
303309
max_versions: int = 1,
304310
) -> None:
305311
logger.title("Looking for new releases...")
306-
blueprints = list(configuration.blueprints)
307312
releases, errors = find_latest_releases(
308-
configuration, blueprints, fetcher, skip_names, only_names
313+
configuration, fetcher, skip_names, only_names
309314
)
310315

311316
summary: list[str] = []

tests/test_ops2deb.py

+26
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,32 @@ def test_update__should_not_produce_configuration_files_that_dont_pass_format_co
890890
assert result_format.exit_code == 0
891891

892892

893+
def test_update___only_looks_for_updates_for_the_last_blueprint_when_multiple_blueprints_have_the_same_name( # noqa: E501
894+
call_ops2deb, configuration_paths
895+
):
896+
# Given
897+
configuration = """\
898+
- name: great-app
899+
version: 1.0.0
900+
summary: great package
901+
fetch: http://testserver/{{version}}/great-app.tar.gz
902+
903+
- name: great-app
904+
version: 1.0.1
905+
summary: super package
906+
fetch: http://testserver/{{version}}/great-app.tar.gz
907+
"""
908+
909+
# When
910+
result = call_ops2deb("update", "--only", "great-app", configurations=[configuration])
911+
912+
# Then
913+
raw_blueprints = load_configuration_file(configuration_paths[0]).raw_blueprints
914+
assert result.exit_code == 0
915+
assert raw_blueprints[0]["version"] == "1.0.0"
916+
assert raw_blueprints[1]["version"] == "1.1.1"
917+
918+
893919
def test__format_should_be_idempotent(call_ops2deb, configuration_paths):
894920
# Given
895921
configuration_0 = """

0 commit comments

Comments
 (0)