MCPcopy Create free account
hub / github.com/cli/cli / CommentableRun

Function CommentableRun

pkg/cmd/pr/shared/commentable.go:154–210  ·  view source on GitHub ↗
(opts *CommentableOptions)

Source from the content-addressed store, hash-verified

152}
153
154func CommentableRun(opts *CommentableOptions) error {
155 commentable, repo, err := opts.RetrieveCommentable()
156 if err != nil {
157 return err
158 }
159 opts.Host = repo.RepoHost()
160 if opts.DeleteLast {
161 return deleteComment(commentable, opts)
162 }
163
164 // Guarded on the assets, because createComment and updateComment return
165 // early on the web path. An unguarded check here would fail a run that
166 // attached nothing.
167 var uploader *attachments.Uploader
168 if len(opts.Assets) > 0 {
169 httpClient, err := opts.HttpClient()
170 if err != nil {
171 return err
172 }
173 uploader, err = attachments.NewUploader(httpClient, opts.Host, commentable.RepositoryDatabaseID(), commentable.RepositoryViewerPermission())
174 if err != nil {
175 return err
176 }
177 }
178
179 // Create new comment, bail before complexities of updating the last comment
180 if !opts.EditLast {
181 return createComment(commentable, opts, uploader)
182 }
183
184 // Update the last comment, handling success or unexpected errors accordingly
185 err = updateComment(commentable, opts, uploader)
186 if err == nil {
187 return nil
188 }
189 if !errors.Is(err, errNoUserComments) {
190 return err
191 }
192
193 // Determine whether to create new comment, prompt user if interactive and missing option
194 if !opts.CreateIfNone && opts.Interactive {
195 opts.CreateIfNone, err = opts.ConfirmCreateIfNoneSurvey()
196 if err != nil {
197 return err
198 }
199 }
200 if !opts.CreateIfNone {
201 return errNoUserComments
202 }
203
204 // Create new comment because updating the last comment failed due to no user comments
205 if opts.Interactive {
206 fmt.Fprintln(opts.IO.ErrOut, "No comments found. Creating a new comment.")
207 }
208
209 return createComment(commentable, opts, uploader)
210}
211

Callers 6

Test_commentRunFunction · 0.92
closeRunFunction · 0.92
reopenRunFunction · 0.92
NewCmdCommentFunction · 0.92
Test_commentRunFunction · 0.92

Calls 7

NewUploaderFunction · 0.92
deleteCommentFunction · 0.85
createCommentFunction · 0.85
updateCommentFunction · 0.85
RepoHostMethod · 0.65
RepositoryDatabaseIDMethod · 0.65

Tested by 3

Test_commentRunFunction · 0.74
Test_commentRunFunction · 0.74