70 lines
1.5 KiB
Go
70 lines
1.5 KiB
Go
package plugin
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
"github.com/mattermost/mattermost/server/public/plugin"
|
|
)
|
|
|
|
func (p *Plugin) InitApi() {
|
|
p.router = mux.NewRouter()
|
|
p.router.HandleFunc("/webhook", p.handleWebhook).Methods("POST")
|
|
}
|
|
|
|
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
|
|
if !p.IsReady {
|
|
http.Error(w, "Plugin not ready", http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
|
|
p.router.ServeHTTP(w, r)
|
|
}
|
|
|
|
func (p *Plugin) registerCommands() error {
|
|
command := &model.Command{
|
|
Trigger: "sentry",
|
|
DisplayName: "Sentry",
|
|
Description: "Manage Sentry alerts and integrations",
|
|
AutoComplete: true,
|
|
AutoCompleteDesc: "Available commands: help, link, unlink, list",
|
|
AutoCompleteHint: "help | link <project> | unlink <project> | list",
|
|
}
|
|
|
|
if err := p.API.RegisterCommand(command); err != nil {
|
|
p.API.LogError("Failed to register Sentry command", "error", err.Error())
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (p *Plugin) ExecuteCommand(
|
|
ctx *plugin.Context,
|
|
args *model.CommandArgs,
|
|
) (*model.CommandResponse, *model.AppError) {
|
|
|
|
split := strings.Fields(args.Command)
|
|
if len(split) < 2 {
|
|
return p.commandHelp(), nil
|
|
}
|
|
|
|
switch split[1] {
|
|
case "setup":
|
|
return p.commandSetup(args)
|
|
case "link":
|
|
return p.commandLink(args, split)
|
|
case "unlink":
|
|
return p.commandUnlink(args, split)
|
|
case "list":
|
|
return p.commandList(args)
|
|
case "help":
|
|
fallthrough
|
|
default:
|
|
return p.commandHelp(), nil
|
|
}
|
|
|
|
}
|