Skip to content

Commit cc94ffb

Browse files
committed
Refactor backport table generation in PR description validation
This commit enhances the `generate_backport_table` function in `validate_pr_description.py` to collect and sort unique branches from the input. The changes ensure that the backporting URL is generated for all unique branches, improving the accuracy and clarity of the backport table in PR descriptions. Key changes: - Updated logic to collect unique branches from multiple entries. - Sorted branches for consistent output. - Modified the backport button label for clarity.
1 parent 0bc0853 commit cc94ffb

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

.github/actions/validate_pr_description/validate_pr_description.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,18 @@ def generate_backport_table(pr_number: int, app_domain: str) -> str:
191191

192192
rows.append(f"| [![▶ {branch}](https://img.shields.io/badge/%E2%96%B6_{branch.replace('-', '_')}-4caf50?style=flat-square)]({url}) [![⚙️](https://img.shields.io/badge/%E2%9A%99%EF%B8%8F-ff9800?style=flat-square)]({url_ui}) |")
193193

194-
# Generate URL for backporting multiple branches
195-
all_branches = ",".join(branches)
194+
# Collect all unique branches from all entries (each entry may contain multiple branches separated by comma)
195+
all_unique_branches = set()
196+
for branch_entry in branches:
197+
# Split by comma and strip whitespace
198+
branch_list = [b.strip() for b in branch_entry.split(',')]
199+
all_unique_branches.update(branch_list)
200+
201+
# Sort for consistent output
202+
all_unique_branches_sorted = sorted(all_unique_branches)
203+
all_branches = ",".join(all_unique_branches_sorted)
204+
205+
# Generate URL for backporting all unique branches
196206
params_multiple = {
197207
"owner": owner,
198208
"repo": repo,
@@ -212,7 +222,7 @@ def generate_backport_table(pr_number: int, app_domain: str) -> str:
212222
table += "|----------|\n"
213223
table += "\n".join(rows)
214224
table += "\n\n"
215-
table += f"[![⚙️ Backport multiple branches](https://img.shields.io/badge/%E2%9A%99%EF%B8%8F_Backport_multiple_branches-2196F3?style=flat-square)]({url_multiple_ui})"
225+
table += f"[![⚙️ Backport (custom)](https://img.shields.io/badge/%E2%9A%99%EF%B8%8F_Backport_%28custom%29-2196F3?style=flat-square)]({url_multiple_ui})"
216226
return table
217227

218228
def get_legend() -> str:

0 commit comments

Comments
 (0)