Skip to content

Commit 2025dc4

Browse files
authored
feat: Check for BO4E-Schemas releases in bo4e repo versions (#92)
Exclude versions which are not present as release in repo `BO4E-Schemas`. (E.g. due to buggy CI)
1 parent bd43f1d commit 2025dc4

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/bo4e_cli/io/git.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Iterable, Literal
1111

1212
from bo4e_cli.io.console import CONSOLE
13+
from bo4e_cli.io.github import release_exists
1314
from bo4e_cli.models.version import Version
1415

1516

@@ -103,7 +104,12 @@ def get_ref(ref: str) -> tuple[Literal["tag", "branch", "commit"], str]:
103104

104105
# pylint: disable=too-many-branches
105106
def get_last_n_tags(
106-
n: int, *, ref: str = "main", exclude_candidates: bool = True, exclude_technical_bumps: bool = False
107+
n: int,
108+
*,
109+
ref: str = "main",
110+
exclude_candidates: bool = True,
111+
exclude_technical_bumps: bool = False,
112+
token: str | None = None,
107113
) -> Iterable[Version]:
108114
"""
109115
Get the last n tags in chronological descending order starting from `ref`.
@@ -161,6 +167,11 @@ def get_last_n_tags(
161167
):
162168
CONSOLE.print(f"Skipping version {version}", show_only_on_verbose=True)
163169
continue
170+
if not release_exists(version, token):
171+
CONSOLE.print(
172+
f"Skipping version {version} because it does not exist in the BO4E-Schemas repository.", style="warning"
173+
)
174+
continue
164175
CONSOLE.print(f"Yielding version {version}", show_only_on_verbose=True)
165176
yield version
166177
last_version = version

src/bo4e_cli/io/github.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ def get_versions(token: str | None) -> Iterable[Version]:
5656
pass
5757

5858

59+
def release_exists(version: Version, token: str | None) -> bool:
60+
"""
61+
Check if a release with the given version exists in the BO4E-Schemas repository.
62+
"""
63+
repo = get_source_repo(token)
64+
try:
65+
repo.get_release(str(version))
66+
return True
67+
except Exception: # pylint: disable=broad-exception-caught
68+
return False
69+
70+
5971
def get_schemas_meta_from_gh(version: Version, token: str | None) -> Schemas:
6072
"""
6173
Query the github tree api for a specific package and version.

unittests/cli/repo/test_versions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ def test_repo_last_versions_quiet_and_extra_flags(self) -> None:
2020

2121
version_tags = result.stdout.splitlines()
2222

23-
assert version_tags == ["v202401.7.1", "v202401.6.0", "v202401.5.0"]
23+
assert version_tags == ["v202401.7.0", "v202401.6.0", "v202401.5.0"]
2424

2525
def test_repo_last_versions_with_table(self) -> None:
2626
with change_cwd(BO4E_PYTHON_DIR):
2727
result = CliRunner().invoke(
2828
app,
2929
["-v", "repo", "versions", "-sr", "ff94097932d6e2e0aadb515281f53f3619a93486"],
30-
# This commit sha corresponds to the (wrongly tagged) 2025.0.0 tag.
31-
# For some reason, dependabot created this tag?
3230
catch_exceptions=False,
3331
# terminal_width=20,
3432
# It seems that the click runner constraints the terminal width + this option does not work.
@@ -41,7 +39,9 @@ def test_repo_last_versions_with_table(self) -> None:
4139
assert "Commit date" in result.stdout, f"Expected 'Commit date' in output, got: {result.stdout}"
4240

4341
# Check if the output contains some expected versions
44-
assert "v202401.7.1" in result.stdout, f"Expected 'v202401.7.1' in output, got: {result.stdout}"
42+
assert (
43+
"Skipping version v202401.7.1" in result.stdout
44+
), f"Expected 'v202401.7.1' in output, got: {result.stdout}"
4545
assert "v202401.7.0" in result.stdout
4646
assert "v202401.6.0" in result.stdout
4747
assert "v202401.5.0" in result.stdout

0 commit comments

Comments
 (0)