Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: List Project Groups functionality #288

Merged
merged 5 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 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 @@ -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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is groupName defined? This message is confusing. I expect this message to be like "There are no groups for project '%s'" with the cmdProjectName as substitute

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈
Will fix it up

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the condition though, this shouldn't ever be reached as projects should always have 1 group. Did you encounter this error?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I get this error message for all of our projects. We haven't assigned our projects to a group yet.

~ % lagoon list project-groups -p <PROJECT NAME>
Info: There are no projects in group ''

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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/guregu/null v4.0.0+incompatible
// workaround for https://github.com/manifoldco/promptui/issues/98
github.com/nicksnyder/go-i18n v1.10.1 // indirect
github.com/uselagoon/machinery v0.0.11
github.com/uselagoon/machinery v0.0.13
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20191105091915-95d230a53780 // indirect
Expand All @@ -41,4 +41,4 @@ replace github.com/olekukonko/tablewriter => github.com/shreddedbacon/tablewrite

// replace github.com/machinebox/graphql => ../../shreddedbacon/graphql

// replace github.com/olekukonko/tablewriter => ../../shreddedbacon/tablewriter
// replace github.com/olekukonko/tablewriter => ../../shreddedbacon/tablewriter
16 changes: 14 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3 h1:I4BOK3PBMjhWfQM2zPJKK7lOBGsrsvOB7kBELP33hiE=
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
Expand Down Expand Up @@ -105,8 +106,19 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9 h1:vY5WqiEon0ZSTGM3ayVVi+twaHKHDFUVloaQ/wug9/c=
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9/go.mod h1:q+QjxYvZ+fpjMXqs+XEriussHjSYqeXVnAdSV1tkMYk=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/uselagoon/machinery v0.0.11 h1:s6EhyU/pj1+C4FdS0EqmR6C0dLsoeCd9n+5xHL1YDag=
github.com/uselagoon/machinery v0.0.11/go.mod h1:IXLxlkahEAEgpCmu9Xa/Wmjo6ja4Aoq7tf8G7VrileE=
github.com/uselagoon/machinery v0.0.8 h1:PDPjBOoQGcmDDFsdibVN/iNkvWo3LJd1Yj+jOuw2bBg=
github.com/uselagoon/machinery v0.0.8/go.mod h1:dGAvkxWQkRu/eLQeWLrTl5HvNoFsiXlXInCptHUxzUw=
github.com/uselagoon/machinery v0.0.9-0.20230710124508-ef420b365811 h1:OUujMdzHe71+7l/GlS4VRyvehatO/jTT9+EIfbr+gwc=
github.com/uselagoon/machinery v0.0.9-0.20230710124508-ef420b365811/go.mod h1:IXLxlkahEAEgpCmu9Xa/Wmjo6ja4Aoq7tf8G7VrileE=
github.com/uselagoon/machinery v0.0.10 h1:pR+2iwXod0XnnyeZsJMlmkSU5BV8cYI65JNoaLwUVbQ=
github.com/uselagoon/machinery v0.0.10/go.mod h1:IXLxlkahEAEgpCmu9Xa/Wmjo6ja4Aoq7tf8G7VrileE=
github.com/uselagoon/machinery v0.0.12-0.20230825064934-e3ebd4b50b51 h1:xGymM19kpjhDapCxl8+gJ2dwiH3PcsjbgmqhxAclIEo=
github.com/uselagoon/machinery v0.0.12-0.20230825064934-e3ebd4b50b51/go.mod h1:IXLxlkahEAEgpCmu9Xa/Wmjo6ja4Aoq7tf8G7VrileE=
github.com/uselagoon/machinery v0.0.12-0.20230828053336-cb8156419c94 h1:GZQox2sqLVBPyCQqG7A163oFCMJ/+Egkoa1u/RXxHdU=
github.com/uselagoon/machinery v0.0.12-0.20230828053336-cb8156419c94/go.mod h1:IXLxlkahEAEgpCmu9Xa/Wmjo6ja4Aoq7tf8G7VrileE=
github.com/uselagoon/machinery v0.0.12/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk=
github.com/uselagoon/machinery v0.0.13 h1:ZCLBNWJmDr3wikaHs3pWhQ1j8MprhIqRuChgSqmLyZc=
github.com/uselagoon/machinery v0.0.13/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
Loading