(opts *ReadyOptions)
| 64 | } |
| 65 | |
| 66 | func 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 | } |
no test coverage detected