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

Function CommentableRun

pkg/cmd/pr/shared/commentable.go:154–217  ·  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 cfg, err := opts.Config()
174 if err != nil {
175 return err
176 }
177 // Asked of opts.Host, so the answer is about the host the commentable
178 // was actually fetched from.
179 tokenType := cfg.Authentication().ActiveTokenType(opts.Host)
180 uploader, err = attachments.NewUploader(httpClient, tokenType, opts.Host, commentable.RepositoryDatabaseID(), commentable.RepositoryViewerPermission())
181 if err != nil {
182 return err
183 }
184 }
185
186 // Create new comment, bail before complexities of updating the last comment
187 if !opts.EditLast {
188 return createComment(commentable, opts, uploader)
189 }
190
191 // Update the last comment, handling success or unexpected errors accordingly
192 err = updateComment(commentable, opts, uploader)
193 if err == nil {
194 return nil
195 }
196 if !errors.Is(err, errNoUserComments) {
197 return err
198 }
199
200 // Determine whether to create new comment, prompt user if interactive and missing option
201 if !opts.CreateIfNone && opts.Interactive {
202 opts.CreateIfNone, err = opts.ConfirmCreateIfNoneSurvey()
203 if err != nil {
204 return err
205 }
206 }
207 if !opts.CreateIfNone {
208 return errNoUserComments
209 }
210
211 // Create new comment because updating the last comment failed due to no user comments

Callers 6

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

Calls 10

NewUploaderFunction · 0.92
deleteCommentFunction · 0.85
createCommentFunction · 0.85
updateCommentFunction · 0.85
RepoHostMethod · 0.65
ConfigMethod · 0.65
ActiveTokenTypeMethod · 0.65
AuthenticationMethod · 0.65
RepositoryDatabaseIDMethod · 0.65

Tested by 3

Test_commentRunFunction · 0.74
Test_commentRunFunction · 0.74