(opts *ReviewOptions)
| 146 | } |
| 147 | |
| 148 | func 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 | |
| 204 | func reviewSurvey(opts *ReviewOptions) (*api.PullRequestReviewInput, error) { |
| 205 | options := []string{"Comment", "Approve", "Request Changes"} |
no test coverage detected