Help us shape the future of Go! Take the 2026 Go Developer Survey

webhook

package
v1.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 57 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxNotificationTemplateSize bounds templates stored in webhook metadata.
	MaxNotificationTemplateSize = 16 * 1024
)

Variables

This section is empty.

Functions

func Deliver

func Deliver(ctx context.Context, t *webhook_model.HookTask) error

Deliver creates the http.Request (depending on the webhook type), sends it and records the status and response.

func Init

func Init() error

Init starts the hooks delivery thread

func IsValidHookTaskType

func IsValidHookTaskType(name string) bool

IsValidHookTaskType returns true if a webhook registered

func IsValidSlackChannel

func IsValidSlackChannel(name string) bool

func MatrixLinkToRef

func MatrixLinkToRef(repoURL, ref string) string

MatrixLinkToRef Matrix-formatter link to a repo ref

func NewNotifier

func NewNotifier() notify_service.Notifier

NewNotifier create a new webhookNotifier notifier

func NotificationConfigMeta added in v1.7.0

func NotificationConfigMeta(kind webhook_module.HookType, existing string, config map[string]string) (string, error)

NotificationConfigMeta merges API edits without dropping channel credentials or routing policy.

func NotificationMatches added in v1.7.0

func NotificationMatches(settings NotificationSettings, payloadJSON []byte) (bool, error)

func NotificationMeta added in v1.7.0

func NotificationMeta(meta any, settings NotificationSettings) (string, error)

func NotificationWebhookSupported added in v1.7.0

func NotificationWebhookSupported(kind webhook_module.HookType) bool

func PrepareTestWebhook added in v1.3.0

func PrepareTestWebhook(ctx context.Context, w *webhook_model.Webhook, event webhook_module.HookEventType, p api.Payloader) error

PrepareTestWebhook always creates and enqueues a hook task for manual testing. Unlike PrepareWebhook, it ignores event subscriptions and branch filters so the Test Push Event control can verify delivery even when those gates would suppress a real event.

func PrepareWebhook

PrepareWebhook creates a hook task and enqueues it for processing. The payload is saved as-is. The adjustments depending on the webhook type happen right before delivery, in the Deliver method.

func PrepareWebhooks

func PrepareWebhooks(ctx context.Context, source EventSource, event webhook_module.HookEventType, p api.Payloader) error

PrepareWebhooks adds new webhooks to task queue for given payload.

func RegisterWebhookRequester

func RegisterWebhookRequester(hookType webhook_module.HookType, requester Requester)

func ReplayHookTask

func ReplayHookTask(ctx context.Context, w *webhook_model.Webhook, uuid string) error

ReplayHookTask replays a webhook task

func SlackLinkFormatter

func SlackLinkFormatter(url, text string) string

SlackLinkFormatter creates a link compatible with slack

func SlackLinkToRef

func SlackLinkToRef(repoURL, ref string) string

SlackLinkToRef slack-formatter link to a repo ref

func SlackShortTextFormatter

func SlackShortTextFormatter(s string) string

SlackShortTextFormatter replaces &, <, > with HTML characters

func SlackTextFormatter

func SlackTextFormatter(s string) string

SlackTextFormatter replaces &, <, > with HTML characters see: https://api.slack.com/docs/formatting

func ToHook

func ToHook(repoLink string, w *webhook_model.Webhook) (*api.Hook, error)

ToHook convert models.Webhook to api.Hook This function is not part of the convert package to prevent an import cycle

func ValidateNotificationTemplate

func ValidateNotificationTemplate(source string) error

ValidateNotificationTemplate checks syntax without executing the template.

Types

type DingtalkPayload

type DingtalkPayload dingtalk.Payload

type DiscordEmbed

type DiscordEmbed struct {
	Title       string              `json:"title"`
	Description string              `json:"description"`
	URL         string              `json:"url"`
	Color       int                 `json:"color"`
	Footer      DiscordEmbedFooter  `json:"footer"`
	Author      DiscordEmbedAuthor  `json:"author"`
	Fields      []DiscordEmbedField `json:"fields"`
}

DiscordEmbed is for Embed Structure

type DiscordEmbedAuthor

type DiscordEmbedAuthor struct {
	Name    string `json:"name"`
	URL     string `json:"url"`
	IconURL string `json:"icon_url"`
}

DiscordEmbedAuthor for Embed Author Structure

type DiscordEmbedField

