@@ -377,10 +377,11 @@ def _display_draft_releases(draft_files: list[Path], title: str = "Draft Release
377377@click .option ('--prerelease' , type = click .Choice (['auto' , 'true' , 'false' ], case_sensitive = False ), default = None ,
378378 help = 'Mark as prerelease: auto (detect from version), true, or false (default: from config)' )
379379@click .option ('--force' , type = click .Choice (['none' , 'draft' , 'published' ], case_sensitive = False ), default = 'none' , help = 'Force overwrite existing release (default: none)' )
380+ @click .option ('--ticket' , type = int , default = None , help = 'Ticket/issue number to associate with this release' )
380381@click .option ('--dry-run' , is_flag = True , help = 'Show what would be published without making changes' )
381382@click .pass_context
382383def publish (ctx , version : Optional [str ], list_drafts : bool , delete_drafts : bool , notes_file : Optional [str ], create_release : Optional [bool ],
383- create_pr : Optional [bool ], release_mode : Optional [str ], prerelease : Optional [str ], force : str ,
384+ create_pr : Optional [bool ], release_mode : Optional [str ], prerelease : Optional [str ], force : str , ticket : Optional [ int ],
384385 dry_run : bool ):
385386 """
386387 Publish a release to GitHub.
@@ -914,13 +915,32 @@ def publish(ctx, version: Optional[str], list_drafts: bool, delete_drafts: bool,
914915 # Create release tracking ticket if enabled
915916 ticket_result = None
916917
917- # If force=draft, try to find existing ticket interactively first if not in DB
918- if config .output .create_ticket and force == 'draft' and not dry_run :
918+ # If ticket number provided explicitly, use it directly
919+ if config .output .create_ticket and ticket and not dry_run :
920+ try :
921+ issue = github_client .gh .get_repo (issues_repo ).get_issue (ticket )
922+ ticket_result = {'number' : str (issue .number ), 'url' : issue .html_url }
923+ console .print (f"[blue]Using provided ticket #{ ticket } [/blue]" )
924+ # Save association to database
925+ db .save_ticket_association (
926+ repo_full_name = repo_name ,
927+ version = version ,
928+ ticket_number = ticket ,
929+ ticket_url = issue .html_url
930+ )
931+ if debug :
932+ console .print (f"[dim]Saved ticket association to database[/dim]" )
933+ except Exception as e :
934+ console .print (f"[yellow]Warning: Could not use ticket #{ ticket } : { e } [/yellow]" )
935+ ticket_result = None
936+
937+ # If force=draft, try to find existing ticket automatically (non-interactive)
938+ if config .output .create_ticket and force == 'draft' and not dry_run and not ticket_result :
919939 existing_association = db .get_ticket_association (repo_name , version )
920940 if not existing_association :
921- ticket_result = _find_existing_ticket_interactive (config , github_client , version )
941+ ticket_result = _find_existing_ticket_auto (config , github_client , version , debug )
922942 if ticket_result :
923- console .print (f"[blue]Reusing existing ticket #{ ticket_result ['number' ]} [/blue]" )
943+ console .print (f"[blue]Auto-selected open ticket #{ ticket_result ['number' ]} [/blue]" )
924944 # Save association
925945 db .save_ticket_association (
926946 repo_full_name = repo_name ,
@@ -1171,35 +1191,27 @@ def publish(ctx, version: Optional[str], list_drafts: bool, delete_drafts: bool,
11711191 db .close ()
11721192
11731193
1174- def _find_existing_ticket_interactive (config : Config , github_client : GitHubClient , version : str ) -> Optional [dict ]:
1175- """Find existing ticket interactively ."""
1194+ def _find_existing_ticket_auto (config : Config , github_client : GitHubClient , version : str , debug : bool = False ) -> Optional [dict ]:
1195+ """Find existing ticket automatically (non-interactive, picks first open ticket) ."""
11761196 issues_repo = _get_issues_repo (config )
1177- query = f"repo:{ issues_repo } is:issue { version } in:title"
1178- console .print (f"[cyan]Searching for existing tickets in { issues_repo } ...[/cyan]" )
1197+ # Search only for OPEN issues
1198+ query = f"repo:{ issues_repo } is:issue is:open { version } in:title"
1199+
1200+ if debug :
1201+ console .print (f"[dim]Searching for open tickets matching version { version } ...[/dim]" )
11791202
1180- # We need to use the underlying github client to search
1181- # This is a bit of a hack, but we don't have a search method in GitHubClient
1182- # Assuming github_client.gh is available
1203+ # Search for open issues matching the version
11831204 issues = list (github_client .gh .search_issues (query )[:5 ])
11841205
11851206 if not issues :
1186- console .print ("[yellow]No matching tickets found.[/yellow]" )
1207+ if debug :
1208+ console .print ("[dim]No matching open tickets found.[/dim]" )
11871209 return None
1188-
1189- table = Table (title = "Found Tickets" )
1190- table .add_column ("#" , style = "cyan" )
1191- table .add_column ("Number" , style = "green" )
1192- table .add_column ("Title" , style = "white" )
1193- table .add_column ("State" , style = "yellow" )
11941210
1195- for i , issue in enumerate (issues ):
1196- table .add_row (str (i + 1 ), str (issue .number ), issue .title , issue .state )
1197-
1198- console .print (table )
1211+ # Automatically use the first open ticket found
1212+ selected = issues [0 ]
11991213
1200- response = input ("\n Select ticket to reuse (1-5) or 'n' to create new: " ).strip ().lower ()
1201- if response .isdigit () and 1 <= int (response ) <= len (issues ):
1202- selected = issues [int (response )- 1 ]
1203- return {'number' : str (selected .number ), 'url' : selected .html_url }
1204-
1205- return None
1214+ if debug :
1215+ console .print (f"[dim]Found open ticket #{ selected .number } : { selected .title } [/dim]" )
1216+
1217+ return {'number' : str (selected .number ), 'url' : selected .html_url }
0 commit comments