MCPcopy
hub / github.com/cli/cli / reopenRun

Function reopenRun

pkg/cmd/pr/reopen/reopen.go:54–105  ·  view source on GitHub ↗
(opts *ReopenOptions)

Source from the content-addressed store, hash-verified

52}
53
54func 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}

Callers 1

NewCmdReopenFunction · 0.70

Calls 10

FullNameFunction · 0.92
CommentableRunFunction · 0.92
PullRequestReopenFunction · 0.92
ColorSchemeMethod · 0.80
FailureIconMethod · 0.80
IsOpenMethod · 0.80
WarningIconMethod · 0.80
SuccessIconWithColorMethod · 0.80
FindMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected