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

Improvement: Includes logic checks if project doesn't exist or no notifications found (#322) #323

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 {
shreddedbacon marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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
github.com/uselagoon/machinery v0.0.17-0.20240313011522-ed1d14100c69
golang.org/x/crypto v0.17.0
gopkg.in/yaml.v3 v3.0.1
sigs.k8s.io/yaml v1.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ 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/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=
Expand Down
Loading