@@ -3,18 +3,24 @@ package slackhttp
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "github.com/google/martian/log"
6
7
"github.com/gsdevme/gitops-commit/internal/pkg/gitops"
7
8
"github.com/slack-go/slack"
8
9
"net/http"
9
10
"strings"
10
11
)
11
12
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
+
12
18
func (s * server ) handleSlackCommand (registry * NamedRepositoryRegistry ) func (http.ResponseWriter , slack.SlashCommand ) {
13
19
return func (w http.ResponseWriter , sl slack.SlashCommand ) {
14
20
text := strings .Split (sl .Text , " " )
15
21
16
22
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 )
18
24
19
25
return
20
26
}
@@ -28,7 +34,7 @@ func (s *server) handleSlackCommand(registry *NamedRepositoryRegistry) func(http
28
34
return
29
35
default :
30
36
respondSlack (
31
- fmt .Sprintf ("Unknown command %s, expected /gitops-commit [command] [name] [tag]" , command ),
37
+ fmt .Sprintf (SlackUnknownCommandResponse , command ),
32
38
slack .ResponseTypeEphemeral ,
33
39
w ,
34
40
)
@@ -73,7 +79,7 @@ func deploy(s *server, w http.ResponseWriter, registry *NamedRepositoryRegistry,
73
79
go func () {
74
80
err = gitops .DeployVersionHandler (command )
75
81
if err != nil {
76
- respondSlack ( fmt . Sprintf ("failed to deploy: %s " , err ), slack . ResponseTypeEphemeral , w )
82
+ log . Errorf ("failed to deploy %w " , err )
77
83
78
84
return
79
85
}
@@ -92,7 +98,6 @@ func respondSlack(m string, t string, w http.ResponseWriter) {
92
98
ResponseType : t ,
93
99
})
94
100
if err != nil {
95
- fmt .Println (err )
96
101
w .WriteHeader (http .StatusInternalServerError )
97
102
return
98
103
}
0 commit comments