webhook

package
v1.16.8 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 32 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deliver

func Deliver(t *webhook_model.HookTask) error

Deliver deliver hook task

func DeliverHooks

func DeliverHooks(ctx context.Context)

DeliverHooks checks and delivers undelivered hooks. FIXME: graceful: This would likely benefit from either a worker pool with dummy queue or a full queue. Then more hooks could be sent at same time.

func GetDingtalkPayload

func GetDingtalkPayload(p api.Payloader, event webhook_model.HookEventType, meta string) (api.Payloader, error)

GetDingtalkPayload converts a ding talk webhook into a DingtalkPayload

func GetDiscordPayload

func GetDiscordPayload(p api.Payloader, event webhook_model.HookEventType, meta string) (api.Payloader, error)

GetDiscordPayload converts a discord webhook into a DiscordPayload

func GetFeishuPayload

func GetFeishuPayload(p api.Payloader, event webhook_model.HookEventType, meta string) (api.Payloader, error)

GetFeishuPayload converts a ding talk webhook into a FeishuPayload

func GetMSTeamsPayload

func GetMSTeamsPayload(p api.Payloader, event webhook_model.HookEventType, meta string) (api.Payloader, error)

GetMSTeamsPayload converts a MSTeams webhook into a MSTeamsPayload

func GetMatrixPayload

func GetMatrixPayload(p api.Payloader, event webhook_model.HookEventType, meta string) (api.Payloader, error)

GetMatrixPayload converts a Matrix webhook into a MatrixPayloadUnsafe

func GetSlackPayload

func GetSlackPayload(p api.Payloader, event webhook_model.HookEventType, meta string) (api.Payloader, error)

GetSlackPayload converts a slack webhook into a SlackPayload

func GetTelegramPayload

func GetTelegramPayload(p api.Payloader, event webhook_model.HookEventType, meta string) (api.Payloader, error)

GetTelegramPayload converts a telegram webhook into a TelegramPayload

func GetWechatworkPayload added in v1.16.0

func GetWechatworkPayload(p api.Payloader, event webhook_model.HookEventType, meta string) (api.Payloader, error)

GetWechatworkPayload GetWechatworkPayload converts a ding talk webhook into a WechatworkPayload

func InitDeliverHooks

func InitDeliverHooks()

InitDeliverHooks starts the hooks delivery thread

func IsValidHookTaskType

func IsValidHookTaskType(name string) bool

IsValidHookTaskType returns true if a webhook registered

func MatrixLinkFormatter

func MatrixLinkFormatter(url, text string) string

MatrixLinkFormatter creates a link compatible with Matrix

func MatrixLinkToRef

func MatrixLinkToRef(repoURL, ref string) string

MatrixLinkToRef Matrix-formatter link to a repo ref

func PrepareWebhook

PrepareWebhook adds special webhook to task queue for given payload.

func PrepareWebhooks

func PrepareWebhooks(repo *repo_model.Repository, event webhook_model.HookEventType, p api.Payloader) error

PrepareWebhooks adds new webhooks to task queue for given payload.

func RegisterWebhook

func RegisterWebhook(name string, webhook *webhook)

RegisterWebhook registers a webhook

func ReplayHookTask added in v1.16.0

func ReplayHookTask(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

Types

type DingtalkPayload

type DingtalkPayload dingtalk.Payload

DingtalkPayload represents

func (*DingtalkPayload) Create

Create implements PayloadConvertor Create method

func (*DingtalkPayload) Delete

Delete implements PayloadConvertor Delete method

func (*DingtalkPayload) Fork

Fork implements PayloadConvertor Fork method

func (*DingtalkPayload) Issue

Issue implements PayloadConvertor Issue method

func (*DingtalkPayload) IssueComment

func (d *DingtalkPayload) IssueComment(p *api.IssueCommentPayload) (api.Payloader, error)

IssueComment implements PayloadConvertor IssueComment method

func (*DingtalkPayload) JSONPayload

func (d *DingtalkPayload) JSONPayload() ([]byte, error)

JSONPayload Marshals the DingtalkPayload to json

func (*DingtalkPayload) PullRequest

func (d *DingtalkPayload) PullRequest(p *api.PullRequestPayload) (api.Payloader, error)

PullRequest implements PayloadConvertor PullRequest method

func (*DingtalkPayload) Push

Push implements PayloadConvertor Push method

func (*DingtalkPayload) Release

Release implements PayloadConvertor Release method

func (*DingtalkPayload) Repository

func (d *DingtalkPayload) Repository(p *api.RepositoryPayload) (api.Payloader, error)

Repository implements PayloadConvertor Repository method

func (*DingtalkPayload) Review

Review implements PayloadConvertor Review method

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"`
	AvatarURL string         `json:"avatar_url"`
	TTS       bool           `json:"tts"`
	Embeds    []DiscordEmbed `json:"embeds"`
}

