MCPcopy Index your code
hub / github.com/cli/cli / readyRun

Function readyRun

pkg/cmd/pr/ready/ready.go:66–115  ·  view source on GitHub ↗
(opts *ReadyOptions)

Source from the content-addressed store, hash-verified

64}
65
66func readyRun(opts *ReadyOptions) error {
67 cs := opts.IO.ColorScheme()
68
69 findOptions := shared.FindOptions{
70 Selector: opts.SelectorArg,
71 Fields: []string{"id", "number", "state", "isDraft"},
72 }
73 pr, baseRepo, err := opts.Finder.Find(findOptions)
74 if err != nil {
75 return err
76 }
77
78 if !pr.IsOpen() {
79 fmt.Fprintf(opts.IO.ErrOut, "%s Pull request %s#%d is closed. Only draft pull requests can be marked as \"ready for review\"\n", cs.FailureIcon(), ghrepo.FullName(baseRepo), pr.Number)
80 return cmdutil.SilentError
81 }
82
83 httpClient, err := opts.HttpClient()
84 if err != nil {
85 return err
86 }
87 apiClient := api.NewClientFromHTTP(httpClient)
88
89 if opts.Undo { // convert to draft
90 if pr.IsDraft {
91 fmt.Fprintf(opts.IO.ErrOut, "%s Pull request %s#%d is already \"in draft\"\n", cs.WarningIcon(), ghrepo.FullName(baseRepo), pr.Number)
92 return nil
93 }
94 err = api.ConvertPullRequestToDraft(apiClient, baseRepo, pr)
95 if err != nil {
96 return fmt.Errorf("API call failed: %w", err)
97 }
98
99 fmt.Fprintf(opts.IO.ErrOut, "%s Pull request %s#%d is converted to \"draft\"\n", cs.SuccessIconWithColor(cs.Green), ghrepo.FullName(baseRepo), pr.Number)
100 } else { // mark as ready for review
101 if !pr.IsDraft {
102 fmt.Fprintf(opts.IO.ErrOut, "%s Pull request %s#%d is already \"ready for review\"\n", cs.WarningIcon(), ghrepo.FullName(baseRepo), pr.Number)
103 return nil
104 }
105
106 err = api.PullRequestReady(apiClient, baseRepo, pr)
107 if err != nil {
108 return fmt.Errorf("API call failed: %w", err)
109 }
110
111 fmt.Fprintf(opts.IO.ErrOut, "%s Pull request %s#%d is marked as \"ready for review\"\n", cs.SuccessIconWithColor(cs.Green), ghrepo.FullName(baseRepo), pr.Number)
112 }
113
114 return nil
115}

Callers 1

NewCmdReadyFunction · 0.85

Calls 11

FullNameFunction · 0.92
NewClientFromHTTPFunction · 0.92
PullRequestReadyFunction · 0.92
ColorSchemeMethod · 0.80
IsOpenMethod · 0.80
FailureIconMethod · 0.80
WarningIconMethod · 0.80
SuccessIconWithColorMethod · 0.80
FindMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected