webhook

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2020 License: MIT Imports: 28 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deliver

func Deliver(t *models.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 InitDeliverHooks

func InitDeliverHooks()

InitDeliverHooks starts the hooks delivery thread

func PrepareWebhook

func PrepareWebhook(w *models.Webhook, repo *models.Repository, event models.HookEventType, p api.Payloader) error

PrepareWebhook adds special webhook to task queue for given payload.

func PrepareWebhooks

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

PrepareWebhooks adds new webhooks to task queue for given payload.

func SlackLinkFormatter

func SlackLinkFormatter(url string, 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 GetDingtalkPayload

func GetDingtalkPayload(p api.Payloader, event models.HookEventType, meta string) (*DingtalkPayload, error)

GetDingtalkPayload converts a ding talk webhook into a DingtalkPayload

func (*DingtalkPayload) JSONPayload

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

JSONPayload Marshals the DingtalkPayload to json

func (*DingtalkPayload) SetSecret

func (p *DingtalkPayload) SetSecret(_ string)

SetSecret sets the dingtalk secret

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 *models.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 GetDiscordPayload

func GetDiscordPayload(p api.Payloader, event models.HookEventType, meta string) (*DiscordPayload, error)

GetDiscordPayload converts a discord webhook into a DiscordPayload

func (*DiscordPayload) JSONPayload

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

JSONPayload Marshals the DiscordPayload to json

func (*DiscordPayload) SetSecret

func (p *DiscordPayload) SetSecret(_ string)

SetSecret sets the discord secret

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 GetMSTeamsPayload

func GetMSTeamsPayload(p api.Payloader, event models.HookEventType, meta string) (*MSTeamsPayload, error)

GetMSTeamsPayload converts a MSTeams webhook into a MSTeamsPayload

func (*MSTeamsPayload) JSONPayload

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

JSONPayload Marshals the MSTeamsPayload to json

func (*MSTeamsPayload) SetSecret

func (p *MSTeamsPayload) SetSecret(_ string)

SetSecret sets the MSTeams secret

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 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 *models.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

func GetSlackPayload

func GetSlackPayload(p api.Payloader, event models.HookEventType, meta string) (*SlackPayload, error)

GetSlackPayload converts a slack webhook into a SlackPayload

func (*SlackPayload) JSONPayload

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

JSONPayload Marshals the SlackPayload to json

func (*SlackPayload) SetSecret

func (p *SlackPayload) SetSecret(_ string)

SetSecret sets the slack secret

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 *models.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 GetTelegramPayload

func GetTelegramPayload(p api.Payloader, event models.HookEventType, meta string) (*TelegramPayload, error)

GetTelegramPayload converts a telegram webhook into a TelegramPayload

func (*TelegramPayload) JSONPayload

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

JSONPayload Marshals the TelegramPayload to json

func (*TelegramPayload) SetSecret

func (p *TelegramPayload) SetSecret(_ string)

SetSecret sets the telegram secret

Jump to

Keyboard shortcuts

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