DiscordPayload represents

func (*DiscordPayload) Create

Create implements PayloadConvertor Create method

func (*DiscordPayload) Delete

Delete implements PayloadConvertor Delete method

func (*DiscordPayload) Fork

Fork implements PayloadConvertor Fork method

func (*DiscordPayload) Issue

Issue implements PayloadConvertor Issue method

func (*DiscordPayload) IssueComment

func (d *DiscordPayload) IssueComment(p *api.IssueCommentPayload) (api.Payloader, error)

IssueComment implements PayloadConvertor IssueComment method

func (*DiscordPayload) JSONPayload

func (d *DiscordPayload) JSONPayload() ([]byte, error)

JSONPayload Marshals the DiscordPayload to json

func (*DiscordPayload) PullRequest

func (d *DiscordPayload) PullRequest(p *api.PullRequestPayload) (api.Payloader, error)

PullRequest implements PayloadConvertor PullRequest method

func (*DiscordPayload) Push

Push implements PayloadConvertor Push method

func (*DiscordPayload) Release

func (d *DiscordPayload) Release(p *api.ReleasePayload) (api.Payloader, error)

Release implements PayloadConvertor Release method

func (*DiscordPayload) Repository

func (d *DiscordPayload) Repository(p *api.RepositoryPayload) (api.Payloader, error)

Repository implements PayloadConvertor Repository method

func (*DiscordPayload) Review

Review implements PayloadConvertor Review method

type FeishuPayload

type FeishuPayload struct {
	MsgType string `json:"msg_type"` // text / post / image / share_chat / interactive
	Content struct {
		Text string `json:"text"`
	} `json:"content"`
}

FeishuPayload represents

func (*FeishuPayload) Create

func (f *FeishuPayload) Create(p *api.CreatePayload) (api.Payloader, error)

Create implements PayloadConvertor Create method

func (*FeishuPayload) Delete

func (f *FeishuPayload) Delete(p *api.DeletePayload) (api.Payloader, error)

Delete implements PayloadConvertor Delete method

func (*FeishuPayload) Fork

Fork implements PayloadConvertor Fork method

func (*FeishuPayload) Issue

func (f *FeishuPayload) Issue(p *api.IssuePayload) (api.Payloader, error)

Issue implements PayloadConvertor Issue method

func (*FeishuPayload) IssueComment

func (f *FeishuPayload) IssueComment(p *api.IssueCommentPayload) (api.Payloader, error)

IssueComment implements PayloadConvertor IssueComment method

func (*FeishuPayload) JSONPayload

func (f *FeishuPayload) JSONPayload() ([]byte, error)

JSONPayload Marshals the FeishuPayload to json

func (*FeishuPayload) PullRequest

func (f *FeishuPayload) PullRequest(p *api.PullRequestPayload) (api.Payloader, error)

PullRequest implements PayloadConvertor PullRequest method

func (*FeishuPayload) Push

Push implements PayloadConvertor Push method

func (*FeishuPayload) Release

func (f *FeishuPayload) Release(p *api.ReleasePayload) (api.Payloader, error)

Release implements PayloadConvertor Release method

func (*FeishuPayload) Repository

func (f *FeishuPayload) Repository(p *api.RepositoryPayload) (api.Payloader, error)

Repository implements PayloadConvertor Repository method

func (*FeishuPayload) Review

Review implements PayloadConvertor Review method

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

func (*MSTeamsPayload) Create

