Skip to content

Commit 1b3f781

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 37a5b33 commit 1b3f781

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
@@ -183,8 +183,18 @@ def generate_backport_table(pr_number: int, app_domain: str) -> str:
183183

184184
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}) |")
185185

186-
# Generate URL for backporting multiple branches
187-
all_branches = ",".join(branches)
186+
# Collect all unique branches from all entries (each entry may contain multiple branches separated by comma)
187+
all_unique_branches = set()
188+
for branch_entry in branches:
189+
# Split by comma and strip whitespace
190+
branch_list = [b.strip() for b in branch_entry.split(',')]
191+
all_unique_branches.update(branch_list)
192+
193+
# Sort for consistent output
194+
all_unique_branches_sorted = sorted(all_unique_branches)
195+
all_branches = ",".join(all_unique_branches_sorted)
196+
197+
# Generate URL for backporting all unique branches
188198
params_multiple = {
189199
"owner": owner,
190200
"repo": repo,
@@ -204,7 +214,7 @@ def generate_backport_table(pr_number: int, app_domain: str) -> str:
204214
table += "|----------|\n"
205215
table += "\n".join(rows)
206216
table += "\n\n"
207-
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})"
217+
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})"
208218
return table
209219

210220
def get_legend() -> str:

0 commit comments

Comments
 (0)