Skip to content

Commit

Permalink
chore: merge main and fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Dec 5, 2023
2 parents e9fd16b + eeb83b5 commit 7bea834
Show file tree
Hide file tree
Showing 27 changed files with 359 additions and 641 deletions.
23 changes: 16 additions & 7 deletions cmd/deploytargetconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package cmd
import (
"context"
"fmt"
l "github.com/uselagoon/machinery/api/lagoon"
lclient "github.com/uselagoon/machinery/api/lagoon/client"
s "github.com/uselagoon/machinery/api/schema"

"github.com/spf13/cobra"
"github.com/uselagoon/lagoon-cli/internal/lagoon"
Expand Down Expand Up @@ -41,38 +44,44 @@ var addDeployTargetConfigCmd = &cobra.Command{
return err
}

if cmdProjectName == "" {
return fmt.Errorf("Missing arguments: project is a required flag")
}
if deploytarget == 0 {
return fmt.Errorf("Missing arguments: deploytarget id is a required flag")
}
if pullrequests == "" {
return fmt.Errorf("Missing arguments: pullrequests is a required flag")
}
if branches == "" {
return fmt.Errorf("Missing arguments: branches is a required flag")
}
current := lagoonCLIConfig.Current
lc := client.New(
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
&token,
debug)
project, err := lagoon.GetMinimalProjectByName(context.TODO(), cmdProjectName, lc)
project, err := l.GetMinimalProjectByName(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
addDeployTargetConfig := &schema.AddDeployTargetConfigInput{
addDeployTargetConfig := &s.AddDeployTargetConfigInput{
Project: uint(project.ID),
Weight: weight,
}
if branches != "" {
addDeployTargetConfig.Branches = branches
}
if branches != "" {
if pullrequests != "" {
addDeployTargetConfig.Pullrequests = pullrequests
}
if deploytarget != 0 {
addDeployTargetConfig.DeployTarget = deploytarget
}
if yesNo(fmt.Sprintf("You are attempting to add a deploytarget configuration to project '%s', are you sure?", cmdProjectName)) {
deployTargetConfig, err := lagoon.AddDeployTargetConfiguration(context.TODO(), addDeployTargetConfig, lc)
deployTargetConfig, err := l.AddDeployTargetConfiguration(context.TODO(), addDeployTargetConfig, lc)
if err != nil {
return err
}
Expand Down
84 changes: 67 additions & 17 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/uselagoon/lagoon-cli/pkg/output"

l "github.com/uselagoon/machinery/api/lagoon"
lclient "github.com/uselagoon/machinery/api/lagoon/client"
)
Expand Down Expand Up @@ -46,30 +48,78 @@ var getProjectCmd = &cobra.Command{
Use: "project",
Aliases: []string{"p"},
Short: "Get details about a project",
Run: func(cmd *cobra.Command, args []string) {
getProjectFlags := parseGetFlags(*cmd.Flags())
if getProjectFlags.Project == "" {
PreRunE: func(_ *cobra.Command, _ []string) error {
return validateTokenE(lagoonCLIConfig.Current)
},
RunE: func(cmd *cobra.Command, args []string) error {
debug, err := cmd.Flags().GetBool("debug")
if err != nil {
return err
}
if cmdProjectName == "" {
fmt.Println("Missing arguments: Project name is not defined")
cmd.Help()
os.Exit(1)
return nil
}
returnedJSON, err := pClient.GetProjectInfo(getProjectFlags.Project)
current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIVersion,
&token,
debug)

project, err := l.GetProjectByName(context.TODO(), cmdProjectName, lc)
if err != nil {
output.RenderError(err.Error(), outputOptions)
os.Exit(1)
return err
}
var dataMain output.Table
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
if err != nil {
output.RenderError(err.Error(), outputOptions)
os.Exit(1)

if project == nil {
output.RenderInfo(fmt.Sprintf("No details for project '%s'", cmdProjectName), outputOptions)
return nil
}
if len(dataMain.Data) == 0 {
output.RenderInfo(fmt.Sprintf("No details for project '%s'", getProjectFlags.Project), outputOptions)
os.Exit(0)

DevEnvironments := 0
productionRoute := "none"
deploymentsDisabled, err := strconv.ParseBool(strconv.Itoa(int(project.DeploymentsDisabled)))
handleError(err)
autoIdle, err := strconv.ParseBool(strconv.Itoa(int(project.AutoIdle)))
handleError(err)
factsUI, err := strconv.ParseBool(strconv.Itoa(int(project.FactsUI)))
handleError(err)
problemsUI, err := strconv.ParseBool(strconv.Itoa(int(project.ProblemsUI)))
handleError(err)
for _, environment := range project.Environments {
if environment.EnvironmentType == "development" {
DevEnvironments++
}
if environment.EnvironmentType == "production" {
productionRoute = environment.Route
}
}
output.RenderOutput(dataMain, outputOptions)

data := []output.Data{}
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%d", project.ID)),
returnNonEmptyString(fmt.Sprintf("%v", project.Name)),
returnNonEmptyString(fmt.Sprintf("%v", project.GitURL)),
returnNonEmptyString(fmt.Sprintf("%v", project.Branches)),
returnNonEmptyString(fmt.Sprintf("%v", project.PullRequests)),
returnNonEmptyString(fmt.Sprintf("%v", productionRoute)),
returnNonEmptyString(fmt.Sprintf("%v/%v", DevEnvironments, project.DevelopmentEnvironmentsLimit)),
returnNonEmptyString(fmt.Sprintf("%v", project.DevelopmentEnvironmentsLimit)),
returnNonEmptyString(fmt.Sprintf("%v", project.ProductionEnvironment)),
returnNonEmptyString(fmt.Sprintf("%v", project.RouterPattern)),
returnNonEmptyString(fmt.Sprintf("%v", autoIdle)),
returnNonEmptyString(fmt.Sprintf("%v", factsUI)),
returnNonEmptyString(fmt.Sprintf("%v", problemsUI)),
returnNonEmptyString(fmt.Sprintf("%v", deploymentsDisabled)),
})
dataMain := output.Table{
Header: []string{"ID", "ProjectName", "GitURL", "Branches", "PullRequests", "ProductionRoute", "DevEnvironments", "DevEnvLimit", "ProductionEnv", "RouterPattern", "AutoIdle", "FactsUI", "ProblemsUI", "DeploymentsDisabled"},
Data: data,
}
output.RenderOutput(dataMain, outputOptions)
return nil
},
}

Expand Down
72 changes: 64 additions & 8 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -286,17 +287,10 @@ var listVariablesCmd = &cobra.Command{
env = append(env, returnNonEmptyString(fmt.Sprintf("%v", envvar.Scope)))
env = append(env, returnNonEmptyString(fmt.Sprintf("%v", envvar.Name)))
if reveal {
env = append(env, returnNonEmptyString(fmt.Sprintf("%v", envvar.Value)))
env = append(env, fmt.Sprintf("%v", envvar.Value))
}
data = append(data, env)
}
if len(data) == 0 {
if cmdProjectEnvironment != "" {
return fmt.Errorf("There are no variables for environment '%s' in project '%s'", cmdProjectEnvironment, cmdProjectName)
} else {
return fmt.Errorf("There are no variables for project '%s'", cmdProjectName)
}
}
header := []string{
"ID",
"Project",
Expand All @@ -309,6 +303,13 @@ var listVariablesCmd = &cobra.Command{
if reveal {
header = append(header, "Value")
}
if len(data) == 0 {
if cmdProjectEnvironment != "" {
outputOptions.Error = fmt.Sprintf("There are no variables for environment '%s' in project '%s'", cmdProjectEnvironment, cmdProjectName)
} else {
outputOptions.Error = fmt.Sprintf("There are no variables for project '%s'\n", cmdProjectName)
}
}
output.RenderOutput(output.Table{
Header: header,
Data: data,
Expand Down Expand Up @@ -436,11 +437,66 @@ var listNotificationCmd = &cobra.Command{
},
}

var listProjectGroupsCmd = &cobra.Command{
Use: "project-groups",
Aliases: []string{"pg"},
Short: "List groups in a project (alias: pg)",
PreRunE: func(_ *cobra.Command, _ []string) error {
return validateTokenE(lagoonCLIConfig.Current)
},
RunE: func(cmd *cobra.Command, args []string) error {
debug, err := cmd.Flags().GetBool("debug")
if err != nil {
return err
}
if cmdProjectName == "" {
fmt.Println("Missing arguments: Project is not defined")
cmd.Help()
os.Exit(1)
}

current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIVersion,
&token,
debug)
projectGroups, err := l.GetProjectGroups(context.TODO(), cmdProjectName, lc)
handleError(err)

if len(projectGroups.Groups) == 0 {
output.RenderInfo(fmt.Sprintf("There are no projects in group '%s'", groupName), outputOptions)
os.Exit(0)
}

data := []output.Data{}
for _, group := range projectGroups.Groups {
var organization = "null"
if group.Organization != 0 {
organization = strconv.Itoa(group.Organization)
}
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", group.ID)),
returnNonEmptyString(fmt.Sprintf("%v", group.Name)),
returnNonEmptyString(fmt.Sprintf("%v", organization)),
})
}
dataMain := output.Table{
Header: []string{"Group ID", "Group Name", "Organization"},
Data: data,
}
output.RenderOutput(dataMain, outputOptions)
return nil
},
}

func init() {
listCmd.AddCommand(listDeployTargetsCmd)
listCmd.AddCommand(listDeploymentsCmd)
listCmd.AddCommand(listGroupsCmd)
listCmd.AddCommand(listGroupProjectsCmd)
listCmd.AddCommand(listProjectGroupsCmd)
listCmd.AddCommand(listEnvironmentsCmd)
listCmd.AddCommand(listProjectsCmd)
listCmd.AddCommand(listNotificationCmd)
Expand Down
30 changes: 16 additions & 14 deletions cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"encoding/json"
"fmt"
l "github.com/uselagoon/machinery/api/lagoon"
lclient "github.com/uselagoon/machinery/api/lagoon/client"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -155,13 +157,13 @@ var listProjectByMetadata = &cobra.Command{
return fmt.Errorf("Missing arguments: key is not defined")
}
current := lagoonCLIConfig.Current
lc := client.New(
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
&token,
debug)
projects, err := lagoon.GetProjectsByMetadata(context.TODO(), key, value, lc)
projects, err := l.GetProjectsByMetadata(context.TODO(), key, value, lc)
if err != nil {
return err
}
Expand Down Expand Up @@ -275,17 +277,17 @@ var updateProjectMetadata = &cobra.Command{
}
if yesNo(fmt.Sprintf("You are attempting to update key '%s' for project '%s' metadata, are you sure?", key, cmdProjectName)) {
current := lagoonCLIConfig.Current
lc := client.New(
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
&token,
debug)
project, err := lagoon.GetMinimalProjectByName(context.TODO(), cmdProjectName, lc)
project, err := l.GetMinimalProjectByName(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
projectResult, err := lagoon.UpdateProjectMetadata(context.TODO(), int(project.ID), key, value, lc)
projectResult, err := l.UpdateProjectMetadata(context.TODO(), int(project.ID), key, value, lc)
if err != nil {
return err
}
Expand Down Expand Up @@ -330,17 +332,17 @@ var deleteProjectMetadataByKey = &cobra.Command{
}
if yesNo(fmt.Sprintf("You are attempting to delete key '%s' from project '%s' metadata, are you sure?", key, cmdProjectName)) {
current := lagoonCLIConfig.Current
lc := client.New(
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
&token,
debug)
project, err := lagoon.GetMinimalProjectByName(context.TODO(), cmdProjectName, lc)
project, err := l.GetMinimalProjectByName(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
projectResult, err := lagoon.RemoveProjectMetadataByKey(context.TODO(), int(project.ID), key, lc)
projectResult, err := l.RemoveProjectMetadataByKey(context.TODO(), int(project.ID), key, lc)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 7bea834

Please sign in to comment.