Skip to content

Commit 4533187

Browse files
charlesprostclaude
andcommitted
Accept 3-digit Jira fix version for pre-GA hotfix branches
When hotfix/X.Y.Z has no GA tag yet (hfrev == 0, target version ends in ".0"), the Jira project may not have an "X.Y.Z.0" release entry yet. Allow either the 4-digit form ("10.0.0.0") OR the 3-digit base ("10.0.0") to satisfy the fix-version check. Once the GA tag is pushed, hfrev advances to 1, the target becomes "10.0.0.1", and only that exact 4-digit version is accepted again — matching the existing post-GA behaviour. Also update the incorrect_fix_version.md template: the condition now checks whether the last expected version has 4 digits (covers both pre-GA with two alternatives and post-GA with one), replacing the prior "length == 1" check that would miss the pre-GA two-version case. Add bert_e/tests/unit/test_jira.py with 13 unit tests covering: - pre-GA: 4-digit accepted, 3-digit accepted, wrong/missing rejected - post-GA: correct hfrev accepted, 3-digit base and wrong hfrev rejected - dev-branch: existing behaviour unchanged Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3f1c9a1 commit 4533187

3 files changed

Lines changed: 133 additions & 4 deletions

File tree

bert_e/templates/incorrect_fix_version.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ The `Fix Version/s` in issue {{ issue.key }} contains:
1313
* *None*
1414
{% endfor %}
1515

16-
{% if expect_versions|length == 1 and expect_versions[0].split('.')|length == 4 %}
17-
Considering where you are trying to merge, I expected to find at least:
16+
{% if expect_versions and expect_versions[-1].split('.')|length == 4 %}
17+
Considering where you are trying to merge, I expected to find at least one of:
1818
{% else %}
1919
Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:
2020
{% endif %}

