MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / ListDeploys

Method ListDeploys

component/user.go:498–558  ·  view source on GitHub ↗
(ctx context.Context, repoType types.RepositoryType, req *types.DeployReq)

Source from the content-addressed store, hash-verified

496}
497
498func (c *UserComponent) ListDeploys(ctx context.Context, repoType types.RepositoryType, req *types.DeployReq) ([]types.DeployRepo, int, error) {
499 user, err := c.us.FindByUsername(ctx, req.CurrentUser)
500 if err != nil {
501 newError := fmt.Errorf("failed to check for the presence of the user:%s, error:%w", req.CurrentUser, err)
502 return nil, 0, newError
503 }
504 deploys, total, err := c.deploy.ListDeployByUserID(ctx, user.ID, req)
505 if err != nil {
506 newError := fmt.Errorf("failed to get user deploys for %s with error:%w", repoType, err)
507 return nil, 0, newError
508 }
509
510 var resDeploys []types.DeployRepo
511 for _, deploy := range deploys {
512 d := &database.Deploy{
513 SvcName: deploy.SvcName,
514 ClusterID: deploy.ClusterID,
515 Status: deploy.Status,
516 }
517 endpoint, _ := c.repoComponent.generateEndpoint(ctx, d)
518 repoPath := strings.TrimPrefix(deploy.GitPath, string(repoType)+"s_")
519 var hardware types.HardWare
520 json.Unmarshal([]byte(deploy.Hardware), &hardware)
521 resourceType := ""
522 if hardware.Gpu.Num != "" {
523 resourceType = hardware.Gpu.Type
524 } else {
525 resourceType = hardware.Cpu.Type
526 }
527 tag := ""
528 tags, _ := c.repo.TagsWithCategory(ctx, deploy.RepoID, "task")
529 if len(tags) > 0 {
530 tag = tags[0].Name
531 }
532 resDeploys = append(resDeploys, types.DeployRepo{
533 DeployID: deploy.ID,
534 DeployName: deploy.DeployName,
535 Path: repoPath,
536 RepoID: deploy.RepoID,
537 SvcName: deploy.SvcName,
538 Status: deployStatusCodeToString(deploy.Status),
539 Hardware: deploy.Hardware,
540 Env: deploy.Env,
541 RuntimeFramework: deploy.RuntimeFramework,
542 ImageID: deploy.ImageID,
543 MinReplica: deploy.MinReplica,
544 MaxReplica: deploy.MaxReplica,
545 GitPath: deploy.GitPath,
546 GitBranch: deploy.GitBranch,
547 ClusterID: deploy.ClusterID,
548 SecureLevel: deploy.SecureLevel,
549 CreatedAt: deploy.CreatedAt,
550 UpdatedAt: deploy.UpdatedAt,
551 Type: deploy.Type,
552 ResourceType: resourceType,
553 RepoTag: tag,
554 Endpoint: endpoint,
555 })

Callers 1

GetRunDeploysMethod · 0.80

Calls 5

deployStatusCodeToStringFunction · 0.85
FindByUsernameMethod · 0.80
ListDeployByUserIDMethod · 0.80
generateEndpointMethod · 0.80
TagsWithCategoryMethod · 0.80

Tested by

no test coverage detected