(opts *RevertOptions)
| 83 | } |
| 84 | |
| 85 | func revertRun(opts *RevertOptions) error { |
| 86 | cs := opts.IO.ColorScheme() |
| 87 | |
| 88 | findOptions := shared.FindOptions{ |
| 89 | Selector: opts.SelectorArg, |
| 90 | Fields: []string{"id", "number", "state", "title"}, |
| 91 | } |
| 92 | pr, baseRepo, err := opts.Finder.Find(findOptions) |
| 93 | if err != nil { |
| 94 | return err |
| 95 | } |
| 96 | if pr.State != "MERGED" { |
| 97 | fmt.Fprintf(opts.IO.ErrOut, "%s Pull request %s#%d (%s) can't be reverted because it has not been merged\n", cs.FailureIcon(), ghrepo.FullName(baseRepo), pr.Number, pr.Title) |
| 98 | return cmdutil.SilentError |
| 99 | } |
| 100 | |
| 101 | httpClient, err := opts.HttpClient() |
| 102 | if err != nil { |
| 103 | return err |
| 104 | } |
| 105 | apiClient := api.NewClientFromHTTP(httpClient) |
| 106 | |
| 107 | params := githubv4.RevertPullRequestInput{ |
| 108 | PullRequestID: pr.ID, |
| 109 | Draft: githubv4.NewBoolean(githubv4.Boolean(opts.IsDraft)), |
| 110 | } |
| 111 | // Only set the Body field when opts.BodySet is true to avoid overriding |
| 112 | // GitHub's default revert body generation. |
| 113 | if opts.BodySet { |
| 114 | params.Body = githubv4.NewString(githubv4.String(opts.Body)) |
| 115 | } |
| 116 | // Only set the Title field when opts.Title is not empty to avoid overriding |
| 117 | // GitHub's default revert title generation. |
| 118 | if opts.Title != "" { |
| 119 | params.Title = githubv4.NewString(githubv4.String(opts.Title)) |
| 120 | } |
| 121 | |
| 122 | revertPR, err := api.PullRequestRevert(apiClient, baseRepo, params) |
| 123 | if err != nil { |
| 124 | fmt.Fprintf(opts.IO.ErrOut, "%s %s\n", cs.FailureIcon(), err) |
| 125 | return fmt.Errorf("API call failed: %w", err) |
| 126 | } |
| 127 | |
| 128 | if revertPR != nil { |
| 129 | fmt.Fprintln(opts.IO.Out, revertPR.URL) |
| 130 | } |
| 131 | return nil |
| 132 | } |
no test coverage detected