| 106 | } |
| 107 | |
| 108 | func 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 | |
| 151 | func createComment(commentable Commentable, opts *CommentableOptions) error { |
| 152 | switch opts.InputType { |