Documentation
¶
Index ¶
- func CleanupHookTaskTable(ctx context.Context, cleanupType HookTaskCleanupType, olderThan time.Duration, ...) error
- func CopyDefaultWebhooksToRepo(ctx context.Context, repoID int64) error
- func CreateWebhook(ctx context.Context, w *Webhook) error
- func CreateWebhooks(ctx context.Context, ws []*Webhook) error
- func DeleteDefaultSystemWebhook(ctx context.Context, id int64) error
- func DeleteWebhookByID(ctx context.Context, id int64) (err error)
- func DeleteWebhookByOwnerID(ctx context.Context, ownerID, id int64) error
- func DeleteWebhookByRepoID(ctx context.Context, repoID, id int64) error
- func FindUndeliveredHookTaskIDs(ctx context.Context, lowerID int64) ([]int64, error)
- func IsErrHookTaskNotExist(err error) bool
- func IsErrWebhookNotExist(err error) bool
- func IsValidHookContentType(name string) bool
- func MarkTaskDelivered(ctx context.Context, task *HookTask) (bool, error)
- func UpdateHookTask(ctx context.Context, t *HookTask) error
- func UpdateWebhook(ctx context.Context, w *Webhook) error
- func UpdateWebhookLastStatus(ctx context.Context, w *Webhook) error
- type ErrHookTaskNotExist
- type ErrWebhookNotExist
- type HookContentType
- type HookRequest
- type HookResponse
- type HookTask
- func CreateHookTask(ctx context.Context, t *HookTask) (*HookTask, error)
- func GetHookTaskByID(ctx context.Context, id int64) (*HookTask, error)
- func HookTasks(ctx context.Context, hookID int64, page int) ([]*HookTask, error)
- func ReplayHookTask(ctx context.Context, hookID int64, uuid string) (*HookTask, error)
- type HookTaskCleanupType
- type ListWebhookOptions
- type Webhook
- func GetDefaultWebhooks(ctx context.Context) ([]*Webhook, error)
- func GetSystemOrDefaultWebhook(ctx context.Context, id int64) (*Webhook, error)
- func GetSystemWebhooks(ctx context.Context, isActive optional.Option[bool]) ([]*Webhook, error)
- func GetWebhookByID(ctx context.Context, id int64) (*Webhook, error)
- func GetWebhookByOwnerID(ctx context.Context, ownerID, id int64) (*Webhook, error)
- func GetWebhookByRepoID(ctx context.Context, repoID, id int64) (*Webhook, error)
- func (w *Webhook) AfterLoad()
- func (w *Webhook) EventCheckers() []struct{ ... }
- func (w *Webhook) EventsArray() []string
- func (w *Webhook) HasCreateEvent() bool
- func (w *Webhook) HasDeleteEvent() bool
- func (w *Webhook) HasForkEvent() bool
- func (w *Webhook) HasIssueCommentEvent() bool
- func (w *Webhook) HasIssuesAssignEvent() bool
- func (w *Webhook) HasIssuesEvent() bool
- func (w *Webhook) HasIssuesLabelEvent() bool
- func (w *Webhook) HasIssuesMilestoneEvent() bool
- func (w *Webhook) HasPackageEvent() bool
- func (w *Webhook) HasPullRequestApprovedEvent() bool
- func (w *Webhook) HasPullRequestAssignEvent() bool
- func (w *Webhook) HasPullRequestCommentEvent() bool
- func (w *Webhook) HasPullRequestEvent() bool
- func (w *Webhook) HasPullRequestLabelEvent() bool
- func (w *Webhook) HasPullRequestMilestoneEvent() bool
- func (w *Webhook) HasPullRequestRejectedEvent() bool
- func (w *Webhook) HasPullRequestReviewCommentEvent() bool
- func (w *Webhook) HasPullRequestReviewRequestEvent() bool
- func (w *Webhook) HasPullRequestSyncEvent() bool
- func (w *Webhook) HasPushEvent() bool
- func (w *Webhook) HasReleaseEvent() bool
- func (w *Webhook) HasRepositoryEvent() bool
- func (w *Webhook) HasStatusEvent() bool
- func (w *Webhook) HasWikiEvent() bool
- func (w Webhook) HeaderAuthorization() (string, error)
- func (w *Webhook) History(ctx context.Context, page int) ([]*HookTask, error)
- func (w *Webhook) SetHeaderAuthorization(cleartext string) error
- func (w *Webhook) UpdateEvent() error
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 CreateWebhook ¶
func CreateWebhook(ctx context.Context, w *Webhook) error
CreateWebhook creates a new web hook.
func CreateWebhooks ¶ added in v1.17.0
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 DeleteWebhookByID ¶ added in v1.20.6
func DeleteWebhookByID(ctx context.Context, id int64) (err error)
DeleteWebhookByID uses argument bean as query condition, ID must be specified and do not assign unnecessary fields.
func DeleteWebhookByOwnerID ¶ added in v1.20.0
func DeleteWebhookByOwnerID(ctx context.Context, ownerID, id int64) error
DeleteWebhookByOwnerID deletes webhook of a user or organization by given ID.
func DeleteWebhookByRepoID ¶
func DeleteWebhookByRepoID(ctx context.Context, repoID, id int64) error
DeleteWebhookByRepoID deletes webhook of repository by given ID.
func FindUndeliveredHookTaskIDs ¶ added in v1.17.4
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 ¶ added in v1.17.4
func MarkTaskDelivered(ctx context.Context, task *HookTask) (bool, error)
func UpdateHookTask ¶
func UpdateHookTask(ctx context.Context, t *HookTask) error
UpdateHookTask updates information of hook task.
func UpdateWebhook ¶
func UpdateWebhook(ctx context.Context, w *Webhook) error
UpdateWebhook updates information of webhook.
func UpdateWebhookLastStatus ¶
func UpdateWebhookLastStatus(ctx context.Context, 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.
type ErrWebhookNotExist ¶
type ErrWebhookNotExist struct {
ID int64
}
ErrWebhookNotExist represents a "WebhookNotExist" kind of 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.
type HookRequest ¶
type HookRequest struct {
URL string `json:"url"`
HTTPMethod string `json:"http_method"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
}
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"`
PayloadContent string `xorm:"LONGTEXT"`
// PayloadVersion number to allow for smooth version upgrades:
// - PayloadVersion 1: PayloadContent contains the JSON as sent to the URL
// - PayloadVersion 2: PayloadContent contains the original event
PayloadVersion int `xorm:"DEFAULT 1"`
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 ¶ added in v1.17.4
func GetHookTaskByID(ctx context.Context, id int64) (*HookTask, error)
func HookTasks ¶
func HookTasks(ctx context.Context, 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 optional.Option[bool]
}
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 optional.Option[bool]) ([]*Webhook, error)
GetSystemWebhooks returns all admin system webhooks.
func GetWebhookByID ¶
func GetWebhookByID(ctx context.Context, id int64) (*Webhook, error)
GetWebhookByID returns webhook of repository by given ID.
func GetWebhookByOwnerID ¶ added in v1.20.0
func GetWebhookByOwnerID(ctx context.Context, ownerID, id int64) (*Webhook, error)
GetWebhookByOwnerID returns webhook of a user or organization by given ID.
func GetWebhookByRepoID ¶
func GetWebhookByRepoID(ctx context.Context, repoID, id int64) (*Webhook, error)
GetWebhookByRepoID returns webhook of repository by given ID.
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 ¶ added in v1.17.0
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) HasPullRequestReviewRequestEvent ¶ added in v1.20.0
func (w *Webhook) HasPullRequestReviewRequestEvent() bool
HasPullRequestReviewRequestEvent returns true if hook enabled pull request review request 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) HasStatusEvent ¶ added in v1.23.2
func (w *Webhook) HasStatusEvent() bool
func (*Webhook) HasWikiEvent ¶ added in v1.17.4
func (w *Webhook) HasWikiEvent() bool
HasWikiEvent returns true if hook enabled wiki event.
func (Webhook) HeaderAuthorization ¶ added in v1.17.4
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(ctx context.Context, page int) ([]*HookTask, error)
History returns history of webhook by given conditions.
func (*Webhook) SetHeaderAuthorization ¶ added in v1.17.4
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.