@@ -42,6 +42,7 @@ func (f *IssuesCommandFactory) CreateCommand(t *i18n.Translations, cfg *config.C
4242 Usage : t .GetMessage ("issue.command_usage" , 0 , nil ),
4343 Commands : []* cli.Command {
4444 f .newGenerateCommand (t , cfg ),
45+ f .newLinkCommand (t , cfg ),
4546 f .newTemplateCommand (t , cfg ),
4647 },
4748 }
@@ -346,3 +347,74 @@ func (f *IssuesCommandFactory) checkoutBranch(branchName string) error {
346347 }
347348 return nil
348349}
350+
351+ // newLinkCommand crea el subcomando 'link'.
352+ func (f * IssuesCommandFactory ) newLinkCommand (t * i18n.Translations , cfg * config.Config ) * cli.Command {
353+ return & cli.Command {
354+ Name : "link" ,
355+ Aliases : []string {"l" },
356+ Usage : t .GetMessage ("issue.link_usage" , 0 , nil ),
357+ Flags : []cli.Flag {
358+ & cli.IntFlag {
359+ Name : "pr" ,
360+ Aliases : []string {"p" },
361+ Usage : t .GetMessage ("issue.flag_pr_number" , 0 , nil ),
362+ Required : true ,
363+ },
364+ & cli.IntFlag {
365+ Name : "issue" ,
366+ Aliases : []string {"i" },
367+ Usage : t .GetMessage ("issue.flag_issue_number" , 0 , nil ),
368+ Required : true ,
369+ },
370+ },
371+ Action : f .createLinkAction (t , cfg ),
372+ }
373+ }
374+
375+ // createLinkAction crea la acción para linkear un PR a una issue.
376+ func (f * IssuesCommandFactory ) createLinkAction (t * i18n.Translations , cfg * config.Config ) cli.ActionFunc {
377+ return func (ctx context.Context , command * cli.Command ) error {
378+ prNumber := command .Int ("pr" )
379+ issueNumber := command .Int ("issue" )
380+
381+ if prNumber <= 0 {
382+ ui .PrintError (t .GetMessage ("issue.error_invalid_pr" , 0 , nil ))
383+ return fmt .Errorf ("invalid PR number" )
384+ }
385+
386+ if issueNumber <= 0 {
387+ ui .PrintError (t .GetMessage ("issue.error_invalid_issue" , 0 , nil ))
388+ return fmt .Errorf ("invalid issue number" )
389+ }
390+
391+ ui .PrintSectionBanner (t .GetMessage ("issue.link_banner" , 0 , nil ))
392+
393+ issueService , err := f .issueServiceProvider (ctx )
394+ if err != nil {
395+ ui .PrintError (fmt .Sprintf ("%s: %v" , t .GetMessage ("issue.error_linking" , 0 , nil ), err ))
396+ return err
397+ }
398+
399+ spinner := ui .NewSmartSpinner (t .GetMessage ("issue.linking" , 0 , map [string ]interface {}{
400+ "PR" : prNumber ,
401+ "Issue" : issueNumber ,
402+ }))
403+ spinner .Start ()
404+
405+ err = issueService .LinkIssueToPR (ctx , prNumber , issueNumber )
406+ spinner .Stop ()
407+
408+ if err != nil {
409+ ui .PrintError (fmt .Sprintf ("%s: %v" , t .GetMessage ("issue.error_linking" , 0 , nil ), err ))
410+ return err
411+ }
412+
413+ ui .PrintSuccess (t .GetMessage ("issue.link_success" , 0 , map [string ]interface {}{
414+ "PR" : prNumber ,
415+ "Issue" : issueNumber ,
416+ }))
417+
418+ return nil
419+ }
420+ }
0 commit comments