Create implements PayloadConvertor Create method

func (*MSTeamsPayload) Delete

Delete implements PayloadConvertor Delete method

func (*MSTeamsPayload) Fork

Fork implements PayloadConvertor Fork method

func (*MSTeamsPayload) Issue

Issue implements PayloadConvertor Issue method

func (*MSTeamsPayload) IssueComment

func (m *MSTeamsPayload) IssueComment(p *api.IssueCommentPayload) (api.Payloader, error)

IssueComment implements PayloadConvertor IssueComment method

func (*MSTeamsPayload) JSONPayload

func (m *MSTeamsPayload) JSONPayload() ([]byte, error)

JSONPayload Marshals the MSTeamsPayload to json

func (*MSTeamsPayload) PullRequest

func (m *MSTeamsPayload) PullRequest(p *api.PullRequestPayload) (api.Payloader, error)

PullRequest implements PayloadConvertor PullRequest method

func (*MSTeamsPayload) Push

Push implements PayloadConvertor Push method

func (*MSTeamsPayload) Release

func (m *MSTeamsPayload) Release(p *api.ReleasePayload) (api.Payloader, error)

Release implements PayloadConvertor Release method

func (*MSTeamsPayload) Repository

func (m *MSTeamsPayload) Repository(p *api.RepositoryPayload) (api.Payloader, error)

Repository implements PayloadConvertor Repository method

func (*MSTeamsPayload) Review

Review implements PayloadConvertor Review method

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"`
	AccessToken   string `json:"access_token"`
	MessageType   int    `json:"message_type"`
}

MatrixMeta contains the Matrix metadata

func GetMatrixHook

func GetMatrixHook(w *webhook_model.Webhook) *MatrixMeta

GetMatrixHook returns Matrix metadata

type MatrixPayloadSafe

type MatrixPayloadSafe 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"`
}

MatrixPayloadSafe contains (safe) payload for a Matrix room

type MatrixPayloadUnsafe

type MatrixPayloadUnsafe struct {
	MatrixPayloadSafe
	AccessToken string `json:"access_token"`
}

MatrixPayloadUnsafe contains the (unsafe) payload for a Matrix room

func (*MatrixPayloadUnsafe) Create

Create implements PayloadConvertor Create method

func (*MatrixPayloadUnsafe) Delete

Delete composes Matrix payload for delete a branch or tag.

func (*MatrixPayloadUnsafe) Fork

Fork composes Matrix payload for forked by a repository.

func (*MatrixPayloadUnsafe) Issue

Issue implements PayloadConvertor Issue method

func (*MatrixPayloadUnsafe) IssueComment

IssueComment implements PayloadConvertor IssueComment method

func (*MatrixPayloadUnsafe) JSONPayload

func (m *MatrixPayloadUnsafe) JSONPayload() ([]byte, error)

JSONPayload Marshals the MatrixPayloadUnsafe to json

func (*MatrixPayloadUnsafe) PullRequest

PullRequest implements PayloadConvertor PullRequest method

func (*MatrixPayloadUnsafe) Push

Push implements PayloadConvertor Push method

func (*MatrixPayloadUnsafe) Release

Release implements PayloadConvertor Release method

func (*MatrixPayloadUnsafe) Repository

Repository implements PayloadConvertor Repository method

func (*MatrixPayloadUnsafe) Review

Review implements PayloadConvertor Review method

type PayloadConvertor

PayloadConvertor defines the interface to convert system webhook payload to external payload

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"`
	Color       string            `json:"-"`
	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

func (*SlackPayload) Create

func (s *SlackPayload) Create(p *api.CreatePayload) (api.Payloader, error)

Create implements PayloadConvertor Create method

func (*SlackPayload) Delete

func (s *SlackPayload) Delete(p *api.DeletePayload) (api.Payloader, error)

Delete composes Slack payload for delete a branch or tag.

func (*SlackPayload) Fork

func (s *SlackPayload) Fork(p *api.ForkPayload) (api.Payloader, error)

Fork composes Slack payload for forked by a repository.

func (*SlackPayload) Issue

func (s *SlackPayload) Issue(p *api.IssuePayload) (api.Payloader, error)

