MCPcopy
hub / github.com/cli/cli / editRun

Function editRun

pkg/cmd/discussion/edit/edit.go:122–220  ·  view source on GitHub ↗
(opts *EditOptions)

Source from the content-addressed store, hash-verified

120}
121
122func editRun(opts *EditOptions) error {
123 repo, err := opts.BaseRepo()
124 if err != nil {
125 return err
126 }
127
128 c, err := opts.Client()
129 if err != nil {
130 return err
131 }
132
133 opts.IO.StartProgressIndicator()
134 discussion, err := c.GetByNumber(repo, opts.DiscussionNumber)
135 opts.IO.StopProgressIndicator()
136 if err != nil {
137 return err
138 }
139
140 input := client.UpdateDiscussionInput{
141 DiscussionID: discussion.ID,
142 }
143
144 if opts.Interactive {
145 changed, err := promptEdit(opts, discussion, c, repo, &input)
146 if err != nil {
147 return err
148 }
149
150 if !changed {
151 return cmdutil.CancelError
152 }
153 } else {
154 if opts.TitleProvided {
155 if strings.TrimSpace(opts.Title) == "" {
156 return cmdutil.FlagErrorf("title cannot be blank")
157 }
158 input.Title = &opts.Title
159 }
160 if opts.BodyProvided {
161 if opts.BodyFile != "" {
162 bodyBytes, err := cmdutil.ReadFile(opts.BodyFile, opts.IO.In)
163 if err != nil {
164 return err
165 }
166 opts.Body = string(bodyBytes)
167 }
168 input.Body = &opts.Body
169 }
170 if opts.CategoryProvided {
171 opts.IO.StartProgressIndicator()
172 categories, err := c.ListCategories(repo)
173 opts.IO.StopProgressIndicator()
174 if err != nil {
175 return err
176 }
177 cat, err := shared.MatchCategory(opts.Category, categories)
178 if err != nil {
179 return err

Callers 2

TestEditRunFunction · 0.70
NewCmdEditFunction · 0.70

Calls 14

FlagErrorfFunction · 0.92
ReadFileFunction · 0.92
MatchCategoryFunction · 0.92
ResolveLabelsFunction · 0.92
promptEditFunction · 0.85
BaseRepoMethod · 0.65
GetByNumberMethod · 0.65
StopProgressIndicatorMethod · 0.65
ListCategoriesMethod · 0.65
ListLabelsMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

TestEditRunFunction · 0.56