11import sys
22import re
33from typing import Tuple
4-
5- issue_patterns = [
6- r"https://github.com/ydb-platform/[a-z\-]+/issues/\d+" ,
7- r"https://st.yandex-team.ru/[a-zA-Z]+-\d+" ,
8- r"#\d+" ,
9- r"[a-zA-Z]+-\d+"
10- ]
11-
12- pull_request_template = """
13- ### Changelog entry <!-- a user-readable short description of the changes that goes to CHANGELOG.md and Release Notes -->
14-
15- ...
16-
17- ### Changelog category <!-- remove all except one -->
18-
19- * New feature
20- * Experimental feature
21- * Improvement
22- * Performance improvement
23- * User Interface
24- * Bugfix
25- * Backward incompatible change
26- * Documentation (changelog entry is not required)
27- * Not for changelog (changelog entry is not required)
28- """
4+ from pr_template import (
5+ ISSUE_PATTERNS ,
6+ PULL_REQUEST_TEMPLATE ,
7+ FOR_CHANGELOG_CATEGORIES ,
8+ NOT_FOR_CHANGELOG_CATEGORIES ,
9+ ALL_CATEGORIES
10+ )
2911
3012def validate_pr_description (description , is_not_for_cl_valid = True ) -> bool :
3113 try :
@@ -44,7 +26,7 @@ def check_pr_description(description, is_not_for_cl_valid=True) -> Tuple[bool, s
4426 if "### Changelog category" not in description and "### Changelog entry" not in description :
4527 return is_not_for_cl_valid , "Changelog category and entry sections are not found."
4628
47- if pull_request_template .strip () in description .strip ():
29+ if PULL_REQUEST_TEMPLATE .strip () in description .strip ():
4830 return is_not_for_cl_valid , "Pull request template as is."
4931
5032 # Extract changelog category section
@@ -62,34 +44,18 @@ def check_pr_description(description, is_not_for_cl_valid=True) -> Tuple[bool, s
6244 return False , txt
6345
6446 category = categories [0 ]
65- for_cl_categories = [
66- "New feature" ,
67- "Experimental feature" ,
68- "User Interface" ,
69- "Improvement" ,
70- "Performance improvement" ,
71- "Bugfix" ,
72- "Backward incompatible change"
73- ]
74-
75- not_for_cl_categories = [
76- "Documentation (changelog entry is not required)" ,
77- "Not for changelog (changelog entry is not required)"
78- ]
79-
80- valid_categories = for_cl_categories + not_for_cl_categories
81-
82- if not any (cat .startswith (category ) for cat in valid_categories ):
47+
48+ if not any (cat .startswith (category ) for cat in ALL_CATEGORIES ):
8349 txt = f"Invalid Changelog category: { category } "
8450 print (f"::warning::{ txt } " )
8551 return False , txt
8652
87- if not is_not_for_cl_valid and any (cat .startswith (category ) for cat in not_for_cl_categories ):
53+ if not is_not_for_cl_valid and any (cat .startswith (category ) for cat in NOT_FOR_CHANGELOG_CATEGORIES ):
8854 txt = f"Category is not for changelog: { category } "
8955 print (f"::notice::{ txt } " )
9056 return False , txt
9157
92- if not any (cat .startswith (category ) for cat in not_for_cl_categories ):
58+ if not any (cat .startswith (category ) for cat in NOT_FOR_CHANGELOG_CATEGORIES ):
9359 entry_section = re .search (r"### Changelog entry.*?\n(.*?)(\n###|$)" , description , re .DOTALL )
9460 if not entry_section or len (entry_section .group (1 ).strip ()) < 20 :
9561 txt = "The changelog entry is less than 20 characters or missing."
@@ -100,7 +66,7 @@ def check_pr_description(description, is_not_for_cl_valid=True) -> Tuple[bool, s
10066 def check_issue_pattern (issue_pattern ):
10167 return re .search (issue_pattern , description )
10268
103- if not any (check_issue_pattern (issue_pattern ) for issue_pattern in issue_patterns ):
69+ if not any (check_issue_pattern (issue_pattern ) for issue_pattern in ISSUE_PATTERNS ):
10470 txt = "Bugfix requires a linked issue in the changelog entry"
10571 print (f"::warning::{ txt } " )
10672 return False , txt
0 commit comments