type DiscordEmbedField struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

DiscordEmbedField for Embed Field Structure

type DiscordEmbedFooter

type DiscordEmbedFooter struct {
	Text string `json:"text"`
}

DiscordEmbedFooter for Embed Footer Structure.

type DiscordMeta

type DiscordMeta struct {
	Username string `json:"username"`
	IconURL  string `json:"icon_url"`
}

DiscordMeta contains the discord metadata

func GetDiscordHook

func GetDiscordHook(w *webhook_model.Webhook) *DiscordMeta

GetDiscordHook returns discord metadata

type DiscordPayload

type DiscordPayload struct {
	Wait      bool           `json:"wait"`
	Content   string         `json:"content"`
	Username  string         `json:"username,omitempty"`
	AvatarURL string         `json:"avatar_url,omitempty"`
	TTS       bool           `json:"tts"`
	Embeds    []DiscordEmbed `json:"embeds"`
}

DiscordPayload represents

type EventSource

type EventSource struct {
	Repository *repo_model.Repository
	Owner      *user_model.User
}

EventSource represents the source of a webhook action. Repository and/or Owner must be set.

type FeishuMeta

type FeishuMeta struct {
	MessageTemplate string `json:"message_template,omitempty"`
}

FeishuMeta contains gitsss-specific Feishu notification settings.

func GetFeishuHook

func GetFeishuHook(w *webhook_model.Webhook) *FeishuMeta

GetFeishuHook returns Feishu metadata.

type FeishuPayload

type FeishuPayload struct {
	Timestamp int64  `json:"timestamp,omitempty"` // Unix timestamp for signature verification
	Sign      string `json:"sign,omitempty"`      // Signature for verification
	MsgType   string `json:"msg_type"`            // text / post / image / share_chat / interactive / file /audio / media
	Content   struct {
		Text string `json:"text"`
	} `json:"content"`
}

FeishuPayload represents the payload for Feishu webhook

type MSTeamsAction

type MSTeamsAction struct {
	Type    string                `json:"@type"`
	Name    string                `json:"name"`
	Targets []MSTeamsActionTarget `json:"targets,omitempty"`
}

MSTeamsAction is an action (creates buttons, links etc)

type MSTeamsActionTarget

type MSTeamsActionTarget struct {
	Os  string `json:"os"`
	URI string `json:"uri"`
}

MSTeamsActionTarget is the actual link to follow, etc

type MSTeamsFact

type MSTeamsFact struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

MSTeamsFact for Fact Structure

type MSTeamsPayload

type MSTeamsPayload struct {
	Type            string           `json:"@type"`
	Context         string           `json:"@context"`
	ThemeColor      string           `json:"themeColor"`
	Title           string           `json:"title"`
	Summary         string           `json:"summary"`
	Sections        []MSTeamsSection `json:"sections"`
	PotentialAction []MSTeamsAction  `json:"potentialAction"`
}

MSTeamsPayload is the parent object

type MSTeamsSection

type MSTeamsSection struct {
	ActivityTitle    string        `json:"activityTitle"`
	ActivitySubtitle string        `json:"activitySubtitle"`
	ActivityImage    string        `json:"activityImage"`
	Facts            []MSTeamsFact `json:"facts"`
	Text             string        `json:"text"`
}

MSTeamsSection is a MessageCard section

type MatrixMeta

type MatrixMeta struct {
	HomeserverURL string `json:"homeserver_url"`
	Room          string `json:"room_id"`
	MessageType   int    `json:"message_type"`
}

MatrixMeta contains the Matrix metadata

func GetMatrixHook

func GetMatrixHook(w *webhook_model.Webhook) *MatrixMeta

GetMatrixHook returns Matrix metadata

type MatrixPayload

type MatrixPayload struct {
	Body          string               `json:"body"`
	MsgType       string               `json:"msgtype"`
	Format        string               `json:"format"`
	FormattedBody string               `json:"formatted_body"`
	Commits       []*api.PayloadCommit `json:"io.gitea.commits,omitempty"`
}

MatrixPayload contains payload for a Matrix room

type NotificationSettings added in v1.7.0

