(ctx context.Context, req *connect.Request[v1pb.ListIssueCommentsRequest])
| 1187 | } |
| 1188 | |
| 1189 | func (s *IssueService) ListIssueComments(ctx context.Context, req *connect.Request[v1pb.ListIssueCommentsRequest]) (*connect.Response[v1pb.ListIssueCommentsResponse], error) { |
| 1190 | if req.Msg.PageSize < 0 { |
| 1191 | return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("page size must be non-negative: %d", req.Msg.PageSize)) |
| 1192 | } |
| 1193 | projectID, issueUID, err := common.GetProjectIDIssueUID(req.Msg.Parent) |
| 1194 | if err != nil { |
| 1195 | return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("%v", err.Error())) |
| 1196 | } |
| 1197 | issue, err := s.store.GetIssue(ctx, &store.FindIssueMessage{ |
| 1198 | Workspace: common.GetWorkspaceIDFromContext(ctx), |
| 1199 | UID: &issueUID, |
| 1200 | ProjectIDs: []string{projectID}, |
| 1201 | }) |
| 1202 | if err != nil { |
| 1203 | return nil, connect.NewError(connect.CodeInternal, errors.Errorf("failed to get issue, err: %v", err)) |
| 1204 | } |
| 1205 | if issue == nil { |
| 1206 | return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("issue %q not found", req.Msg.Parent)) |
| 1207 | } |
| 1208 | |
| 1209 | offset, err := parseLimitAndOffset(&pageSize{ |
| 1210 | token: req.Msg.PageToken, |
| 1211 | limit: int(req.Msg.PageSize), |
| 1212 | maximum: 1000, |
| 1213 | }) |
| 1214 | if err != nil { |
| 1215 | return nil, err |
| 1216 | } |
| 1217 | limitPlusOne := offset.limit + 1 |
| 1218 | |
| 1219 | issueComments, err := s.store.ListIssueComment(ctx, &store.FindIssueCommentMessage{ |
| 1220 | ProjectID: projectID, |
| 1221 | IssueUID: &issue.UID, |
| 1222 | Limit: &limitPlusOne, |
| 1223 | Offset: &offset.offset, |
| 1224 | }) |
| 1225 | if err != nil { |
| 1226 | return nil, connect.NewError(connect.CodeInternal, errors.Errorf("failed to list issue comments, err: %v", err)) |
| 1227 | } |
| 1228 | var nextPageToken string |
| 1229 | if len(issueComments) == limitPlusOne { |
| 1230 | if nextPageToken, err = offset.getNextPageToken(); err != nil { |
| 1231 | return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to get next page token")) |
| 1232 | } |
| 1233 | issueComments = issueComments[:offset.limit] |
| 1234 | } |
| 1235 | |
| 1236 | return connect.NewResponse(&v1pb.ListIssueCommentsResponse{ |
| 1237 | IssueComments: convertToIssueComments(req.Msg.Parent, issueComments), |
| 1238 | NextPageToken: nextPageToken, |
| 1239 | }), nil |
| 1240 | } |
| 1241 | |
| 1242 | // CreateIssueComment creates the issue comment. |
| 1243 | func (s *IssueService) CreateIssueComment(ctx context.Context, req *connect.Request[v1pb.CreateIssueCommentRequest]) (*connect.Response[v1pb.IssueComment], error) { |
nothing calls this directly
no test coverage detected