(ctx context.Context, repoType types.RepositoryType, req *types.DeployReq)
| 496 | } |
| 497 | |
| 498 | func (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 | }) |
no test coverage detected