bert_e/tests/unit/test_jira.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
"""Unit tests for check_fix_versions in jira.py.
2+
3+
Covers the pre-GA hotfix dual-acceptance rule:
4+
- When the hotfix branch has no GA tag yet (hfrev == 0 → target ends
5+
in ".0"), both the 4-digit form ("10.0.0.0") AND the 3-digit base
6+
("10.0.0") must be accepted.
7+
- Once the GA tag is pushed (hfrev advances to 1 → target becomes
8+
"10.0.0.1"), only the exact 4-digit version is accepted again.
9+
"""
10+
import pytest
11+
from types import SimpleNamespace
12+
13+
from bert_e import exceptions
14+
from bert_e.workflow.gitwaterflow.jira import check_fix_versions
15+
16+
17+
def _make_issue(*version_names):
18+
versions = [SimpleNamespace(name=v) for v in version_names]
19+
return SimpleNamespace(
20+
key='TEST-00001',
21+
fields=SimpleNamespace(fixVersions=versions),
22+
)
23+
24+
25+
def _make_job(*target_versions):
26+
cascade = SimpleNamespace(target_versions=list(target_versions))
27+
git = SimpleNamespace(cascade=cascade)
28+
return SimpleNamespace(git=git, active_options=[])
29+
30+
31+
# ---------------------------------------------------------------------------
32+
# Pre-GA hotfix: target ends in ".0" (hfrev == 0, no GA tag yet)
33+
# ---------------------------------------------------------------------------
34+
35+
def test_pre_ga_hotfix_accepts_four_digit_version():
36+
"""Jira with '10.0.0.0' is accepted for pre-GA hotfix/10.0.0."""
37+
check_fix_versions(_make_job('10.0.0.0'), _make_issue('10.0.0.0'))
38+
39+
40+
def test_pre_ga_hotfix_accepts_three_digit_version():
41+
"""Jira with '10.0.0' is accepted for pre-GA hotfix/10.0.0 (no GA tag)."""
42+
check_fix_versions(_make_job('10.0.0.0'), _make_issue('10.0.0'))
43+
44+
45+
def test_pre_ga_hotfix_accepts_three_digit_among_others():
46+
"""Jira with '10.0.0' among other versions is still accepted."""
47+
check_fix_versions(
48+
_make_job('10.0.0.0'),
49+
_make_issue('9.5.3', '10.0.0', '11.0.0'),
50+
)
51+
52+
53+
def test_pre_ga_hotfix_rejects_wrong_version():
54+
"""Unrelated version is rejected for pre-GA hotfix/10.0.0."""
55+
with pytest.raises(exceptions.IncorrectFixVersion):
56+
check_fix_versions(_make_job('10.0.0.0'), _make_issue('9.5.0'))
57+
58+
59+
def test_pre_ga_hotfix_rejects_empty_versions():
60+
"""No fix version in Jira is rejected for pre-GA hotfix/10.0.0."""
61+
with pytest.raises(exceptions.IncorrectFixVersion):
62+
check_fix_versions(_make_job('10.0.0.0'), _make_issue())
63+
64+
65+
def test_pre_ga_hotfix_rejects_next_micro():
66+
"""'10.0.1' is not a valid substitute for pre-GA '10.0.0.0'."""
67+
with pytest.raises(exceptions.IncorrectFixVersion):
68+
check_fix_versions(_make_job('10.0.0.0'), _make_issue('10.0.1'))
69+
70+
71+
# ---------------------------------------------------------------------------
72+
# Post-GA hotfix: target does NOT end in ".0" (hfrev >= 1, GA tag exists)
73+
# ---------------------------------------------------------------------------
74+
75+
def test_post_ga_hotfix_accepts_correct_4digit():
76+
"""'10.0.0.1' in Jira is accepted for post-GA hotfix (hfrev=1)."""
77+
check_fix_versions(_make_job('10.0.0.1'), _make_issue('10.0.0.1'))
78+
79+
80+
def test_post_ga_hotfix_rejects_3digit_base():
81+
"""'10.0.0' is NOT accepted once GA tag exists (target is '10.0.0.1')."""
82+
with pytest.raises(exceptions.IncorrectFixVersion):
83+
check_fix_versions(_make_job('10.0.0.1'), _make_issue('10.0.0'))
84+
85+
86+
def test_post_ga_hotfix_rejects_pre_ga_4digit():
87+
"""'10.0.0.0' is NOT accepted once GA tag exists (target is '10.0.0.1')."""
88+
with pytest.raises(exceptions.IncorrectFixVersion):
89+
check_fix_versions(_make_job('10.0.0.1'), _make_issue('10.0.0.0'))
90+
91+
92+
def test_post_ga_second_hotfix():
93+
"""'10.0.0.2' in Jira is accepted for second post-GA hotfix (hfrev=2)."""
94+
check_fix_versions(_make_job('10.0.0.2'), _make_issue('10.0.0.2'))
95+
96+
97+
def test_post_ga_hotfix_rejects_lower_hfrev():
98+
"""'10.0.0.1' is NOT accepted when target is '10.0.0.2'."""
99+
with pytest.raises(exceptions.IncorrectFixVersion):
100+
check_fix_versions(_make_job('10.0.0.2'), _make_issue('10.0.0.1'))
101+
102+
103+
# ---------------------------------------------------------------------------
104+
# Regular dev-branch PR (not hotfix) — pre-existing behaviour unchanged
105+
# ---------------------------------------------------------------------------
106+
107+
def test_dev_branch_accepts_matching_versions():
108+
"""Standard 3-digit dev-branch version check still works."""
109+
check_fix_versions(
110+
_make_job('4.3.19', '5.1.4'),
111+
_make_issue('4.3.19', '5.1.4'),
112+
)
113+
114+
115+
def test_dev_branch_rejects_mismatch():
116+
"""Wrong versions for a dev-branch PR are still rejected."""
117+
with pytest.raises(exceptions.IncorrectFixVersion):
118+
check_fix_versions(
119+
_make_job('4.3.19', '5.1.4'),
120+
_make_issue('4.3.18', '5.1.4'),
121+
)

bert_e/workflow/gitwaterflow/jira.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,19 @@ def check_fix_versions(job, issue):
165165
hf_target = target_version
166166

167167
if hf_target:
168-
if hf_target not in issue_versions:
168+
# Pre-GA: the hotfix branch has no tag yet (hfrev == 0 → target ends
169+
# in ".0"). The Jira project may not have a ".0" release entry yet,
170+
# so also accept the 3-digit base version (e.g. "10.0.0" for "10.0.0.0").
171+
# Once the GA tag is pushed hfrev advances to 1, the target becomes
172+
# "10.0.0.1", and only that exact version is accepted again.
173+
accepted = {hf_target}
174+
if hf_target.endswith('.0'):
175+
accepted.add(hf_target[:-2])
176+
if not (accepted & issue_versions):
169177
raise exceptions.IncorrectFixVersion(
170178
issue=issue,
171179
issue_versions=sorted(issue_versions),
172-
expect_versions=sorted(expected_versions),
180+
expect_versions=sorted(accepted),
173181
active_options=job.active_options
174182
)
175183
elif checked_versions != expected_versions:

0 commit comments

Comments
 (0)