type NotificationSettings struct {
	Style                  string `json:"style,omitempty"`
	Language               string `json:"language,omitempty"`
	TitleTemplate          string `json:"title_template,omitempty"`
	MessageTemplate        string `json:"message_template,omitempty"`
	PayloadTemplate        string `json:"payload_template,omitempty"`
	Footer                 string `json:"footer,omitempty"`
	Color                  string `json:"color,omitempty"`
	FeishuHeaderColor      string `json:"feishu_header_color,omitempty"`
	FeishuRepositoryColors string `json:"feishu_repository_colors,omitempty"`
	MaxCommits             int    `json:"max_commits,omitempty"`
	IncludeFiles           bool   `json:"include_files"`
	IncludeCommitBody      bool   `json:"include_commit_body"`
	RepositoryFilter       string `json:"repository_filter,omitempty"`
	ExcludeRepository      string `json:"exclude_repository,omitempty"`
	ActorFilter            string `json:"actor_filter,omitempty"`
	SkipBots               bool   `json:"skip_bots"`
	EventPolicy            string `json:"event_policy,omitempty"`
	TagFilter              string `json:"tag_filter,omitempty"`
}

NotificationSettings is stored inside existing webhook metadata; routing and delivery IDs stay unchanged.

func GetNotificationSettings added in v1.7.0

func GetNotificationSettings(meta string) (NotificationSettings, error)

func (NotificationSettings) Validate added in v1.7.0

func (n NotificationSettings) Validate() error

func (NotificationSettings) ValidateForChannel added in v1.16.0

func (n NotificationSettings) ValidateForChannel(kind webhook_module.HookType) error

ValidateForChannel checks the provider envelope before storing a template.

type NotificationTemplateData

type NotificationTemplateData struct {
	Event   string
	Text    string
	Payload map[string]any
}

NotificationTemplateData is the sandboxed data available to notification templates.

type PackagistMeta

type PackagistMeta struct {
	Username   string `json:"username"`
	APIToken   string `json:"api_token"`
	PackageURL string `json:"package_url"`
}

PackagistMeta contains the metadata for the webhook

func GetPackagistHook

func GetPackagistHook(w *webhook_model.Webhook) *PackagistMeta

GetPackagistHook returns packagist metadata

type PackagistPayload

type PackagistPayload struct {
	PackagistRepository struct {
		URL string `json:"url"`
	} `json:"repository"`
}

PackagistPayload represents

type Requester

type Requester func(context.Context, *webhook_model.Webhook, *webhook_model.HookTask) (req *http.Request, body []byte, err error)

type SlackAttachment

type SlackAttachment struct {
	Fallback  string `json:"fallback"`
	Color     string `json:"color"`
	Title     string `json:"title"`
	TitleLink string `json:"title_link"`
	Text      string `json:"text"`
}

SlackAttachment contains the slack message

type SlackMeta

type SlackMeta struct {
	Channel  string `json:"channel"`
	Username string `json:"username"`
	IconURL  string `json:"icon_url"`
	Color    string `json:"color"`
}

SlackMeta contains the slack metadata

func GetSlackHook

func GetSlackHook(w *webhook_model.Webhook) *SlackMeta

GetSlackHook returns slack metadata

type SlackPayload

type SlackPayload struct {
	Channel     string            `json:"channel"`
	Text        string            `json:"text"`
	Username    string            `json:"username"`
	IconURL     string            `json:"icon_url"`
	UnfurlLinks int               `json:"unfurl_links"`
	LinkNames   int               `json:"link_names"`
	Attachments []SlackAttachment `json:"attachments"`
}

SlackPayload contains the information about the slack channel

type TelegramMeta

type TelegramMeta struct {
	BotToken string `json:"bot_token"`
	ChatID   string `json:"chat_id"`
	ThreadID string `json:"thread_id"`
}

TelegramMeta contains the telegram metadata

func GetTelegramHook

func GetTelegramHook(w *webhook_model.Webhook) *TelegramMeta

GetTelegramHook returns telegram metadata

type TelegramPayload

type TelegramPayload struct {
	Message           string `json:"text"`
	ParseMode         string `json:"parse_mode"`
	DisableWebPreview bool   `json:"disable_web_page_preview"`
}

TelegramPayload represents

type WechatworkPayload

type WechatworkPayload struct {
	Msgtype string `json:"msgtype"`
	Text    struct {
		Content             string   `json:"content"`
		MentionedList       []string `json:"mentioned_list"`
		MentionedMobileList []string `json:"mentioned_mobile_list"`
	} `json:"text"`
	Markdown struct {
		Content string `json:"content"`
	} `json:"markdown"`
}

WechatworkPayload represents

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL