Skip to content

Commit

Permalink
Improvement: Includes logic checks if project doesn't exist or no not…
Browse files Browse the repository at this point in the history
…ifications found (#322) (#323)

* Included logic checks if project doesn't exist or no notifications found

* Upgraded to latest machinery

---------

Co-authored-by: Ben Jackson <shreddedbacon@users.noreply.github.com>
  • Loading branch information
CGoodwin90 and shreddedbacon committed Mar 20, 2024
1 parent b638de5 commit 9bb1ee7
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 61 deletions.
32 changes: 21 additions & 11 deletions cmd/notificationsemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,36 @@ var listProjectEmailsCmd = &cobra.Command{
if err != nil {
return err
}
if cmdProjectName == "" {
return fmt.Errorf("Missing arguments: project name is not defined")
if err := requiredInputCheck("Project name", cmdProjectName); err != nil {
return err
}

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)
result, err := lagoon.GetProjectNotificationEmail(context.TODO(), cmdProjectName, lc)

result, err := l.GetProjectNotificationEmail(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
if len(result.Name) == 0 {
outputOptions.Error = fmt.Sprintf("No project found for '%s'\n", cmdProjectName)
} else if len(result.Notifications.Email) == 0 {
outputOptions.Error = fmt.Sprintf("No email notificatons found for project: '%s'\n", cmdProjectName)
}

data := []output.Data{}
for _, notification := range result.Notifications.Email {
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", notification.Name)),
returnNonEmptyString(fmt.Sprintf("%v", notification.EmailAddress)),
})
if result.Notifications != nil {
for _, notification := range result.Notifications.Email {
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", notification.Name)),
returnNonEmptyString(fmt.Sprintf("%v", notification.EmailAddress)),
})
}
}
output.RenderOutput(output.Table{
Header: []string{
Expand Down
34 changes: 22 additions & 12 deletions cmd/notificationsrocketchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,27 +162,37 @@ var listProjectRocketChatsCmd = &cobra.Command{
if err != nil {
return err
}
if cmdProjectName == "" {
return fmt.Errorf("Missing arguments: project name is not defined")
if err := requiredInputCheck("Project name", cmdProjectName); err != nil {
return err
}

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)
result, err := lagoon.GetProjectNotificationRocketChat(context.TODO(), cmdProjectName, lc)

result, err := l.GetProjectNotificationRocketChat(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
if len(result.Name) == 0 {
outputOptions.Error = fmt.Sprintf("No project found for '%s'\n", cmdProjectName)
} else if len(result.Notifications.RocketChat) == 0 {
outputOptions.Error = fmt.Sprintf("No rocketchat notificatons found for project: '%s'\n", cmdProjectName)
}

data := []output.Data{}
for _, notification := range result.Notifications.RocketChat {
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", notification.Name)),
returnNonEmptyString(fmt.Sprintf("%v", notification.Webhook)),
returnNonEmptyString(fmt.Sprintf("%v", notification.Channel)),
})
if result.Notifications != nil {
for _, notification := range result.Notifications.RocketChat {
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", notification.Name)),
returnNonEmptyString(fmt.Sprintf("%v", notification.Webhook)),
returnNonEmptyString(fmt.Sprintf("%v", notification.Channel)),
})
}
}
output.RenderOutput(output.Table{
Header: []string{
Expand Down
34 changes: 22 additions & 12 deletions cmd/notificationsslack.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,27 +162,37 @@ var listProjectSlacksCmd = &cobra.Command{
if err != nil {
return err
}
if cmdProjectName == "" {
return fmt.Errorf("Missing arguments: project name is not defined")
if err := requiredInputCheck("Project name", cmdProjectName); err != nil {
return err
}

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)
result, err := lagoon.GetProjectNotificationSlack(context.TODO(), cmdProjectName, lc)

result, err := l.GetProjectNotificationSlack(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
if len(result.Name) == 0 {
outputOptions.Error = fmt.Sprintf("No project found for '%s'\n", cmdProjectName)
} else if len(result.Notifications.Slack) == 0 {
outputOptions.Error = fmt.Sprintf("No slack notificatons found for project: '%s'\n", cmdProjectName)
}

data := []output.Data{}
for _, notification := range result.Notifications.Slack {
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", notification.Name)),
returnNonEmptyString(fmt.Sprintf("%v", notification.Webhook)),
returnNonEmptyString(fmt.Sprintf("%v", notification.Channel)),
})
if result.Notifications != nil {
for _, notification := range result.Notifications.Slack {
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", notification.Name)),
returnNonEmptyString(fmt.Sprintf("%v", notification.Webhook)),
returnNonEmptyString(fmt.Sprintf("%v", notification.Channel)),
})
}
}
output.RenderOutput(output.Table{
Header: []string{
Expand Down
32 changes: 21 additions & 11 deletions cmd/notificationsteams.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,36 @@ var listProjectMicrosoftTeamsCmd = &cobra.Command{
if err != nil {
return err
}
if cmdProjectName == "" {
return fmt.Errorf("Missing arguments: project name is not defined")
if err := requiredInputCheck("Project name", cmdProjectName); err != nil {
return err
}

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)
result, err := lagoon.GetProjectNotificationMicrosoftTeams(context.TODO(), cmdProjectName, lc)

result, err := l.GetProjectNotificationMicrosoftTeams(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
if len(result.Name) == 0 {
outputOptions.Error = fmt.Sprintf("No project found for '%s'\n", cmdProjectName)
} else if len(result.Notifications.MicrosoftTeams) == 0 {
outputOptions.Error = fmt.Sprintf("No microsoft teams notificatons found for project: '%s'\n", cmdProjectName)
}

data := []output.Data{}
for _, notification := range result.Notifications.MicrosoftTeams {
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", notification.Name)),
returnNonEmptyString(fmt.Sprintf("%v", notification.Webhook)),
})
if result.Notifications != nil {
for _, notification := range result.Notifications.MicrosoftTeams {
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", notification.Name)),
returnNonEmptyString(fmt.Sprintf("%v", notification.Webhook)),
})
}
}
output.RenderOutput(output.Table{
Header: []string{
Expand Down
32 changes: 21 additions & 11 deletions cmd/notificationswebhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,36 @@ var listProjectWebhooksCmd = &cobra.Command{
if err != nil {
return err
}
if cmdProjectName == "" {
return fmt.Errorf("Missing arguments: project name is not defined")
if err := requiredInputCheck("Project name", cmdProjectName); err != nil {
return err
}

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)
result, err := lagoon.GetProjectNotificationWebhook(context.TODO(), cmdProjectName, lc)

result, err := l.GetProjectNotificationWebhook(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
if len(result.Name) == 0 {
outputOptions.Error = fmt.Sprintf("No project found for '%s'\n", cmdProjectName)
} else if len(result.Notifications.Webhook) == 0 {
outputOptions.Error = fmt.Sprintf("No webhook notificatons found for project: '%s'\n", cmdProjectName)
}

data := []output.Data{}
for _, notification := range result.Notifications.Webhook {
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", notification.Name)),
returnNonEmptyString(fmt.Sprintf("%v", notification.Webhook)),
})
if result.Notifications != nil {
for _, notification := range result.Notifications.Webhook {
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", notification.Name)),
returnNonEmptyString(fmt.Sprintf("%v", notification.Webhook)),
})
}
}
output.RenderOutput(output.Table{
Header: []string{
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.2
github.com/uselagoon/machinery v0.0.16
golang.org/x/crypto v0.17.0
github.com/uselagoon/machinery v0.0.18
golang.org/x/crypto v0.21.0
gopkg.in/yaml.v3 v3.0.1
sigs.k8s.io/yaml v1.4.0
)
Expand All @@ -36,8 +36,8 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
)

// replace github.com/uselagoon/machinery => ../machinery
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,18 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/uselagoon/machinery v0.0.16 h1:LGWUaESTXPfiTyJTJCC1i+3ghidY2qsf9li7mGbH9Wo=
github.com/uselagoon/machinery v0.0.16/go.mod h1:Duljjz/3d/7m0jbmF1nVRDTNaMxMr6m+5LkgjiRrQaU=
github.com/uselagoon/machinery v0.0.17-0.20240313011522-ed1d14100c69 h1:T6wm/RNQMhIdAWtzcVGttbXKasPNN/KKqUeBBOURiFI=
github.com/uselagoon/machinery v0.0.17-0.20240313011522-ed1d14100c69/go.mod h1:Duljjz/3d/7m0jbmF1nVRDTNaMxMr6m+5LkgjiRrQaU=
github.com/uselagoon/machinery v0.0.18 h1:KQLMAYa0pJOSDlnwv7uKa4XXZTqw8WiI0VL+yIFgesM=
github.com/uselagoon/machinery v0.0.18/go.mod h1:NbgtEofjK2XY0iUpk9aMYazIo+W/NI56+UF72jv8zVY=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand All @@ -88,9 +95,15 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down

0 comments on commit 9bb1ee7

Please sign in to comment.