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

105 lines
2.4 KiB
Go

package plugin
import (
"encoding/json"
"fmt"
"net/http"
"github.com/mattermost/mattermost/server/public/model"
)
func (p *Plugin) handleDialogSubmit(w http.ResponseWriter, r *http.Request) {
var req model.SubmitDialogRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
if req.CallbackId != "sentry_setup" {
w.WriteHeader(http.StatusOK)
return
}
sub := req.Submission
projectSlug := sub["project_slug"].(string)
channelID := sub["default_channel_id"].(string)
hooks := HookSettings{
EventAlert: getBool(sub, "hook_event_alert", true),
MetricAlert: getBool(sub, "hook_metric_alert", true),
Issue: getBool(sub, "hook_issue", true),
Comment: getBool(sub, "hook_comment", true),
}
project, err := p.linkProjectToChannel(projectSlug, channelID, hooks)
if err != nil {
p.API.SendEphemeralPost(req.UserId, &model.Post{
ChannelId: channelID,
Message: "❌ " + err.Error(),
})
return
}
p.API.SendEphemeralPost(req.UserId, &model.Post{
ChannelId: channelID,
Message: fmt.Sprintf(
"✅ Linked **%s** (`%s`)\nHooks: event=%v, metric=%v, issue=%v, comment=%v",
project.Name,
project.Slug,
hooks.EventAlert,
hooks.MetricAlert,
hooks.Issue,
hooks.Comment,
),
})
}
func (p *Plugin) openEventAlertSetup(
args *model.CommandArgs,
project *LinkedProject,
) (*model.CommandResponse, *model.AppError) {
if args.TriggerId == "" {
return ephemeral("This command must be run from UI"), nil
}
return ephemeral("🛠 Event alert setup is not implemented yet"), nil
}
func (p *Plugin) openMetricAlertSetup(
args *model.CommandArgs,
project *LinkedProject,
) (*model.CommandResponse, *model.AppError) {
if args.TriggerId == "" {
return ephemeral("This command must be run from UI"), nil
}
return ephemeral("🛠 Metric alert setup is not implemented yet"), nil
}
func (p *Plugin) openIssueSetup(
args *model.CommandArgs,
project *LinkedProject,
) (*model.CommandResponse, *model.AppError) {
if args.TriggerId == "" {
return ephemeral("This command must be run from UI"), nil
}
return ephemeral("🛠 Issue setup is not implemented yet"), nil
}
func (p *Plugin) openCommentSetup(
args *model.CommandArgs,
project *LinkedProject,
) (*model.CommandResponse, *model.AppError) {
if args.TriggerId == "" {
return ephemeral("This command must be run from UI"), nil
}
return ephemeral("🛠 Comment setup is not implemented yet"), nil
}