(opts *ReopenOptions)
| 52 | } |
| 53 | |
| 54 | func reopenRun(opts *ReopenOptions) error { |
| 55 | cs := opts.IO.ColorScheme() |
| 56 | |
| 57 | findOptions := shared.FindOptions{ |
| 58 | Selector: opts.SelectorArg, |
| 59 | Fields: []string{"id", "number", "state", "title"}, |
| 60 | } |
| 61 | pr, baseRepo, err := opts.Finder.Find(findOptions) |
| 62 | if err != nil { |
| 63 | return err |
| 64 | } |
| 65 | |
| 66 | if pr.State == "MERGED" { |
| 67 | fmt.Fprintf(opts.IO.ErrOut, "%s Pull request %s#%d (%s) can't be reopened because it was already merged\n", cs.FailureIcon(), ghrepo.FullName(baseRepo), pr.Number, pr.Title) |
| 68 | return cmdutil.SilentError |
| 69 | } |
| 70 | |
| 71 | if pr.IsOpen() { |
| 72 | fmt.Fprintf(opts.IO.ErrOut, "%s Pull request %s#%d (%s) is already open\n", cs.WarningIcon(), ghrepo.FullName(baseRepo), pr.Number, pr.Title) |
| 73 | return nil |
| 74 | } |
| 75 | |
| 76 | httpClient, err := opts.HttpClient() |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | |
| 81 | if opts.Comment != "" { |
| 82 | commentOpts := &shared.CommentableOptions{ |
| 83 | Body: opts.Comment, |
| 84 | HttpClient: opts.HttpClient, |
| 85 | InputType: shared.InputTypeInline, |
| 86 | Quiet: true, |
| 87 | RetrieveCommentable: func() (shared.Commentable, ghrepo.Interface, error) { |
| 88 | return pr, baseRepo, nil |
| 89 | }, |
| 90 | } |
| 91 | err := shared.CommentableRun(commentOpts) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | err = api.PullRequestReopen(httpClient, baseRepo, pr.ID) |
| 98 | if err != nil { |
| 99 | return fmt.Errorf("API call failed: %w", err) |
| 100 | } |
| 101 | |
| 102 | fmt.Fprintf(opts.IO.ErrOut, "%s Reopened pull request %s#%d (%s)\n", cs.SuccessIconWithColor(cs.Green), ghrepo.FullName(baseRepo), pr.Number, pr.Title) |
| 103 | |
| 104 | return nil |
| 105 | } |
no test coverage detected