summaryrefslogtreecommitdiffstats
path: root/services/webhook/slack.go
diff options
context:
space:
mode:
Diffstat (limited to 'services/webhook/slack.go')
-rw-r--r--services/webhook/slack.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/services/webhook/slack.go b/services/webhook/slack.go
index 11e1d3c081..e3d0d406de 100644
--- a/services/webhook/slack.go
+++ b/services/webhook/slack.go
@@ -7,6 +7,7 @@ package webhook
import (
"errors"
"fmt"
+ "regexp"
"strings"
webhook_model "code.gitea.io/gitea/models/webhook"
@@ -286,3 +287,13 @@ func GetSlackPayload(p api.Payloader, event webhook_model.HookEventType, meta st
return convertPayloader(s, p, event)
}
+
+var slackChannel = regexp.MustCompile(`^#?[a-z0-9_-]{1,80}$`)
+
+// IsValidSlackChannel validates a channel name conforms to what slack expects:
+// https://api.slack.com/methods/conversations.rename#naming
+// Conversation names can only contain lowercase letters, numbers, hyphens, and underscores, and must be 80 characters or less.
+// Gitea accepts if it starts with a #.
+func IsValidSlackChannel(name string) bool {
+ return slackChannel.MatchString(name)
+}