MCPcopy
hub / github.com/cli/cli / reviewRun

Function reviewRun

pkg/cmd/pr/review/review.go:148–202  ·  view source on GitHub ↗
(opts *ReviewOptions)

Source from the content-addressed store, hash-verified

146}
147
148func reviewRun(opts *ReviewOptions) error {
149 findOptions := shared.FindOptions{
150 Selector: opts.SelectorArg,
151 Fields: []string{"id", "number"},
152 }
153 pr, baseRepo, err := opts.Finder.Find(findOptions)
154 if err != nil {
155 return err
156 }
157
158 var reviewData *api.PullRequestReviewInput
159 if opts.InteractiveMode {
160 reviewData, err = reviewSurvey(opts)
161 if err != nil {
162 return err
163 }
164 if reviewData == nil {
165 fmt.Fprint(opts.IO.ErrOut, "Discarding.\n")
166 return nil
167 }
168 } else {
169 reviewData = &api.PullRequestReviewInput{
170 State: opts.ReviewType,
171 Body: opts.Body,
172 }
173 }
174
175 httpClient, err := opts.HttpClient()
176 if err != nil {
177 return err
178 }
179 apiClient := api.NewClientFromHTTP(httpClient)
180
181 err = api.AddReview(apiClient, baseRepo, pr, reviewData)
182 if err != nil {
183 return fmt.Errorf("failed to create review: %w", err)
184 }
185
186 if !opts.IO.IsStdoutTTY() || !opts.IO.IsStderrTTY() {
187 return nil
188 }
189
190 cs := opts.IO.ColorScheme()
191
192 switch reviewData.State {
193 case api.ReviewComment:
194 fmt.Fprintf(opts.IO.ErrOut, "%s Reviewed pull request %s#%d\n", cs.Muted("-"), ghrepo.FullName(baseRepo), pr.Number)
195 case api.ReviewApprove:
196 fmt.Fprintf(opts.IO.ErrOut, "%s Approved pull request %s#%d\n", cs.SuccessIcon(), ghrepo.FullName(baseRepo), pr.Number)
197 case api.ReviewRequestChanges:
198 fmt.Fprintf(opts.IO.ErrOut, "%s Requested changes to pull request %s#%d\n", cs.Red("+"), ghrepo.FullName(baseRepo), pr.Number)
199 }
200
201 return nil
202}
203
204func reviewSurvey(opts *ReviewOptions) (*api.PullRequestReviewInput, error) {
205 options := []string{"Comment", "Approve", "Request Changes"}

Callers 1

NewCmdReviewFunction · 0.85

Calls 12

NewClientFromHTTPFunction · 0.92
AddReviewFunction · 0.92
FullNameFunction · 0.92
reviewSurveyFunction · 0.85
IsStdoutTTYMethod · 0.80
IsStderrTTYMethod · 0.80
ColorSchemeMethod · 0.80
MutedMethod · 0.80
SuccessIconMethod · 0.80
RedMethod · 0.80
FindMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected