webhook

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupHookTaskTable

func CleanupHookTaskTable(ctx context.Context, cleanupType HookTaskCleanupType, olderThan time.Duration, numberToKeep int) error

CleanupHookTaskTable deletes rows from hook_task as needed.

func CopyDefaultWebhooksToRepo

func CopyDefaultWebhooksToRepo(ctx context.Context, repoID int64) error

CopyDefaultWebhooksToRepo creates copies of the default webhooks in a new repo

func CountWebhooksByOpts

func CountWebhooksByOpts(opts *ListWebhookOptions) (int64, error)

CountWebhooksByOpts count webhooks based on options and ignore pagination

func CreateWebhook

func CreateWebhook(ctx context.Context, w *Webhook) error

CreateWebhook creates a new web hook.

func CreateWebhooks

func CreateWebhooks(ctx context.Context, ws []*Webhook) error

CreateWebhooks creates multiple web hooks

func DeleteDefaultSystemWebhook

func DeleteDefaultSystemWebhook(ctx context.Context, id int64) error

DeleteDefaultSystemWebhook deletes an admin-configured default or system webhook (where Org and Repo ID both 0)

func DeleteWebhookByOwnerID

func DeleteWebhookByOwnerID(ownerID, id int64) error

DeleteWebhookByOwnerID deletes webhook of a user or organization by given ID.

func DeleteWebhookByRepoID

func DeleteWebhookByRepoID(repoID, id int64) error

DeleteWebhookByRepoID deletes webhook of repository by given ID.

func FindUndeliveredHookTaskIDs

func FindUndeliveredHookTaskIDs(ctx context.Context, lowerID int64) ([]int64, error)

FindUndeliveredHookTaskIDs will find the next 100 undelivered hook tasks with ID greater than the provided lowerID

func IsErrHookTaskNotExist

func IsErrHookTaskNotExist(err error) bool

IsErrHookTaskNotExist checks if an error is a ErrHookTaskNotExist.

func IsErrWebhookNotExist

func IsErrWebhookNotExist(err error) bool

IsErrWebhookNotExist checks if an error is a ErrWebhookNotExist.

func IsValidHookContentType

func IsValidHookContentType(name string) bool

IsValidHookContentType returns true if given name is a valid hook content type.

func MarkTaskDelivered

func MarkTaskDelivered(ctx context.Context, task *HookTask) (bool, error)

func UpdateHookTask

func UpdateHookTask(t *HookTask) error

UpdateHookTask updates information of hook task.

func UpdateWebhook

func UpdateWebhook(w *Webhook) error

UpdateWebhook updates information of webhook.

func UpdateWebhookLastStatus

func UpdateWebhookLastStatus(w *Webhook) error

UpdateWebhookLastStatus updates last status of webhook.

Types

type ErrHookTaskNotExist

type ErrHookTaskNotExist struct {
	TaskID int64
	HookID int64
	UUID   string
}

ErrHookTaskNotExist represents a "HookTaskNotExist" kind of error.

func (ErrHookTaskNotExist) Error

func (err ErrHookTaskNotExist) Error() string

func (ErrHookTaskNotExist) Unwrap

func (err ErrHookTaskNotExist) Unwrap() error

type ErrWebhookNotExist

type ErrWebhookNotExist struct {
	ID int64
}

ErrWebhookNotExist represents a "WebhookNotExist" kind of error.

func (ErrWebhookNotExist) Error

func (err ErrWebhookNotExist) Error() string

func (ErrWebhookNotExist) Unwrap

func (err ErrWebhookNotExist) Unwrap() error

type HookContentType

type HookContentType int

HookContentType is the content type of a web hook

const (
	// ContentTypeJSON is a JSON payload for web hooks
	ContentTypeJSON HookContentType = iota + 1
	// ContentTypeForm is an url-encoded form payload for web hook
	ContentTypeForm
)

func ToHookContentType

func ToHookContentType(name string) HookContentType

ToHookContentType returns HookContentType by given name.

func (HookContentType) Name

func (t HookContentType) Name() string

Name returns the name of a given web hook's content type

type HookRequest

type HookRequest struct {
	URL        string            `json:"url"`
	HTTPMethod string            `json:"http_method"`
	Headers    map[string]string `json:"headers"`
}

HookRequest represents hook task request information.

type HookResponse

type HookResponse struct {
	Status  int               `json:"status"`
	Headers map[string]string `json:"headers"`
	Body    string            `json:"body"`
}

HookResponse represents hook task response information.

type HookTask

type HookTask struct {
	ID             int64  `xorm:"pk autoincr"`
	HookID         int64  `xorm:"index"`
	UUID           string `xorm:"unique"`
	api.Payloader  `xorm:"-"`
	PayloadContent string `xorm:"LONGTEXT"`
	EventType      webhook_module.HookEventType
	IsDelivered    bool
	Delivered      timeutil.TimeStampNano

	// History info.
	IsSucceed       bool
	RequestContent  string        `xorm:"LONGTEXT"`
	RequestInfo     *HookRequest  `xorm:"-"`
	ResponseContent string        `xorm:"LONGTEXT"`
	ResponseInfo    *HookResponse `xorm:"-"`
}

HookTask represents a hook task.

func CreateHookTask

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

CreateHookTask creates a new hook task, it handles conversion from Payload to PayloadContent.

func GetHookTaskByID

func GetHookTaskByID(ctx context.Context, id int64) (*HookTask, error)

func HookTasks

func HookTasks(hookID int64, page int) ([]*HookTask, error)

HookTasks returns a list of hook tasks by given conditions.

func ReplayHookTask

func ReplayHookTask(ctx context.Context, hookID int64, uuid string) (*HookTask, error)

ReplayHookTask copies a hook task to get re-delivered

func (*HookTask) AfterLoad

func (t *HookTask) AfterLoad()

AfterLoad updates the webhook object upon setting a column

func (*HookTask) BeforeUpdate

func (t *HookTask) BeforeUpdate()

BeforeUpdate will be invoked by XORM before updating a record representing this object

type HookTaskCleanupType

type HookTaskCleanupType int

HookTaskCleanupType is the type of cleanup to perform on hook_task

const (
	// OlderThan hook_task rows will be cleaned up by the age of the row
	OlderThan HookTaskCleanupType = iota
	// PerWebhook hook_task rows will be cleaned up by leaving the most recent deliveries for each webhook
	PerWebhook
)

func ToHookTaskCleanupType

func ToHookTaskCleanupType(name string) HookTaskCleanupType

ToHookTaskCleanupType returns HookTaskCleanupType by given name.

type ListWebhookOptions

type ListWebhookOptions struct {
	db.ListOptions
	RepoID   int64
	OwnerID  int64
	IsActive util.OptionalBool
}

ListWebhookOptions are options to filter webhooks on ListWebhooksByOpts

type Webhook

type Webhook struct {
	ID                        int64 `xorm:"pk autoincr"`
	RepoID                    int64 `xorm:"INDEX"` // An ID of 0 indicates either a default or system webhook
	OwnerID                   int64 `xorm:"INDEX"`
	IsSystemWebhook           bool
	URL                       string `xorm:"url TEXT"`
	HTTPMethod                string `xorm:"http_method"`
	ContentType               HookContentType
	Secret                    string `xorm:"TEXT"`
	Events                    string `xorm:"TEXT"`
	*webhook_module.HookEvent `xorm:"-"`
	IsActive                  bool                      `xorm:"INDEX"`
	Type                      webhook_module.HookType   `xorm:"VARCHAR(16) 'type'"`
	Meta                      string                    `xorm:"TEXT"` // store hook-specific attributes
	LastStatus                webhook_module.HookStatus // Last delivery status

	// HeaderAuthorizationEncrypted should be accessed using HeaderAuthorization() and SetHeaderAuthorization()
	HeaderAuthorizationEncrypted string `xorm:"TEXT"`

	CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
	UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
}

Webhook represents a web hook object.

func GetDefaultWebhooks

func GetDefaultWebhooks(ctx context.Context) ([]*Webhook, error)

GetDefaultWebhooks returns all admin-default webhooks.

func GetSystemOrDefaultWebhook

func GetSystemOrDefaultWebhook(ctx context.Context, id int64) (*Webhook, error)

GetSystemOrDefaultWebhook returns admin system or default webhook by given ID.

func GetSystemWebhooks

func GetSystemWebhooks(ctx context.Context, isActive util.OptionalBool) ([]*Webhook, error)

GetSystemWebhooks returns all admin system webhooks.

func GetWebhookByID

func GetWebhookByID(id int64) (*Webhook, error)

GetWebhookByID returns webhook of repository by given ID.

func GetWebhookByOwnerID

func GetWebhookByOwnerID(ownerID, id int64) (*Webhook, error)

GetWebhookByOwnerID returns webhook of a user or organization by given ID.

func GetWebhookByRepoID

func GetWebhookByRepoID(repoID, id int64) (*Webhook, error)

GetWebhookByRepoID returns webhook of repository by given ID.

func ListWebhooksByOpts

func ListWebhooksByOpts(ctx context.Context, opts *ListWebhookOptions) ([]*Webhook, error)

ListWebhooksByOpts return webhooks based on options

func (*Webhook) AfterLoad

func (w *Webhook) AfterLoad()

AfterLoad updates the webhook object upon setting a column

func (*Webhook) EventCheckers

func (w *Webhook) EventCheckers() []struct {
	Has  func() bool
	Type webhook_module.HookEventType
}

EventCheckers returns event checkers

func (*Webhook) EventsArray

func (w *Webhook) EventsArray() []string

EventsArray returns an array of hook events

func (*Webhook) HasCreateEvent

func (w *Webhook) HasCreateEvent() bool

HasCreateEvent returns true if hook enabled create event.

func (*Webhook) HasDeleteEvent

func (w *Webhook) HasDeleteEvent() bool

HasDeleteEvent returns true if hook enabled delete event.

func (*Webhook) HasForkEvent

func (w *Webhook) HasForkEvent() bool

HasForkEvent returns true if hook enabled fork event.

func (*Webhook) HasIssueCommentEvent

func (w *Webhook) HasIssueCommentEvent() bool

HasIssueCommentEvent returns true if hook enabled issue_comment event.

func (*Webhook) HasIssuesAssignEvent

func (w *Webhook) HasIssuesAssignEvent() bool

HasIssuesAssignEvent returns true if hook enabled issues assign event.

func (*Webhook) HasIssuesEvent

func (w *Webhook) HasIssuesEvent() bool

HasIssuesEvent returns true if hook enabled issues event.

func (*Webhook) HasIssuesLabelEvent

func (w *Webhook) HasIssuesLabelEvent() bool

HasIssuesLabelEvent returns true if hook enabled issues label event.

func (*Webhook) HasIssuesMilestoneEvent

func (w *Webhook) HasIssuesMilestoneEvent() bool

HasIssuesMilestoneEvent returns true if hook enabled issues milestone event.

func (*Webhook) HasPackageEvent

func (w *Webhook) HasPackageEvent() bool

HasPackageEvent returns if hook enabled package event.

func (*Webhook) HasPullRequestApprovedEvent

func (w *Webhook) HasPullRequestApprovedEvent() bool

HasPullRequestApprovedEvent returns true if hook enabled pull request review event.

func (*Webhook) HasPullRequestAssignEvent

func (w *Webhook) HasPullRequestAssignEvent() bool

HasPullRequestAssignEvent returns true if hook enabled pull request assign event.

func (*Webhook) HasPullRequestCommentEvent

func (w *Webhook) HasPullRequestCommentEvent() bool

HasPullRequestCommentEvent returns true if hook enabled pull_request_comment event.

func (*Webhook) HasPullRequestEvent

func (w *Webhook) HasPullRequestEvent() bool

HasPullRequestEvent returns true if hook enabled pull request event.

func (*Webhook) HasPullRequestLabelEvent

func (w *Webhook) HasPullRequestLabelEvent() bool

HasPullRequestLabelEvent returns true if hook enabled pull request label event.

func (*Webhook) HasPullRequestMilestoneEvent

func (w *Webhook) HasPullRequestMilestoneEvent() bool

HasPullRequestMilestoneEvent returns true if hook enabled pull request milestone event.

func (*Webhook) HasPullRequestRejectedEvent

func (w *Webhook) HasPullRequestRejectedEvent() bool

HasPullRequestRejectedEvent returns true if hook enabled pull request review event.

func (*Webhook) HasPullRequestReviewCommentEvent

func (w *Webhook) HasPullRequestReviewCommentEvent() bool

HasPullRequestReviewCommentEvent returns true if hook enabled pull request review event.

func (*Webhook) HasPullRequestSyncEvent

func (w *Webhook) HasPullRequestSyncEvent() bool

HasPullRequestSyncEvent returns true if hook enabled pull request sync event.

func (*Webhook) HasPushEvent

func (w *Webhook) HasPushEvent() bool

HasPushEvent returns true if hook enabled push event.

func (*Webhook) HasReleaseEvent

func (w *Webhook) HasReleaseEvent() bool

HasReleaseEvent returns if hook enabled release event.

func (*Webhook) HasRepositoryEvent

func (w *Webhook) HasRepositoryEvent() bool

HasRepositoryEvent returns if hook enabled repository event.

func (*Webhook) HasWikiEvent

func (w *Webhook) HasWikiEvent() bool

HasWikiEvent returns true if hook enabled wiki event.

func (Webhook) HeaderAuthorization

func (w Webhook) HeaderAuthorization() (string, error)

HeaderAuthorization returns the decrypted Authorization header. Not on the reference (*w), to be accessible on WebhooksNew.

func (*Webhook) History

func (w *Webhook) History(page int) ([]*HookTask, error)

History returns history of webhook by given conditions.

func (*Webhook) SetHeaderAuthorization

func (w *Webhook) SetHeaderAuthorization(cleartext string) error

SetHeaderAuthorization encrypts and sets the Authorization header.

func (*Webhook) UpdateEvent

func (w *Webhook) UpdateEvent() error

UpdateEvent handles conversion from HookEvent to Events.

Jump to

Keyboard shortcuts

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