2026-01-23 20:54:16 +03:00

82 lines
1.6 KiB
Go

package plugin
import (
"encoding/json"
"errors"
"github.com/mattermost/mattermost/server/public/model"
)
type HookType string
const (
HookEventAlert HookType = "event_alert"
HookMetricAlert HookType = "metric_alert"
HookIssue HookType = "issue"
HookComment HookType = "comment"
)
func getBool(sub map[string]interface{}, key string, def bool) bool {
if v, ok := sub[key]; ok {
if s, ok := v.(string); ok {
return s == "true"
}
}
return def
}
func boolToStr(v bool) string {
if v {
return "true"
}
return "false"
}
func isHookEnabled(p *LinkedProject, hook HookType) bool {
switch hook {
case HookEventAlert:
return p.Hooks.EventAlert
case HookMetricAlert:
return p.Hooks.MetricAlert
case HookIssue:
return p.Hooks.Issue
case HookComment:
return p.Hooks.Comment
default:
return false
}
}
func (p *Plugin) getProjectByChannel(channelID string) (*LinkedProject, error) {
data, _ := p.API.KVGet("ru.loop.plugin.sentry:projects")
if data == nil {
return nil, errors.New("no projects linked")
}
var ids []string
_ = json.Unmarshal(data, &ids)
for _, id := range ids {
raw, _ := p.API.KVGet("ru.loop.plugin.sentry:project:" + id)
if raw == nil {
continue
}
var project LinkedProject
_ = json.Unmarshal(raw, &project)
if project.ChannelID == channelID {
return &project, nil
}
}
return nil, errors.New("no Sentry project linked to this channel")
}
func ephemeral(text string) *model.CommandResponse {
return &model.CommandResponse{
ResponseType: model.CommandResponseTypeEphemeral,
Text: text,
}
}