Skip to content

Commit e736810

Browse files
committed
Enhance PR description validation for flexible category matching
This commit improves the `check_pr_description` function in `validate_pr_description.py` to allow for more flexible matching of changelog categories. The changes enable the use of `startswith` for category validation, accommodating variations in category names and ensuring better compatibility with existing categories. Key changes: - Introduced logic to check if the category starts with or is matched by valid categories. - Enhanced handling of "Not for changelog" categories to improve validation accuracy. - Updated error messages for clarity in case of invalid categories.
1 parent 1b3f781 commit e736810

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

.github/actions/validate_pr_description/validate_pr_description.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,36 @@ def check_pr_description(description, is_not_for_cl_valid=True) -> Tuple[bool, s
4747
return False, txt
4848

4949
category = categories[0]
50+
category_lower = category.lower()
5051

51-
if not any(category.lower() == valid_cat.lower() for valid_cat in ALL_CATEGORIES):
52+
# Check if category matches any valid category using startswith for flexible matching
53+
# This allows both "Not for changelog" and "Not for changelog (changelog entry is not required)"
54+
is_valid_category = False
55+
is_not_for_changelog = False
56+
57+
for valid_cat in ALL_CATEGORIES:
58+
valid_cat_lower = valid_cat.lower()
59+
# Extract base name (before parentheses) for flexible matching
60+
base_name = valid_cat_lower.split('(')[0].strip()
61+
62+
# Use startswith for all categories to support variants
63+
if category_lower.startswith(base_name) or base_name.startswith(category_lower):
64+
is_valid_category = True
65+
if valid_cat in NOT_FOR_CHANGELOG_CATEGORIES:
66+
is_not_for_changelog = True
67+
break
68+
69+
if not is_valid_category:
5270
txt = f"Invalid Changelog category: {category}"
5371
print(f"::warning::{txt}")
5472
return False, txt
5573

56-
if not is_not_for_cl_valid and any(category.lower() == cat.lower() for cat in NOT_FOR_CHANGELOG_CATEGORIES):
74+
if not is_not_for_cl_valid and is_not_for_changelog:
5775
txt = f"Category is not for changelog: {category}"
5876
print(f"::notice::{txt}")
5977
return False, txt
6078

61-
if not any(category.lower() == cat.lower() for cat in NOT_FOR_CHANGELOG_CATEGORIES):
79+
if not is_not_for_changelog:
6280
entry_section = re.search(r"### Changelog entry.*?\n(.*?)(\n###|$)", description, re.DOTALL)
6381
if not entry_section or len(entry_section.group(1).strip()) < 20:
6482
txt = "The changelog entry is less than 20 characters or missing."

0 commit comments

Comments
 (0)