Skip to content

Commit e8a50b4

Browse files
committed
fix: prevent duplicate backports in add_backports_to_body
Update the set of existing PRs during the insertion loop to detect and skip duplicates in the same input list (including those that normalize to the same reference).
1 parent 15029e5 commit e8a50b4

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

tests/tools/private/release/release_issue_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22

33
from tools.private.release.release_issue import (
4+
add_backports_to_body,
45
format_metadata_line,
56
parse_metadata_line,
67
)
@@ -65,6 +66,36 @@ def test_format_metadata_line(self):
6566
expected = "- [ ] Tag Final"
6667
self.assertEqual(format_metadata_line(False, "Tag Final", {}), expected)
6768

69+
def test_add_backports_to_body(self):
70+
body = """
71+
## Checklist
72+
- [ ] Prepare Release
73+
- [ ] Create Release branch
74+
- [ ] Tag Final
75+
76+
## Backports
77+
- [ ] #123 | status=done
78+
"""
79+
items = [
80+
{"ref": "124"},
81+
{"ref": "#124"},
82+
{"ref": "125"},
83+
{"ref": "#123"},
84+
]
85+
updated_body = add_backports_to_body(body, items)
86+
expected_body = """
87+
## Checklist
88+
- [ ] Prepare Release
89+
- [ ] Create Release branch
90+
- [ ] Tag Final
91+
92+
## Backports
93+
- [ ] #123 | status=done
94+
- [ ] #124
95+
- [ ] #125
96+
"""
97+
self.assertEqual(updated_body.strip(), expected_body.strip())
98+
6899

69100
if __name__ == "__main__":
70101
unittest.main()

tools/private/release/release_issue.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def add_backports_to_body(body: str, items: list[dict]) -> str:
278278
if ref in existing_refs:
279279
print(f"PR {ref} is already in the backports list. Skipping.")
280280
continue
281+
existing_refs.add(ref)
281282

282283
metadata = item.get("metadata", {})
283284
new_lines.append(

0 commit comments

Comments
 (0)