CommentStatus updates a pull request comment status.
( ctx context.Context, session *auth.Session, repoRef string, prNum int64, commentID int64, in *CommentStatusInput, )
| 51 | |
| 52 | // CommentStatus updates a pull request comment status. |
| 53 | func (c *Controller) CommentStatus( |
| 54 | ctx context.Context, |
| 55 | session *auth.Session, |
| 56 | repoRef string, |
| 57 | prNum int64, |
| 58 | commentID int64, |
| 59 | in *CommentStatusInput, |
| 60 | ) (*types.PullReqActivity, error) { |
| 61 | repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview) |
| 62 | if err != nil { |
| 63 | return nil, fmt.Errorf("failed to acquire access to repo: %w", err) |
| 64 | } |
| 65 | |
| 66 | var pr *types.PullReq |
| 67 | var act *types.PullReqActivity |
| 68 | |
| 69 | err = controller.TxOptLock(ctx, c.tx, func(ctx context.Context) error { |
| 70 | pr, err = c.pullreqStore.FindByNumber(ctx, repo.ID, prNum) |
| 71 | if err != nil { |
| 72 | return fmt.Errorf("failed to find pull request by number: %w", err) |
| 73 | } |
| 74 | |
| 75 | if errValidate := in.Validate(); errValidate != nil { |
| 76 | return errValidate |
| 77 | } |
| 78 | |
| 79 | act, err = c.getCommentCheckChangeStatusAccess(ctx, pr, commentID) |
| 80 | if err != nil { |
| 81 | return fmt.Errorf("failed to get comment: %w", err) |
| 82 | } |
| 83 | |
| 84 | if !in.hasChanges(act, session.Principal.ID) { |
| 85 | return nil |
| 86 | } |
| 87 | |
| 88 | act.Resolved = nil |
| 89 | act.ResolvedBy = nil |
| 90 | |
| 91 | now := time.Now().UnixMilli() |
| 92 | |
| 93 | if in.Status != enum.PullReqCommentStatusActive { |
| 94 | // In the future if we add more comment resolved statuses |
| 95 | // we'll add the ResolvedReason field and put the reason there. |
| 96 | // For now, the nullable timestamp field/db-column "Resolved" tells the status (active/resolved). |
| 97 | act.Resolved = &now |
| 98 | act.ResolvedBy = &session.Principal.ID |
| 99 | } |
| 100 | |
| 101 | err = c.activityStore.Update(ctx, act) |
| 102 | if err != nil { |
| 103 | return fmt.Errorf("failed to update status of pull request activity: %w", err) |
| 104 | } |
| 105 | |
| 106 | // Here we deliberately use the transaction and counting the unresolved comments, |
| 107 | // rather than optimistic locking and incrementing/decrementing the counter. |
| 108 | // The idea is that if the counter ever goes out of sync, this would be the place where we get it back in sync. |
| 109 | unresolvedCount, err := c.activityStore.CountUnresolved(ctx, pr.ID) |
| 110 | if err != nil { |
no test coverage detected