@@ -3,18 +3,24 @@ package slackhttp
33import (
44 "encoding/json"
55 "fmt"
6+ "github.com/google/martian/log"
67 "github.com/gsdevme/gitops-commit/internal/pkg/gitops"
78 "github.com/slack-go/slack"
89 "net/http"
910 "strings"
1011)
1112
13+ const (
14+ SlackUnknownResponse = "Incorrect usage, expected /gitops-commit [command] [name] [tag]"
15+ SlackUnknownCommandResponse = "Unknown command '%s', expected /gitops-commit [command] [name] [tag]"
16+ )
17+
1218func (s * server ) handleSlackCommand (registry * NamedRepositoryRegistry ) func (http.ResponseWriter , slack.SlashCommand ) {
1319 return func (w http.ResponseWriter , sl slack.SlashCommand ) {
1420 text := strings .Split (sl .Text , " " )
1521
1622 if len (text ) < 3 || len (text ) > 3 {
17- respondSlack ("Incorrect usage, expected /gitops-commit [command] [name] [tag]" , slack .ResponseTypeEphemeral , w )
23+ respondSlack (SlackUnknownResponse , slack .ResponseTypeEphemeral , w )
1824
1925 return
2026 }
@@ -28,7 +34,7 @@ func (s *server) handleSlackCommand(registry *NamedRepositoryRegistry) func(http
2834 return
2935 default :
3036 respondSlack (
31- fmt .Sprintf ("Unknown command %s, expected /gitops-commit [command] [name] [tag]" , command ),
37+ fmt .Sprintf (SlackUnknownCommandResponse , command ),
3238 slack .ResponseTypeEphemeral ,
3339 w ,
3440 )
@@ -73,7 +79,7 @@ func deploy(s *server, w http.ResponseWriter, registry *NamedRepositoryRegistry,
7379 go func () {
7480 err = gitops .DeployVersionHandler (command )
7581 if err != nil {
76- respondSlack ( fmt . Sprintf ("failed to deploy: %s " , err ), slack . ResponseTypeEphemeral , w )
82+ log . Errorf ("failed to deploy %w " , err )
7783
7884 return
7985 }
@@ -92,7 +98,6 @@ func respondSlack(m string, t string, w http.ResponseWriter) {
9298 ResponseType : t ,
9399 })
94100 if err != nil {
95- fmt .Println (err )
96101 w .WriteHeader (http .StatusInternalServerError )
97102 return
98103 }
0 commit comments