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

Function revertRun

pkg/cmd/pr/revert/revert.go:85–132  ·  view source on GitHub ↗
(opts *RevertOptions)

Source from the content-addressed store, hash-verified

83}
84
85func 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}

Callers 1

NewCmdRevertFunction · 0.85

Calls 8

FullNameFunction · 0.92
NewClientFromHTTPFunction · 0.92
PullRequestRevertFunction · 0.92
ColorSchemeMethod · 0.80
FailureIconMethod · 0.80
FindMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected