CommentUpdate updates a pull request comment.
( ctx context.Context, session *auth.Session, repoRef string, prNum int64, commentID int64, in *CommentUpdateInput, )
| 46 | |
| 47 | // CommentUpdate updates a pull request comment. |
| 48 | func (c *Controller) CommentUpdate( |
| 49 | ctx context.Context, |
| 50 | session *auth.Session, |
| 51 | repoRef string, |
| 52 | prNum int64, |
| 53 | commentID int64, |
| 54 | in *CommentUpdateInput, |
| 55 | ) (*types.PullReqActivity, error) { |
| 56 | if err := in.Sanitize(); err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | |
| 60 | repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview) |
| 61 | if err != nil { |
| 62 | return nil, fmt.Errorf("failed to acquire access to repo: %w", err) |
| 63 | } |
| 64 | |
| 65 | pr, err := c.pullreqStore.FindByNumber(ctx, repo.ID, prNum) |
| 66 | if err != nil { |
| 67 | return nil, fmt.Errorf("failed to find pull request by number: %w", err) |
| 68 | } |
| 69 | |
| 70 | act, err := c.getCommentCheckEditAccess(ctx, session, pr, commentID) |
| 71 | if err != nil { |
| 72 | return nil, fmt.Errorf("failed to get comment: %w", err) |
| 73 | } |
| 74 | |
| 75 | if !in.hasChanges(act) { |
| 76 | return act, nil |
| 77 | } |
| 78 | |
| 79 | // fetch parent activity |
| 80 | var parentAct *types.PullReqActivity |
| 81 | if act.IsReply() { |
| 82 | parentAct, err = c.activityStore.Find(ctx, *act.ParentID) |
| 83 | if err != nil { |
| 84 | return nil, fmt.Errorf("failed to find parent pull request activity: %w", err) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // generate all metadata updates |
| 89 | var metadataUpdates []types.PullReqActivityMetadataUpdate |
| 90 | |
| 91 | metadataUpdates, principalInfos, err := c.appendMetadataUpdateForMentions( |
| 92 | ctx, metadataUpdates, in.Text, |
| 93 | ) |
| 94 | if err != nil { |
| 95 | return nil, fmt.Errorf("failed to update metadata for mentions: %w", err) |
| 96 | } |
| 97 | |
| 98 | // suggestion metadata in case of code comments or code comment replies (don't restrict to either side for now). |
| 99 | if act.IsValidCodeComment() || (act.IsReply() && parentAct.IsValidCodeComment()) { |
| 100 | metadataUpdates = appendMetadataUpdateForSuggestions(metadataUpdates, in.Text) |
| 101 | } |
| 102 | |
| 103 | act, err = c.activityStore.UpdateOptLock(ctx, act, func(act *types.PullReqActivity) error { |
| 104 | now := time.Now().UnixMilli() |
| 105 | act.Edited = now |
no test coverage detected