UpdateIssueComment updates the issue comment.
(ctx context.Context, req *connect.Request[v1pb.UpdateIssueCommentRequest])
| 1277 | |
| 1278 | // UpdateIssueComment updates the issue comment. |
| 1279 | func (s *IssueService) UpdateIssueComment(ctx context.Context, req *connect.Request[v1pb.UpdateIssueCommentRequest]) (*connect.Response[v1pb.IssueComment], error) { |
| 1280 | if req.Msg.UpdateMask.Paths == nil { |
| 1281 | return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("update_mask is required")) |
| 1282 | } |
| 1283 | |
| 1284 | user, ok := GetUserFromContext(ctx) |
| 1285 | if !ok { |
| 1286 | return nil, connect.NewError(connect.CodeInternal, errors.Errorf("user not found")) |
| 1287 | } |
| 1288 | |
| 1289 | parentProjectID, parentIssueUID, err := common.GetProjectIDIssueUID(req.Msg.Parent) |
| 1290 | if err != nil { |
| 1291 | return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("invalid parent %q: %v", req.Msg.Parent, err)) |
| 1292 | } |
| 1293 | |
| 1294 | _, commentIssueUID, issueCommentID, err := common.GetProjectIDIssueUIDIssueCommentID(req.Msg.IssueComment.Name) |
| 1295 | if err != nil { |
| 1296 | return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("invalid comment name %q: %v", req.Msg.IssueComment.Name, err)) |
| 1297 | } |
| 1298 | if parentIssueUID != commentIssueUID { |
| 1299 | return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("issue comment %q does not belong to parent %q", req.Msg.IssueComment.Name, req.Msg.Parent)) |
| 1300 | } |
| 1301 | issueComment, err := s.store.GetIssueComment(ctx, &store.FindIssueCommentMessage{ProjectID: parentProjectID, ResourceID: &issueCommentID, IssueUID: &parentIssueUID}) |
| 1302 | if err != nil { |
| 1303 | return nil, connect.NewError(connect.CodeInternal, errors.Errorf("failed to get issue comment: %v", err)) |
| 1304 | } |
| 1305 | if issueComment == nil { |
| 1306 | if req.Msg.AllowMissing { |
| 1307 | ok, err := s.iamManager.CheckPermission(ctx, permission.IssueCommentsCreate, user, common.GetWorkspaceIDFromContext(ctx)) |
| 1308 | if err != nil { |
| 1309 | return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to check permission")) |
| 1310 | } |
| 1311 | if !ok { |
| 1312 | return nil, connect.NewError(connect.CodePermissionDenied, errors.Errorf("user does not have permission %q", permission.IssueCommentsCreate)) |
| 1313 | } |
| 1314 | return s.CreateIssueComment(ctx, connect.NewRequest(&v1pb.CreateIssueCommentRequest{ |
| 1315 | Parent: req.Msg.Parent, |
| 1316 | IssueComment: req.Msg.IssueComment, |
| 1317 | })) |
| 1318 | } |
| 1319 | return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("issue comment not found")) |
| 1320 | } |
| 1321 | update := &store.UpdateIssueCommentMessage{ |
| 1322 | ProjectID: parentProjectID, |
| 1323 | ResourceID: issueCommentID, |
| 1324 | } |
| 1325 | for _, path := range req.Msg.UpdateMask.Paths { |
| 1326 | switch path { |
| 1327 | case "comment": |
| 1328 | update.Comment = &req.Msg.IssueComment.Comment |
| 1329 | default: |
| 1330 | return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf(`unsupport update_mask: "%s"`, path)) |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | if err := s.store.UpdateIssueComment(ctx, update); err != nil { |
| 1335 | if common.ErrorCode(err) == common.NotFound { |
| 1336 | return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("cannot found the issue comment %s", req.Msg.IssueComment.Name)) |
nothing calls this directly
no test coverage detected