MCPcopy Create free account
hub / github.com/bytebase/bytebase / GetSheet

Method GetSheet

backend/api/v1/sheet_service.go:110–149  ·  view source on GitHub ↗

GetSheet returns the requested sheet, cutoff the content if the content is too long and the `raw` flag in request is false.

(ctx context.Context, request *connect.Request[v1pb.GetSheetRequest])

Source from the content-addressed store, hash-verified

108
109// GetSheet returns the requested sheet, cutoff the content if the content is too long and the `raw` flag in request is false.
110func (s *SheetService) GetSheet(ctx context.Context, request *connect.Request[v1pb.GetSheetRequest]) (*connect.Response[v1pb.Sheet], error) {
111 projectResourceID, sheetSha256, err := common.GetProjectResourceIDSheetSha256(request.Msg.Name)
112 if err != nil {
113 return nil, connect.NewError(connect.CodeInvalidArgument, err)
114 }
115 if sheetSha256 == "" {
116 return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("invalid sheet sha256, must be non-empty"))
117 }
118
119 project, err := s.store.GetProject(ctx, &store.FindProjectMessage{
120 Workspace: common.GetWorkspaceIDFromContext(ctx),
121 ResourceID: &projectResourceID,
122 })
123 if err != nil {
124 return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("project with resource id %s not found", projectResourceID))
125 }
126 if project == nil {
127 return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("project with resource id %s not found", projectResourceID))
128 }
129 if project.Deleted {
130 return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("project with resource id %q had deleted", projectResourceID))
131 }
132
133 var sheet *store.SheetMessage
134 var sheetErr error
135 if request.Msg.Raw {
136 sheet, sheetErr = s.store.GetSheetFull(ctx, sheetSha256)
137 } else {
138 sheet, sheetErr = s.store.GetSheetTruncated(ctx, sheetSha256)
139 }
140 if sheetErr != nil {
141 return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(sheetErr, "failed to get sheet"))
142 }
143 if sheet == nil {
144 return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("cannot find the sheet"))
145 }
146
147 v1pbSheet := convertToAPISheetMessage(project.ResourceID, sheet)
148 return connect.NewResponse(v1pbSheet), nil
149}
150
151func convertToAPISheetMessage(projectID string, sheet *store.SheetMessage) *v1pb.Sheet {
152 return &v1pb.Sheet{

Callers

nothing calls this directly

Calls 7

convertToAPISheetMessageFunction · 0.85
ErrorfMethod · 0.80
GetSheetFullMethod · 0.80
GetSheetTruncatedMethod · 0.80
GetProjectMethod · 0.65

Tested by

no test coverage detected