CommentCreate creates a new pull request comment (pull request activity, type=comment/code-comment). nolint:gocognit // refactor if needed
( ctx context.Context, session *auth.Session, repoRef string, prNum int64, in *CommentCreateInput, )
| 95 | // |
| 96 | //nolint:gocognit // refactor if needed |
| 97 | func (c *Controller) CommentCreate( |
| 98 | ctx context.Context, |
| 99 | session *auth.Session, |
| 100 | repoRef string, |
| 101 | prNum int64, |
| 102 | in *CommentCreateInput, |
| 103 | ) (*types.PullReqActivity, error) { |
| 104 | if err := in.Sanitize(); err != nil { |
| 105 | return nil, err |
| 106 | } |
| 107 | |
| 108 | repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview) |
| 109 | if err != nil { |
| 110 | return nil, fmt.Errorf("failed to acquire access to repo: %w", err) |
| 111 | } |
| 112 | |
| 113 | var pr *types.PullReq |
| 114 | |
| 115 | pr, err = c.pullreqStore.FindByNumber(ctx, repo.ID, prNum) |
| 116 | if err != nil { |
| 117 | return nil, fmt.Errorf("failed to find pull request by number: %w", err) |
| 118 | } |
| 119 | |
| 120 | var parentAct *types.PullReqActivity |
| 121 | if in.IsReply() { |
| 122 | parentAct, err = c.checkIsReplyable(ctx, pr, in.ParentID) |
| 123 | if err != nil { |
| 124 | return nil, fmt.Errorf("failed to verify reply: %w", err) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | // fetch code snippet from git for code comments |
| 129 | var cut git.DiffCutOutput |
| 130 | if in.IsCodeComment() { |
| 131 | cut, err = c.fetchDiffCut(ctx, repo, in) |
| 132 | if err != nil { |
| 133 | return nil, err |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // generate all metadata updates |
| 138 | var metadataUpdates []types.PullReqActivityMetadataUpdate |
| 139 | |
| 140 | metadataUpdates, principalInfos, err := c.appendMetadataUpdateForMentions( |
| 141 | ctx, metadataUpdates, in.Text) |
| 142 | if err != nil { |
| 143 | return nil, fmt.Errorf("failed to update metadata for mentions: %w", err) |
| 144 | } |
| 145 | |
| 146 | // suggestion metadata in case of code comments or code comment replies (don't restrict to either side for now). |
| 147 | if in.IsCodeComment() || (in.IsReply() && parentAct.IsValidCodeComment()) { |
| 148 | metadataUpdates = appendMetadataUpdateForSuggestions(metadataUpdates, in.Text) |
| 149 | } |
| 150 | |
| 151 | var act *types.PullReqActivity |
| 152 | err = controller.TxOptLock(ctx, c.tx, func(ctx context.Context) error { |
| 153 | var err error |
| 154 |
no test coverage detected