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

Function CommentableRun

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

Source from the content-addressed store, hash-verified

106}
107
108func CommentableRun(opts *CommentableOptions) error {
109 commentable, repo, err := opts.RetrieveCommentable()
110 if err != nil {
111 return err
112 }
113 opts.Host = repo.RepoHost()
114 if opts.DeleteLast {
115 return deleteComment(commentable, opts)
116 }
117
118 // Create new comment, bail before complexities of updating the last comment
119 if !opts.EditLast {
120 return createComment(commentable, opts)
121 }
122
123 // Update the last comment, handling success or unexpected errors accordingly
124 err = updateComment(commentable, opts)
125 if err == nil {
126 return nil
127 }
128 if !errors.Is(err, errNoUserComments) {
129 return err
130 }
131
132 // Determine whether to create new comment, prompt user if interactive and missing option
133 if !opts.CreateIfNone && opts.Interactive {
134 opts.CreateIfNone, err = opts.ConfirmCreateIfNoneSurvey()
135 if err != nil {
136 return err
137 }
138 }
139 if !opts.CreateIfNone {
140 return errNoUserComments
141 }
142
143 // Create new comment because updating the last comment failed due to no user comments
144 if opts.Interactive {
145 fmt.Fprintln(opts.IO.ErrOut, "No comments found. Creating a new comment.")
146 }
147
148 return createComment(commentable, opts)
149}
150
151func createComment(commentable Commentable, opts *CommentableOptions) error {
152 switch opts.InputType {

Callers 5

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

Calls 4

deleteCommentFunction · 0.85
createCommentFunction · 0.85
updateCommentFunction · 0.85
RepoHostMethod · 0.65

Tested by 2

Test_commentRunFunction · 0.74
Test_commentRunFunction · 0.74