Documentation
¶
Index ¶
- Variables
- func SendEvent(ctx context.Context, payload EventPayload) error
- func SendWebhook(ctx context.Context, w models.Webhook, event Event, payload interface{}) error
- func ValidateIPBeforeDial(ip net.IP) error
- func ValidateWebhookURL(rawURL string) error
- type Author
- type BranchTagEvent
- type CollaboratorEvent
- type CollaboratorEventAction
- type Commit
- type Common
- type ContentType
- type Delivery
- type Event
- type EventPayload
- type Hook
- type PushEvent
- type Repository
- type RepositoryEvent
- type RepositoryEventAction
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidScheme is returned when the webhook URL scheme is not http or https. ErrInvalidScheme = errors.New("webhook URL must use http or https scheme") // ErrPrivateIP is returned when the webhook URL resolves to a private IP address. ErrPrivateIP = errors.New("webhook URL cannot resolve to private or internal IP addresses") // ErrInvalidURL is returned when the webhook URL is invalid. ErrInvalidURL = errors.New("invalid webhook URL") )
var ErrInvalidContentType = errors.New("invalid content type")
ErrInvalidContentType is returned when the content type is invalid.
var ErrInvalidEvent = errors.New("invalid event")
ErrInvalidEvent is returned when the event is invalid.
Functions ¶
func SendEvent ¶
func SendEvent(ctx context.Context, payload EventPayload) error
SendEvent sends a webhook event.
func SendWebhook ¶
SendWebhook sends a webhook event.
func ValidateIPBeforeDial ¶
ValidateIPBeforeDial validates an IP address before establishing a connection. This is used to prevent DNS rebinding attacks.
func ValidateWebhookURL ¶
ValidateWebhookURL validates that a webhook URL is safe to use. It checks: - URL is properly formatted - Scheme is http or https - Hostname does not resolve to private/internal IP addresses - Hostname is not localhost or similar.
Types ¶
type Author ¶
type Author struct {
// Name is the author name.
Name string `json:"name" url:"name"`
// Email is the author email.
Email string `json:"email" url:"email"`
// Date is the author date.
Date time.Time `json:"date" url:"date"`
}
Author is a commit author.
type BranchTagEvent ¶
type BranchTagEvent struct {
Common
// Ref is the branch or tag name.
Ref string `json:"ref" url:"ref"`
// Before is the previous commit SHA.
Before string `json:"before" url:"before"`
// After is the current commit SHA.
After string `json:"after" url:"after"`
// Created is whether the branch or tag was created.
Created bool `json:"created" url:"created"`
// Deleted is whether the branch or tag was deleted.
Deleted bool `json:"deleted" url:"deleted"`
}
BranchTagEvent is a branch or tag event.
func NewBranchTagEvent ¶
func NewBranchTagEvent(ctx context.Context, user proto.User, repo proto.Repository, ref, before, after string) (BranchTagEvent, error)
NewBranchTagEvent sends a branch or tag event.
type CollaboratorEvent ¶
type CollaboratorEvent struct {
Common
// Action is the collaborator event action.
Action CollaboratorEventAction `json:"action" url:"action"`
// AccessLevel is the collaborator access level.
AccessLevel access.AccessLevel `json:"access_level" url:"access_level"`
// Collaborator is the collaborator.
Collaborator User `json:"collaborator" url:"collaborator"`
}
CollaboratorEvent is a collaborator event.
func NewCollaboratorEvent ¶
func NewCollaboratorEvent(ctx context.Context, user proto.User, repo proto.Repository, collabUsername string, action CollaboratorEventAction) (CollaboratorEvent, error)
NewCollaboratorEvent sends a collaborator event.
type CollaboratorEventAction ¶
type CollaboratorEventAction string
CollaboratorEventAction is a collaborator event action.
const ( // CollaboratorEventAdded is a collaborator added event. CollaboratorEventAdded CollaboratorEventAction = "added" // CollaboratorEventRemoved is a collaborator removed event. CollaboratorEventRemoved CollaboratorEventAction = "removed" )
type Commit ¶
type Commit struct {
// ID is the commit ID.
ID string `json:"id" url:"id"`
// Message is the commit message.
Message string `json:"message" url:"message"`
// Title is the commit title.
Title string `json:"title" url:"title"`
// Author is the commit author.
Author Author `json:"author" url:"author"`
// Committer is the commit committer.
Committer Author `json:"committer" url:"committer"`
// Timestamp is the commit timestamp.
Timestamp time.Time `json:"timestamp" url:"timestamp"`
}
Commit represents a Git commit.
type Common ¶
type Common struct {
// EventType is the event type.
EventType Event `json:"event" url:"event"`
// Repository is the repository payload.
Repository Repository `json:"repository" url:"repository"`
// Sender is the sender payload.
Sender User `json:"sender" url:"sender"`
}
Common is a common payload.
func (Common) RepositoryID ¶
RepositoryID returns the repository ID. Implements EventPayload.
type ContentType ¶
type ContentType int8
ContentType is the type of content that will be sent in a webhook request.
const ( // ContentTypeJSON is the JSON content type. ContentTypeJSON ContentType = iota // ContentTypeForm is the form content type. ContentTypeForm )
func ParseContentType ¶
func ParseContentType(s string) (ContentType, error)
ParseContentType parses a content type string and returns the content type.
func (ContentType) MarshalText ¶
func (c ContentType) MarshalText() (text []byte, err error)
MarshalText implements encoding.TextMarshaler.
func (ContentType) String ¶
func (c ContentType) String() string
String returns the string representation of the content type.
func (*ContentType) UnmarshalText ¶
func (c *ContentType) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
type Delivery ¶
type Delivery struct {
models.WebhookDelivery
Event Event
}
Delivery is a webhook delivery.
type Event ¶
type Event int
Event is a webhook event.
const ( // EventBranchTagCreate is a branch or tag create event. EventBranchTagCreate Event = 1 // EventBranchTagDelete is a branch or tag delete event. EventBranchTagDelete Event = 2 // EventCollaborator is a collaborator change event. EventCollaborator Event = 3 // EventPush is a push event. EventPush Event = 4 // EventRepository is a repository create, delete, rename event. EventRepository Event = 5 // EventRepositoryVisibilityChange is a repository visibility change event. EventRepositoryVisibilityChange Event = 6 )
func ParseEvent ¶
ParseEvent parses an event string and returns the event.
func (Event) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Event) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type EventPayload ¶
type EventPayload interface {
// Event returns the event type.
Event() Event
// RepositoryID returns the repository ID.
RepositoryID() int64
}
EventPayload is a webhook event payload.
type Hook ¶
type Hook struct {
models.Webhook
ContentType ContentType
Events []Event
}
Hook is a repository webhook.
type PushEvent ¶
type PushEvent struct {
Common
// Ref is the branch or tag name.
Ref string `json:"ref" url:"ref"`
// Before is the previous commit SHA.
Before string `json:"before" url:"before"`
// After is the current commit SHA.
After string `json:"after" url:"after"`
// Commits is the list of commits.
Commits []Commit `json:"commits" url:"commits"`
}
PushEvent is a push event.
type Repository ¶
type Repository struct {
// ID is the repository ID.
ID int64 `json:"id" url:"id"`
// Name is the repository name.
Name string `json:"name" url:"name"`
// ProjectName is the repository project name.
ProjectName string `json:"project_name" url:"project_name"`
// Description is the repository description.
Description string `json:"description" url:"description"`
// DefaultBranch is the repository default branch.
DefaultBranch string `json:"default_branch" url:"default_branch"`
// Private is whether the repository is private.
Private bool `json:"private" url:"private"`
// Owner is the repository owner.
Owner User `json:"owner" url:"owner"`
// HTTPURL is the repository HTTP URL.
HTTPURL string `json:"http_url" url:"http_url"`
// SSHURL is the repository SSH URL.
SSHURL string `json:"ssh_url" url:"ssh_url"`
// GitURL is the repository Git URL.
GitURL string `json:"git_url" url:"git_url"`
// CreatedAt is the repository creation time.
CreatedAt time.Time `json:"created_at" url:"created_at"`
// UpdatedAt is the repository last update time.
UpdatedAt time.Time `json:"updated_at" url:"updated_at"`
}
Repository represents an event repository.
type RepositoryEvent ¶
type RepositoryEvent struct {
Common
// Action is the repository event action.
Action RepositoryEventAction `json:"action" url:"action"`
}
RepositoryEvent is a repository payload.
func NewRepositoryEvent ¶
func NewRepositoryEvent(ctx context.Context, user proto.User, repo proto.Repository, action RepositoryEventAction) (RepositoryEvent, error)
NewRepositoryEvent sends a repository event.
type RepositoryEventAction ¶
type RepositoryEventAction string
RepositoryEventAction is a repository event action.
const ( // RepositoryEventActionDelete is a repository deleted event. RepositoryEventActionDelete RepositoryEventAction = "delete" // RepositoryEventActionRename is a repository renamed event. RepositoryEventActionRename RepositoryEventAction = "rename" // RepositoryEventActionVisibilityChange is a repository visibility changed event. RepositoryEventActionVisibilityChange RepositoryEventAction = "visibility_change" // RepositoryEventActionDefaultBranchChange is a repository default branch changed event. RepositoryEventActionDefaultBranchChange RepositoryEventAction = "default_branch_change" )