Skip to content

Commit

Permalink
Make Slack command name configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
kiootic committed Mar 5, 2024
1 parent 812b2ce commit 2329f6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
14 changes: 8 additions & 6 deletions pkg/slack/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import (
var repoRegex = regexp.MustCompile("[a-zA-Z0-9-]+(/[a-zA-Z0-9-]+)?")

type App struct {
logger *zap.Logger
disabled bool
api *slack.Client
store kv.Store
logger *zap.Logger
disabled bool
api *slack.Client
store kv.Store
commandName string
}

type ChannelInfo struct {
Expand All @@ -40,7 +41,8 @@ func NewApp(logger *zap.Logger, config *Config, store kv.Store) *App {
slack.OptionLog(zap.NewStdLog(logger)),
slack.OptionAppLevelToken(config.AppToken),
),
store: store,
store: store,
commandName: config.GetCommandName(),
}
}

Expand Down Expand Up @@ -194,7 +196,7 @@ func (a *App) messageLoop(ctx context.Context, client *socketmode.Client) {
zap.String("text", data.Text),
)

if data.Command != "/gha" {
if data.Command != "/"+a.commandName {
client.Ack(*e.Request, map[string]interface{}{
"text": fmt.Sprintf("Unknown command '%s'\n", data.Command)})
return
Expand Down
16 changes: 12 additions & 4 deletions pkg/slack/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package slack

import "github.com/oursky/github-actions-manager/pkg/kv"
import (
"github.com/oursky/github-actions-manager/pkg/kv"
"github.com/oursky/github-actions-manager/pkg/utils/defaults"
)

type Config struct {
Disabled bool
BotToken string `validate:"required_if=Disabled false"`
AppToken string `validate:"required_if=Disabled false"`
Disabled bool
BotToken string `validate:"required_if=Disabled false"`
AppToken string `validate:"required_if=Disabled false"`
CommandName *string
}

func (c *Config) GetCommandName() string {
return defaults.Value(c.CommandName, "gha")
}

var kvNamespace = kv.RegisterNamespace("slack-subscriptions")

0 comments on commit 2329f6e

Please sign in to comment.