diff --git a/infr-project/application/platform_convert.go b/infr-project/application/platform_convert.go index 8df50a3d..8cbc4cad 100644 --- a/infr-project/application/platform_convert.go +++ b/infr-project/application/platform_convert.go @@ -63,9 +63,9 @@ func (s *PlatformService) convertToPlatformModelProjects(projects map[string]pla return platformProjects } -func (s *PlatformService) convertToPlatformModelEnvironments(values map[string]platformProvider.EnvironmentVariable) []models.ProjectEnvironmentVariable { - return tool.MapToSlice(values, func(key string, v platformProvider.EnvironmentVariable) models.ProjectEnvironmentVariable { - return models.ProjectEnvironmentVariable(v) +func (s *PlatformService) convertToPlatformModelEnvironments(values map[string]platformProvider.EnvironmentVariable) []models.EnvironmentVariable { + return tool.MapToSlice(values, func(key string, v platformProvider.EnvironmentVariable) models.EnvironmentVariable { + return models.EnvironmentVariable(v) }) } @@ -299,7 +299,8 @@ func (s *PlatformService) mergeProject(providerProject *platformProvider.Project modelProject.Url = providerProject.Url modelProject.ProviderProjectId = providerProject.ID - modelProject.Environments = s.convertToPlatformModelEnvironments(providerProject.EnvironmentVariables) + modelProject.EnvironmentVariables = s.convertToPlatformModelEnvironments(providerProject.EnvironmentVariables) + modelProject.Environments = providerProject.Environments modelProject.Workflows = s.convertToPlatformModelWorkflows(providerProject.Workflows) modelProject.Deployments = s.convertToPlatformModelDeployments(providerProject.Deployments) modelProject.BadgeURL = providerProject.BadgeURL diff --git a/infr-project/docs/docs.go b/infr-project/docs/docs.go index df12c351..01113010 100644 --- a/infr-project/docs/docs.go +++ b/infr-project/docs/docs.go @@ -1971,6 +1971,29 @@ const docTemplate = `{ } } }, + "viewmodels.EnvironmentVariable": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "id": { + "type": "string" + }, + "key": { + "type": "string" + }, + "type": { + "type": "string" + }, + "updatedAt": { + "type": "string" + }, + "value": { + "type": "string" + } + } + }, "viewmodels.ImportVaultsRequest": { "type": "object", "properties": { @@ -2078,7 +2101,13 @@ const docTemplate = `{ "environment_variables": { "type": "array", "items": { - "$ref": "#/definitions/viewmodels.ProjectEnvironmentVariable" + "$ref": "#/definitions/viewmodels.EnvironmentVariable" + } + }, + "environments": { + "type": "array", + "items": { + "type": "string" } }, "followed": { @@ -2168,29 +2197,6 @@ const docTemplate = `{ } } }, - "viewmodels.ProjectEnvironmentVariable": { - "type": "object", - "properties": { - "createdAt": { - "type": "string" - }, - "id": { - "type": "string" - }, - "key": { - "type": "string" - }, - "type": { - "type": "string" - }, - "updatedAt": { - "type": "string" - }, - "value": { - "type": "string" - } - } - }, "viewmodels.ProjectPlatform": { "type": "object", "properties": { diff --git a/infr-project/docs/swagger.json b/infr-project/docs/swagger.json index 42dad67b..39157081 100644 --- a/infr-project/docs/swagger.json +++ b/infr-project/docs/swagger.json @@ -1960,6 +1960,29 @@ } } }, + "viewmodels.EnvironmentVariable": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "id": { + "type": "string" + }, + "key": { + "type": "string" + }, + "type": { + "type": "string" + }, + "updatedAt": { + "type": "string" + }, + "value": { + "type": "string" + } + } + }, "viewmodels.ImportVaultsRequest": { "type": "object", "properties": { @@ -2067,7 +2090,13 @@ "environment_variables": { "type": "array", "items": { - "$ref": "#/definitions/viewmodels.ProjectEnvironmentVariable" + "$ref": "#/definitions/viewmodels.EnvironmentVariable" + } + }, + "environments": { + "type": "array", + "items": { + "type": "string" } }, "followed": { @@ -2157,29 +2186,6 @@ } } }, - "viewmodels.ProjectEnvironmentVariable": { - "type": "object", - "properties": { - "createdAt": { - "type": "string" - }, - "id": { - "type": "string" - }, - "key": { - "type": "string" - }, - "type": { - "type": "string" - }, - "updatedAt": { - "type": "string" - }, - "value": { - "type": "string" - } - } - }, "viewmodels.ProjectPlatform": { "type": "object", "properties": { diff --git a/infr-project/docs/swagger.yaml b/infr-project/docs/swagger.yaml index 27f18e23..d041b495 100644 --- a/infr-project/docs/swagger.yaml +++ b/infr-project/docs/swagger.yaml @@ -338,6 +338,21 @@ definitions: readySubstate: type: string type: object + viewmodels.EnvironmentVariable: + properties: + createdAt: + type: string + id: + type: string + key: + type: string + type: + type: string + updatedAt: + type: string + value: + type: string + type: object viewmodels.ImportVaultsRequest: properties: storage_media: @@ -411,7 +426,11 @@ definitions: type: string environment_variables: items: - $ref: '#/definitions/viewmodels.ProjectEnvironmentVariable' + $ref: '#/definitions/viewmodels.EnvironmentVariable' + type: array + environments: + items: + type: string type: array followed: type: boolean @@ -470,21 +489,6 @@ definitions: $ref: '#/definitions/viewmodels.ProjectResource' type: array type: object - viewmodels.ProjectEnvironmentVariable: - properties: - createdAt: - type: string - id: - type: string - key: - type: string - type: - type: string - updatedAt: - type: string - value: - type: string - type: object viewmodels.ProjectPlatform: properties: description: diff --git a/infr-project/platform_provider/github.go b/infr-project/platform_provider/github.go index baddc61d..18fcf3f3 100644 --- a/infr-project/platform_provider/github.go +++ b/infr-project/platform_provider/github.go @@ -271,11 +271,23 @@ func (g *GithubClient) GetProjectAsync(ctx context.Context, filter ProjectFilter } } + environments := []string{} + if gitRuns, _, err := g.client.Repositories.ListEnvironments(ctx, GITHUB_OWNER, filter.Name, &github.EnvironmentListOptions{ + ListOptions: github.ListOptions{Page: 1, PerPage: 20}, + }); err != nil { + log.Println(err.Error()) + } else { + for _, v := range gitRuns.Environments { + environments = append(environments, v.GetEnvironmentName()) + } + } + project := g.buildGithubProject(repository) project.WebHooks = hooks project.EnvironmentVariables = envs project.Workflows = wfs project.Deployments = runs + project.Environments = environments resultChan <- &project }() return resultChan, errorChan diff --git a/infr-project/platform_provider/provider.go b/infr-project/platform_provider/provider.go index 9edbc4d5..b5d46947 100644 --- a/infr-project/platform_provider/provider.go +++ b/infr-project/platform_provider/provider.go @@ -20,6 +20,7 @@ type Project struct { WebHooks []WebHook Properties map[string]string EnvironmentVariables map[string]EnvironmentVariable + Environments []string Workflows map[string]Workflow Deployments map[string]Deployment BadgeURL string diff --git a/infr-project/platform_provider/vercel.go b/infr-project/platform_provider/vercel.go index ed592576..dbe3421c 100644 --- a/infr-project/platform_provider/vercel.go +++ b/infr-project/platform_provider/vercel.go @@ -96,7 +96,9 @@ func (g *VercelClient) ListProjectAsync(ctx context.Context, filter ProjectFilte } properties := map[string]string{} + environments := []string{} for key, v := range project.Targets { + environments = append(environments, key) k := strings.ToUpper(fmt.Sprintf("%s_Alias", key)) properties[k] = strings.Join(v.Alias, ",") } @@ -113,6 +115,7 @@ func (g *VercelClient) ListProjectAsync(ctx context.Context, filter ProjectFilte Url: url, Properties: properties, EnvironmentVariables: g.buildVercelEnv(project.Env), + Environments: environments, Deployments: g.buildVercelDeployment(project.LatestDeployments, url), BadgeURL: badgeURL, BadgeMarkDown: badgeMarkdown, @@ -173,7 +176,9 @@ func (g *VercelClient) GetProjectAsync(ctx context.Context, filter ProjectFilter } properties := map[string]string{} + environments := []string{} for key, v := range vercelProject.Targets { + environments = append(environments, key) k := strings.ToUpper(fmt.Sprintf("%s_Alias", key)) properties[k] = strings.Join(v.Alias, ",") } @@ -198,6 +203,7 @@ func (g *VercelClient) GetProjectAsync(ctx context.Context, filter ProjectFilter EnvironmentVariables: g.buildVercelEnv(vercelProject.Env), Deployments: g.buildVercelDeployment(vercelProject.LatestDeployments, url), BadgeURL: badgeURL, + Environments: environments, BadgeMarkDown: badgeMarkdown, } diff --git a/infr-project/view_models/platform.go b/infr-project/view_models/platform.go index a40fe755..86368b82 100644 --- a/infr-project/view_models/platform.go +++ b/infr-project/view_models/platform.go @@ -80,23 +80,24 @@ type Secret struct { } type PlatformProject struct { - Id string `json:"id"` - Name string `json:"name"` - Url string `json:"url"` - Description string `json:"description"` - Properties []Property `json:"properties"` - Secrets []Secret `json:"secrets"` - Webhooks []Webhook `json:"webhooks"` - Followed bool `json:"followed"` - ProviderProjectId string `json:"provider_project_id"` - Environments []ProjectEnvironmentVariable `json:"environment_variables"` - Workflows []Workflow `json:"workflows"` - Deployments []Deployment `json:"deployments"` - BadgeURL string `json:"badge_url"` - BadgeMarkdown string `json:"badge_markdown"` + Id string `json:"id"` + Name string `json:"name"` + Url string `json:"url"` + Description string `json:"description"` + Properties []Property `json:"properties"` + Secrets []Secret `json:"secrets"` + Webhooks []Webhook `json:"webhooks"` + Followed bool `json:"followed"` + ProviderProjectId string `json:"provider_project_id"` + EnvironmentVariables []EnvironmentVariable `json:"environment_variables"` + Environments []string `json:"environments"` + Workflows []Workflow `json:"workflows"` + Deployments []Deployment `json:"deployments"` + BadgeURL string `json:"badge_url"` + BadgeMarkdown string `json:"badge_markdown"` } -type ProjectEnvironmentVariable struct { +type EnvironmentVariable struct { ID string `json:"id"` Key string `json:"key"` CreatedAt string `json:"createdAt"`