Skip to content

Commit

Permalink
Added platform project environments
Browse files Browse the repository at this point in the history
  • Loading branch information
futugyou committed Jan 11, 2025
1 parent 9ac520f commit 43d15dd
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 83 deletions.
9 changes: 5 additions & 4 deletions infr-project/application/platform_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down Expand Up @@ -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
Expand Down
54 changes: 30 additions & 24 deletions infr-project/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down
54 changes: 30 additions & 24 deletions infr-project/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -2067,7 +2090,13 @@
"environment_variables": {
"type": "array",
"items": {
"$ref": "#/definitions/viewmodels.ProjectEnvironmentVariable"
"$ref": "#/definitions/viewmodels.EnvironmentVariable"
}
},
"environments": {
"type": "array",
"items": {
"type": "string"
}
},
"followed": {
Expand Down Expand Up @@ -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": {
Expand Down
36 changes: 20 additions & 16 deletions infr-project/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions infr-project/platform_provider/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions infr-project/platform_provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions infr-project/platform_provider/vercel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ",")
}
Expand All @@ -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,
Expand Down Expand Up @@ -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, ",")
}
Expand All @@ -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,
}

Expand Down
31 changes: 16 additions & 15 deletions infr-project/view_models/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 43d15dd

Please sign in to comment.