Skip to content

Commit 2258d39

Browse files
committed
feat(slack): add /show command
1 parent bd8ba50 commit 2258d39

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

internal/app/gitops-commit/slackhttp/handler.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ import (
1111
)
1212

1313
const (
14-
SlackUnknownResponse = "Incorrect usage, expected /gitops-commit [command] [name] [tag]"
15-
SlackUnknownCommandResponse = "Unknown command '%s', expected /gitops-commit [command] [name] [tag]"
14+
SlackUnknownResponse = "Incorrect usage, unknown command"
15+
SlackDeployUnknownResponse = "Incorrect usage, expected /gitops-commit [command] [name] [tag]"
1616
)
1717

1818
func (s *server) handleSlackCommand(registry *NamedRepositoryRegistry) func(http.ResponseWriter, slack.SlashCommand) {
1919
return func(w http.ResponseWriter, sl slack.SlashCommand) {
2020
text := strings.Split(sl.Text, " ")
2121

22-
if len(text) < 3 || len(text) > 3 {
23-
respondSlack(SlackUnknownResponse, slack.ResponseTypeEphemeral, w)
22+
if len(text) < 1 {
23+
respondSlack(SlackDeployUnknownResponse, slack.ResponseTypeEphemeral, w)
2424

2525
return
2626
}
@@ -29,19 +29,33 @@ func (s *server) handleSlackCommand(registry *NamedRepositoryRegistry) func(http
2929

3030
switch command {
3131
case "deploy":
32+
if len(text) < 3 || len(text) > 3 {
33+
respondSlack(SlackDeployUnknownResponse, slack.ResponseTypeEphemeral, w)
34+
35+
return
36+
}
37+
3238
deploy(s, w, registry, text[1], text[2])
3339

40+
return
41+
case "show":
42+
show(w, registry)
43+
3444
return
3545
default:
3646
respondSlack(
37-
fmt.Sprintf(SlackUnknownCommandResponse, command),
47+
SlackUnknownResponse,
3848
slack.ResponseTypeEphemeral,
3949
w,
4050
)
4151
}
4252
}
4353
}
4454

55+
func show(w http.ResponseWriter, registry *NamedRepositoryRegistry) {
56+
respondSlack(fmt.Sprintf("Manifest options: %s", registry.getNamesFlattened()), slack.ResponseTypeInChannel, w)
57+
}
58+
4559
func deploy(s *server, w http.ResponseWriter, registry *NamedRepositoryRegistry, name string, version string) {
4660
r, err := registry.findNamedRepository(name)
4761

internal/app/gitops-commit/slackhttp/handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ func Test_handleSlackCommand(t *testing.T) {
2121
{
2222
name: "when using missing bits",
2323
command: "totally wrong",
24-
expect: "Incorrect usage, expected /gitops-commit [command] [name] [tag]",
24+
expect: "Incorrect usage, unknown command",
2525
},
2626
{
2727
name: "when using an invalid command",
2828
command: "wrong thing v1.2.3",
29-
expect: "Unknown command 'wrong', expected /gitops-commit [command] [name] [tag]",
29+
expect: "Incorrect usage, unknown command",
3030
},
3131
{
3232
name: "when using a valid command ",

0 commit comments

Comments
 (0)