Skip to content

Commit

Permalink
lint + cost
Browse files Browse the repository at this point in the history
  • Loading branch information
coryodaniel committed Nov 6, 2024
1 parent 9cadc0f commit f2aa55f
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 42 deletions.
20 changes: 11 additions & 9 deletions cmd/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,22 @@ func NewCmdPreview() *cobra.Command {
previewInitCmd.Flags().StringVarP(&previewInitParamsPath, "output", "o", "./preview.json", "Output path for preview environment params file. This file supports bash interpolation and can be manually edited or programatically modified during CI.")

previewDeployCmd := &cobra.Command{
Use: "deploy",
Short: "Deploys a preview environment in your project",
Long: helpdocs.MustRender("preview/deploy"),
RunE: runPreviewDeploy,
Use: "deploy",
Aliases: []string{"apply"},
Short: "Deploys a preview environment in your project",
Long: helpdocs.MustRender("preview/deploy"),
RunE: runPreviewDeploy,
}
previewDeployCmd.Flags().StringVarP(&previewInitParamsPath, "params", "p", previewInitParamsPath, "Path to preview environment configuration file. This file supports bash interpolation.")
previewDeployCmd.Flags().StringVarP(&previewDeployCiContextPath, "ci-context", "c", previewDeployCiContextPath, "Path to GitHub Actions event.json")

previewDecommissionCmd := &cobra.Command{
Use: "decommission $projectTargetSlug",
Short: "Decommissions a preview environment in your project",
Long: helpdocs.MustRender("preview/decommission"),
RunE: runPreviewDecommission,
Args: cobra.ExactArgs(1),
Use: "decommission $projectTargetSlug",
Aliases: []string{"destroy"},
Short: "Decommissions a preview environment in your project",
Long: helpdocs.MustRender("preview/decommission"),
RunE: runPreviewDecommission,
Args: cobra.ExactArgs(1),
}

previewCmd.AddCommand(previewInitCmd)
Expand Down
6 changes: 3 additions & 3 deletions cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func runProjList(cmd *cobra.Command, args []string) error {
projects, err := api.ListProjects(client, config.OrgID)

w := tabwriter.NewWriter(os.Stdout, 10, 1, 5, ' ', 0)
fmt.Fprintln(w, "ID\tNAME\tSLUG")
fmt.Fprintln(w, "SLUG\tNAME\tMONTHLY\tDAILY")

for _, project := range *projects {
line := fmt.Sprintf("%s\t%s\t%s", project.ID, project.Name, project.Slug)
for _, project := range projects {
line := fmt.Sprintf("%s\t%s\t%.2f\t%.2f", project.Slug, project.Name, project.MonthlyAverageCost, project.DailyAverageCost)
fmt.Fprintln(w, line)
}

Expand Down
18 changes: 17 additions & 1 deletion pkg/api/genqlient.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,23 @@ query getArtifactsByType($organizationId: ID!, $artifactType: String!) {

query projects($organizationId: ID!){
projects(organizationId: $organizationId){
id, name, defaultParams, slug, description
name
id
slug
description
defaultParams
cost{
monthly{
average{
amount
}
}
daily{
average{
amount
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/preview_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type PreviewConfig struct {
}

type PreviewPackage struct {
Params map[string]interface{} `json:"params"`
Params map[string]interface{} `json:"params,omitempty"`
Secrets []Secret `json:"secrets,omitempty"`
RemoteReferences []RemoteRef `json:"remoteReferences,omitempty"`
}
Expand Down
28 changes: 16 additions & 12 deletions pkg/api/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
)

type Project struct {
ID string
Name string
Slug string
Description string
DefaultParams map[string]interface{}
ID string
Name string
Slug string
Description string
DefaultParams map[string]interface{}
MonthlyAverageCost float64
DailyAverageCost float64
}

func GetProject(client graphql.Client, orgID string, idOrSlug string) (*Project, error) {
Expand All @@ -34,23 +36,25 @@ func (p *getProjectByIdProject) toProject() *Project {

func (p *projectsProjectsProject) toProject() Project {
return Project{
ID: p.Id,
Slug: p.Slug,
Name: p.Name,
Description: p.Description,
DefaultParams: p.DefaultParams,
ID: p.Id,
Slug: p.Slug,
Name: p.Name,
Description: p.Description,
DefaultParams: p.DefaultParams,
MonthlyAverageCost: p.Cost.Monthly.Average.Amount,
DailyAverageCost: p.Cost.Daily.Average.Amount,
}
}

func ListProjects(client graphql.Client, orgID string) (*[]Project, error) {
func ListProjects(client graphql.Client, orgID string) ([]Project, error) {
response, err := projects(context.Background(), client, orgID)
records := []Project{}

for _, prj := range response.Projects {
records = append(records, prj.toProject())
}

return &records, err
return records, err
}

func (p *Project) GetDefaultParams() map[string]PreviewPackage {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestListProjects(t *testing.T) {
t.Fatal(err)
}

got := len(*projects)
got := len(projects)

want := 2

Expand Down
106 changes: 91 additions & 15 deletions pkg/api/zz_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f2aa55f

Please sign in to comment.