MCPcopy Index your code
hub / github.com/bytebase/bytebase / UpdateProject

Method UpdateProject

backend/api/v1/project_service.go:259–386  ·  view source on GitHub ↗

UpdateProject updates a project.

(ctx context.Context, req *connect.Request[v1pb.UpdateProjectRequest])

Source from the content-addressed store, hash-verified

257
258// UpdateProject updates a project.
259func (s *ProjectService) UpdateProject(ctx context.Context, req *connect.Request[v1pb.UpdateProjectRequest]) (*connect.Response[v1pb.Project], error) {
260 if req.Msg.Project == nil {
261 return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("project must be set"))
262 }
263 if req.Msg.UpdateMask == nil {
264 return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("update_mask must be set"))
265 }
266
267 project, err := s.getProjectMessage(ctx, req.Msg.Project.Name)
268 if err != nil {
269 if connect.CodeOf(err) == connect.CodeNotFound && req.Msg.AllowMissing {
270 // When allow_missing is true and project doesn't exist, create a new one
271 projectID, perr := common.GetProjectID(req.Msg.Project.Name)
272 if perr != nil {
273 return nil, connect.NewError(connect.CodeInvalidArgument, perr)
274 }
275
276 return s.CreateProject(ctx, connect.NewRequest(&v1pb.CreateProjectRequest{
277 Project: req.Msg.Project,
278 ProjectId: projectID,
279 }))
280 }
281 return nil, err
282 }
283 if project.Deleted {
284 return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("project %q has been deleted", req.Msg.Project.Name))
285 }
286 if common.IsDefaultProject(project.Workspace, project.ResourceID) {
287 return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("default project cannot be updated"))
288 }
289
290 patch := &store.UpdateProjectMessage{
291 ResourceID: project.ResourceID,
292 Workspace: project.Workspace,
293 }
294
295 projectSettings := proto.CloneOf(project.Setting)
296 for _, path := range req.Msg.UpdateMask.Paths {
297 switch path {
298 case "title":
299 patch.Title = &req.Msg.Project.Title
300 case "data_classification_config_id":
301 setting, err := s.store.GetDataClassificationSetting(ctx, common.GetWorkspaceIDFromContext(ctx))
302 if err != nil {
303 return nil, connect.NewError(connect.CodeInternal, errors.Errorf("failed to get data classification setting"))
304 }
305 existConfig := false
306 for _, config := range setting.Configs {
307 if config.Id == req.Msg.Project.DataClassificationConfigId {
308 existConfig = true
309 break
310 }
311 }
312 if !existConfig {
313 return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("data classification %s not exists", req.Msg.Project.DataClassificationConfigId))
314 }
315 projectSettings.DataClassificationConfigId = req.Msg.Project.DataClassificationConfigId
316 patch.Setting = projectSettings

Callers

nothing calls this directly

Calls 13

getProjectMessageMethod · 0.95
CreateProjectMethod · 0.95
GetProjectIDFunction · 0.92
IsDefaultProjectFunction · 0.92
validateIssueLabelsFunction · 0.85
validateLabelsFunction · 0.85
convertToProjectFunction · 0.85
ErrorfMethod · 0.80
UpdateProjectsMethod · 0.80

Tested by

no test coverage detected