Issue implements PayloadConvertor Issue method

func (*SlackPayload) IssueComment

func (s *SlackPayload) IssueComment(p *api.IssueCommentPayload) (api.Payloader, error)

IssueComment implements PayloadConvertor IssueComment method

func (*SlackPayload) JSONPayload

func (s *SlackPayload) JSONPayload() ([]byte, error)

JSONPayload Marshals the SlackPayload to json

func (*SlackPayload) PullRequest

func (s *SlackPayload) PullRequest(p *api.PullRequestPayload) (api.Payloader, error)

PullRequest implements PayloadConvertor PullRequest method

func (*SlackPayload) Push

func (s *SlackPayload) Push(p *api.PushPayload) (api.Payloader, error)

Push implements PayloadConvertor Push method

func (*SlackPayload) Release

func (s *SlackPayload) Release(p *api.ReleasePayload) (api.Payloader, error)

Release implements PayloadConvertor Release method

func (*SlackPayload) Repository

func (s *SlackPayload) Repository(p *api.RepositoryPayload) (api.Payloader, error)

Repository implements PayloadConvertor Repository method

func (*SlackPayload) Review

Review implements PayloadConvertor Review method

type TelegramMeta

type TelegramMeta struct {
	BotToken string `json:"bot_token"`
	ChatID   string `json:"chat_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

func (*TelegramPayload) Create

Create implements PayloadConvertor Create method

func (*TelegramPayload) Delete

Delete implements PayloadConvertor Delete method

func (*TelegramPayload) Fork

Fork implements PayloadConvertor Fork method

func (*TelegramPayload) Issue

Issue implements PayloadConvertor Issue method

func (*TelegramPayload) IssueComment

func (t *TelegramPayload) IssueComment(p *api.IssueCommentPayload) (api.Payloader, error)

IssueComment implements PayloadConvertor IssueComment method

func (*TelegramPayload) JSONPayload

func (t *TelegramPayload) JSONPayload() ([]byte, error)

JSONPayload Marshals the TelegramPayload to json

func (*TelegramPayload) PullRequest

func (t *TelegramPayload) PullRequest(p *api.PullRequestPayload) (api.Payloader, error)

PullRequest implements PayloadConvertor PullRequest method

func (*TelegramPayload) Push

Push implements PayloadConvertor Push method

func (*TelegramPayload) Release

Release implements PayloadConvertor Release method

func (*TelegramPayload) Repository

func (t *TelegramPayload) Repository(p *api.RepositoryPayload) (api.Payloader, error)

Repository implements PayloadConvertor Repository method

func (*TelegramPayload) Review

Review implements PayloadConvertor Review method

type WechatworkPayload added in v1.16.0

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

func (*WechatworkPayload) Create added in v1.16.0

Create implements PayloadConvertor Create method

func (*WechatworkPayload) Delete added in v1.16.0

Delete implements PayloadConvertor Delete method

func (*WechatworkPayload) Fork added in v1.16.0

Fork implements PayloadConvertor Fork method

func (*WechatworkPayload) Issue added in v1.16.0

Issue implements PayloadConvertor Issue method

func (*WechatworkPayload) IssueComment added in v1.16.0

IssueComment implements PayloadConvertor IssueComment method

func (*WechatworkPayload) JSONPayload added in v1.16.0

func (f *WechatworkPayload) JSONPayload() ([]byte, error)

JSONPayload Marshals the WechatworkPayload to json

func (*WechatworkPayload) PullRequest added in v1.16.0

PullRequest implements PayloadConvertor PullRequest method

func (*WechatworkPayload) Push added in v1.16.0

Push implements PayloadConvertor Push method

func (*WechatworkPayload) Release added in v1.16.0

Release implements PayloadConvertor Release method

func (*WechatworkPayload) Repository added in v1.16.0

Repository implements PayloadConvertor Repository method

func (*WechatworkPayload) Review added in v1.16.0

Review implements PayloadConvertor Review method

func (*WechatworkPayload) SetSecret added in v1.16.0

func (f *WechatworkPayload) SetSecret(_ string)

SetSecret sets the Wechatwork secret

Jump to

Keyboard shortcuts

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