Skip to content

Commit a71ad61

Browse files
(PTFE-2505) Manage two digit branch without tag
1 parent 4c452cb commit a71ad61

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

bert_e/tests/test_bert_e.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,20 @@ def test_branch_cascade_hotfix_and_development_three_digit(self):
547547
fixver = ['4.3.18.1']
548548
self.finalize_cascade(branches, tags, destination, fixver)
549549

550+
def test_branch_cascade_mixed_versions_0(self):
551+
"""Test cascade with mix of 2-digit and 3-digit development branches"""
552+
destination = 'development/5.1'
553+
branches = OrderedDict({
554+
1: {'name': 'development/4.3.17', 'ignore': True},
555+
2: {'name': 'development/4.3', 'ignore': True},
556+
3: {'name': 'development/5.1.0', 'ignore': True},
557+
4: {'name': 'development/5.1', 'ignore': False},
558+
5: {'name': 'development/10', 'ignore': False}
559+
})
560+
tags = ['4.3.16', '4.3.18']
561+
fixver = ['5.1.1', '10.0.0']
562+
self.finalize_cascade(branches, tags, destination, fixver)
563+
550564
def test_branch_cascade_mixed_versions(self):
551565
"""Test cascade with mix of 2-digit and 3-digit development branches"""
552566
destination = 'development/5.1'
@@ -555,7 +569,7 @@ def test_branch_cascade_mixed_versions(self):
555569
2: {'name': 'development/4.3', 'ignore': True},
556570
3: {'name': 'development/5.1.8', 'ignore': True},
557571
4: {'name': 'development/5.1', 'ignore': False},
558-
5: {'name': 'development/10.0', 'ignore': False}
572+
5: {'name': 'development/10', 'ignore': False}
559573
})
560574
tags = ['4.3.16', '4.3.18', '5.1.3', '5.1.7']
561575
fixver = ['5.1.9', '10.0.0']

bert_e/workflow/gitwaterflow/branches.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ def build(self, repo):
377377
except errors.UnrecognizedBranchPattern:
378378
continue
379379
self._add_branch(branch)
380-
381380
self.finalize()
382381

383382
@property
@@ -858,7 +857,6 @@ def build(self, repo, dst_branch=None):
858857
self._cascade = OrderedDict(
859858
sorted(self._cascade.items(), key=cmp_to_key(compare_branches))
860859
)
861-
862860
self._update_major_versions()
863861
if dst_branch:
864862
self.finalize(dst_branch)
@@ -979,6 +977,7 @@ def update_versions(self, tag):
979977
if dev_branch:
980978
# Only update if tag matches X.Y
981979
# And is not a three-digit dev branch
980+
982981
if dev_branch.major == major and dev_branch.minor == minor:
983982
# Exclude tags whose micro is already
984983
# A three-digit dev branch for this X.Y
@@ -989,7 +988,6 @@ def update_versions(self, tag):
989988

990989
three_digit_micros = set(k[2] for k in three_digit_keys)
991990
next_micro = micro + 1
992-
993991
while next_micro in three_digit_micros:
994992
next_micro += 1
995993
if (not hasattr(dev_branch, '_next_micro') or
@@ -1042,21 +1040,37 @@ def _update_major_versions(self):
10421040
"""
10431041
for version_tuple, branch_set in self._cascade.items():
10441042
# Only process major-only branches (tuples where minor is None)
1045-
if len(version_tuple) < 2 or version_tuple[1] is not None:
1043+
if len(version_tuple) < 2:
10461044
continue
1047-
major_branch: DevelopmentBranch = branch_set[DevelopmentBranch]
1048-
major = version_tuple[0]
1049-
1050-
# Find all minor versions for this major
1051-
minors = [
1052-
version_tuple[1] for version_tuple in self._cascade.keys()
1053-
if (len(version_tuple) >= 2 and
1054-
version_tuple[0] == major and
1055-
version_tuple[1] is not None)
1056-
]
1057-
minors.append(major_branch.latest_minor)
1045+
if len(version_tuple) == 2 and version_tuple[1] is None:
1046+
major_branch: DevelopmentBranch = branch_set[DevelopmentBranch]
1047+
major = version_tuple[0]
1048+
1049+
# Find all minor versions for this major
1050+
minors = [
1051+
version_tuple[1] for version_tuple in self._cascade.keys()
1052+
if (len(version_tuple) >= 2 and
1053+
version_tuple[0] == major and
1054+
version_tuple[1] is not None)
1055+
]
1056+
minors.append(major_branch.latest_minor)
1057+
1058+
major_branch.latest_minor = max(minors)
1059+
elif len(version_tuple) == 2 and version_tuple[1] is not None:
1060+
minor_branch: DevelopmentBranch = branch_set[DevelopmentBranch]
1061+
minor = version_tuple[1]
1062+
major = version_tuple[0]
1063+
1064+
# Find all micros versions for this minor
1065+
micros = [
1066+
version_tuple[2] for version_tuple in self._cascade.keys()
1067+
if (len(version_tuple) >= 3 and
1068+
version_tuple[0] == major and
1069+
version_tuple[1] == minor and
1070+
version_tuple[2] is not None)
1071+
]
10581072

1059-
major_branch.latest_minor = max(minors)
1073+
minor_branch.latest_micro = max(micros)
10601074

10611075
def _set_target_versions(self, dst_branch):
10621076
"""Compute list of expected Jira FixVersion/s.
@@ -1091,7 +1105,10 @@ def _set_target_versions(self, dst_branch):
10911105
self.target_versions.append(version_current)
10921106
next_micro = dev_branch.micro
10931107
else:
1094-
next_micro = 0
1108+
if hasattr(dev_branch, 'latest_micro'):
1109+
next_micro = dev_branch.latest_micro + 1
1110+
else:
1111+
next_micro = 0
10951112
version_str = '%d.%d.%d' % (
10961113
dev_branch.major, dev_branch.minor, next_micro
10971114
)

0 commit comments

Comments
 (0)