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

Function CommentableRun

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

Source from the content-addressed store, hash-verified

149}
150
151func CommentableRun(opts *CommentableOptions) error {
152 commentable, repo, err := opts.RetrieveCommentable()
153 if err != nil {
154 return err
155 }
156 opts.Host = repo.RepoHost()
157 if opts.DeleteLast {
158 return deleteComment(commentable, opts)
159 }
160
161 // Guarded on the assets, because createComment and updateComment return
162 // early on the web path. An unguarded check here would fail a run that
163 // attached nothing.
164 var uploader *attachments.Uploader
165 if len(opts.Assets) > 0 {
166 httpClient, err := opts.HttpClient()
167 if err != nil {
168 return err
169 }
170 cfg, err := opts.Config()
171 if err != nil {
172 return err
173 }
174 // Asked of opts.Host, so the answer is about the host the commentable
175 // was actually fetched from.
176 tokenType := cfg.Authentication().ActiveTokenType(opts.Host)
177 uploader, err = attachments.NewUploader(httpClient, tokenType, opts.Host, commentable.RepositoryDatabaseID(), commentable.RepositoryViewerPermission())
178 if err != nil {
179 return err
180 }
181 }
182
183 // Create new comment, bail before complexities of updating the last comment
184 if !opts.EditLast {
185 return createComment(commentable, opts, uploader)
186 }
187
188 // Update the last comment, handling success or unexpected errors accordingly
189 err = updateComment(commentable, opts, uploader)
190 if err == nil {
191 return nil
192 }
193 if !errors.Is(err, errNoUserComments) {
194 return err
195 }
196
197 // Determine whether to create new comment, prompt user if interactive and missing option
198 if !opts.CreateIfNone && opts.Interactive {
199 opts.CreateIfNone, err = opts.ConfirmCreateIfNoneSurvey()
200 if err != nil {
201 return err
202 }
203 }
204 if !opts.CreateIfNone {
205 return errNoUserComments
206 }
207
208 // 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