BuildWorkspaceContext converts detected project metadata plus the current Pad client configuration into a machine-readable workspace context.
(dir string, info ProjectInfo, cfg *config.Config)
| 13 | // BuildWorkspaceContext converts detected project metadata plus the current Pad |
| 14 | // client configuration into a machine-readable workspace context. |
| 15 | func BuildWorkspaceContext(dir string, info ProjectInfo, cfg *config.Config) *models.WorkspaceContext { |
| 16 | context := &models.WorkspaceContext{ |
| 17 | Repositories: detectWorkspaceRepositories(dir), |
| 18 | Paths: detectWorkspacePaths(dir), |
| 19 | Commands: detectWorkspaceCommands(info), |
| 20 | Stack: &models.WorkspaceStack{ |
| 21 | Languages: uniqueNonEmpty([]string{info.Language}), |
| 22 | Frameworks: uniqueNonEmpty(info.Frameworks), |
| 23 | PackageManagers: uniqueNonEmpty(info.PackageManagers), |
| 24 | }, |
| 25 | Deployment: detectWorkspaceDeployment(cfg), |
| 26 | Assumptions: detectWorkspaceAssumptions(dir, cfg), |
| 27 | } |
| 28 | |
| 29 | if len(context.Repositories) == 0 { |
| 30 | context.Repositories = nil |
| 31 | } |
| 32 | if context.Paths != nil && *context.Paths == (models.WorkspacePaths{}) { |
| 33 | context.Paths = nil |
| 34 | } |
| 35 | if context.Commands != nil && *context.Commands == (models.WorkspaceCommands{}) { |
| 36 | context.Commands = nil |
| 37 | } |
| 38 | if context.Stack != nil && len(context.Stack.Languages) == 0 && len(context.Stack.Frameworks) == 0 && len(context.Stack.PackageManagers) == 0 { |
| 39 | context.Stack = nil |
| 40 | } |
| 41 | if context.Deployment != nil && *context.Deployment == (models.WorkspaceDeployment{}) { |
| 42 | context.Deployment = nil |
| 43 | } |
| 44 | if len(context.Assumptions) == 0 { |
| 45 | context.Assumptions = nil |
| 46 | } |
| 47 | |
| 48 | return context |
| 49 | } |
| 50 | |
| 51 | func detectWorkspaceRepositories(dir string) []models.WorkspaceRepository { |
| 52 | var repos []models.WorkspaceRepository |