1- """Subcommand to add PRs to the release tracking issue backports checklist."""
1+ import os
22
33from tools .private .release .gh import GitHub
4+ from tools .private .release .git import Git
45from tools .private .release .release_issue import (
6+ RELEASE_TITLE_RE ,
57 add_backports_to_body ,
68 add_rc_task_to_body ,
79 add_sync_changelog_task_to_body ,
10+ load_release_tracking_template ,
811 parse_checklist_state ,
912)
13+ from tools .private .release .utils import determine_next_version
1014
1115
1216class AddBackports :
1317 """Class to add PRs to the release tracking issue."""
1418
15- def __init__ (self , args , gh : GitHub ):
19+ def __init__ (self , args , gh : GitHub , git : Git | None = None ):
1620 self .args = args
1721 self .gh = gh
22+ self .git = git or Git (os .getcwd ())
1823
1924 def run (self ) -> int :
2025 """Executes the add-backports subcommand."""
@@ -28,21 +33,40 @@ def run(self) -> int:
2833 )
2934 try :
3035 open_issues = self .gh .get_open_tracking_issues ()
31- if not open_issues :
32- print ("Error: No open release tracking issues found." )
33- return 1
3436 if len (open_issues ) > 1 :
3537 print (
36- "Error: Multiple open release tracking issues found."
38+ "::error:: Multiple open release tracking issues found."
3739 " Cannot determine active one:"
3840 )
3941 for issue in open_issues :
4042 print (f"- #{ issue ['number' ]} : { issue ['title' ]} " )
4143 return 1
42- issue_num = open_issues [0 ]["number" ]
43- print (f"Auto-discovered active release tracking issue: #{ issue_num } " )
44+ elif len (open_issues ) == 1 :
45+ issue_num = open_issues [0 ]["number" ]
46+ print (
47+ f"Auto-discovered active release tracking issue: #{ issue_num } "
48+ )
49+ else :
50+ print (
51+ "No open release tracking issue found. Creating a new"
52+ " patch release tracking issue..."
53+ )
54+ patch_version = determine_next_version (git = self .git , is_patch = True )
55+ template_content = load_release_tracking_template (
56+ version = patch_version
57+ )
58+
59+ issue_num = self .gh .create_release_tracking_issue (
60+ patch_version , template_content
61+ )
62+ print (
63+ f"::notice::Created patch release tracking issue #{ issue_num } for"
64+ f" v{ patch_version } "
65+ )
4466 except Exception as e :
45- print (f"Error auto-discovering tracking issue: { e } " )
67+ print (
68+ f"::error::Error auto-discovering or creating tracking issue: { e } "
69+ )
4670 return 1
4771
4872 resolved_prs = []
@@ -51,7 +75,7 @@ def run(self) -> int:
5175 pr_num = self .gh .resolve_pr_number (pr_ref )
5276 resolved_prs .append (pr_num )
5377 except Exception as e :
54- print (f"Error resolving PR ref '{ pr_ref } ': { e } " )
78+ print (f"::error:: Error resolving PR ref '{ pr_ref } ': { e } " )
5579 return 1
5680
5781 print (
@@ -69,24 +93,34 @@ def run(self) -> int:
6993 not task .checked and task .status != "done" for task in rc_tags .values ()
7094 )
7195 next_rc_num = max (rc_tags .keys ()) + 1 if rc_tags else 0
72- if not has_pending_rc :
96+
97+ issue_title = self .gh .get_issue_title (issue_num )
98+ version_match = RELEASE_TITLE_RE .search (issue_title )
99+ is_patch = False
100+ if version_match :
101+ version = version_match .group (1 )
102+ is_patch = not version .endswith (".0" )
103+
104+ if not has_pending_rc and (rc_tags or not is_patch ):
73105 print (
74106 f"No pending RC task found. Adding 'Tag"
75107 f" RC{ next_rc_num } ' to checklist..."
76108 )
77109 body = add_rc_task_to_body (body , next_rc_num )
78110 except ValueError as e :
79- print (f"Error: { e } " )
111+ print (f"::error:: { e } " )
80112 return 1
81113 except Exception as e :
82- print (f"Failed to update tracking issue: { e } " )
114+ print (f"::error:: Failed to update tracking issue: { e } " )
83115 return 1
84116
85117 try :
86118 self .gh .update_issue_body (issue_num , body )
87- print ("Successfully updated tracking issue checklist." )
119+ print (
120+ f"::notice::Successfully updated tracking issue #{ issue_num } checklist."
121+ )
88122 except Exception as e :
89- print (f"Failed to update tracking issue body: { e } " )
123+ print (f"::error:: Failed to update tracking issue body: { e } " )
90124 return 1
91125
92126 return 0
@@ -115,4 +149,5 @@ def add_parser(cls, subparsers):
115149 def run_from_args (cls , args ):
116150 """Instantiates and runs the command from parsed args."""
117151 gh = GitHub ()
118- return cls (args , gh ).run ()
152+ git = Git (os .getcwd ())
153+ return cls (args , gh , git ).run ()
0 commit comments