webhook

package
v0.67.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHTTPMethod = errors.New("invalid http method")
	ErrParsingPayload    = errors.New("failed to parse payload")
)
View Source
var (
	ErrIncorrectSecretKey            = errors.New("incorrect secret key")
	ErrHMACVerificationFailed        = errors.New("HMAC verification failed")
	ErrGitlabTokenVerificationFailed = errors.New("gitlab token verification failed")
	ErrMissingSecurityHeader         = errors.New("missing signature or token header")
)
View Source
var ErrUnknownProvider = errors.New("unknown SCM provider")
View Source
var ScmProviderEventHeaders = map[ScmProvider]string{
	Github:  "X-GitHub-Event",
	Gitlab:  "X-Gitlab-Event",
	Gitea:   "X-Gitea-Event",
	Gogs:    "X-Gogs-Event",
	Forgejo: "X-Forgejo-Event",
}

ScmProviderEventHeaders maps ScmProvider to their respective event header names.

View Source
var ScmProviderSecurityHeaders = map[ScmProvider]string{
	Github:  "X-Hub-Signature-256",
	Gitlab:  "X-Gitlab-Token",
	Gitea:   "X-Gitea-Signature",
	Gogs:    "X-Gogs-Signature",
	Forgejo: "X-Forgejo-Signature",
}

ScmProviderSecurityHeaders maps ScmProvider to their respective security header names.

Functions

func GenerateHMAC added in v0.7.1

func GenerateHMAC(payload []byte, secretKey string) string

func IsBranchOrTagDeletionEvent added in v0.63.0

func IsBranchOrTagDeletionEvent(r *http.Request, payload ParsedPayload, provider ScmProvider) (bool, error)

IsBranchOrTagDeletionEvent checks if the incoming webhook event is a branch or tag deletion event for the given provider.

func Parse

func Parse(r *http.Request, secretKey string) (ScmProvider, ParsedPayload, error)

Parse parses the payload and returns the parsed payload data.

Types

type GithubPushPayload

type GithubPushPayload struct {
	Ref        string `json:"ref"`
	RefType    string `json:"ref_type,omitempty"` // ref_type is only present in create/delete events
	Before     string `json:"before"`
	After      string `json:"after"`
	Repository struct {
		Name     string `json:"name"`
		FullName string `json:"full_name"`
		CloneURL string `json:"clone_url"`
		SSHUrl   string `json:"ssh_url"`
		WebURL   string `json:"html_url"`
		Private  bool   `json:"private"`
	} `json:"repository"`
}

GithubPushPayload is a struct that represents the payload sent by GitHub or Gitea, as they have the same structure.

type GitlabPushPayload

type GitlabPushPayload struct {
	Ref        string `json:"ref"`
	Before     string `json:"before"`
	After      string `json:"after"`
	CommitSHA  string `json:"checkout_sha"`
	Repository struct {
		Name              string `json:"name"`
		PathWithNamespace string `json:"path_with_namespace"`
		CloneURL          string `json:"http_url"`
		SSHUrl            string `json:"ssh_url"`
		WebURL            string `json:"web_url"`
		VisibilityLevel   int64  `json:"visibility_level"`
	} `json:"project"`
}

GitlabPushPayload is a struct that represents the payload sent by GitLab.

type ParsedPayload

type ParsedPayload struct {
	Ref       string // Ref is the branch or tag that triggered the webhook
	RefType   string // RefType is the type of ref (branch or tag) that triggered the webhook, only present in delete events
	Before    string // Before is the SHA of the commit before the push, only present in GitLab payloads
	After     string // After is the SHA of the commit after the push, only present in GitLab payloads
	CommitSHA string // CommitSHA is the SHA of the commit that triggered the webhook
	Name      string // Name is the short name of the repository (without owner or organization)
	FullName  string // FullName is the full name of the repository (e.g., owner/repo)
	CloneURL  string // CloneURL is the URL to clone the repository
	SSHUrl    string // SSHUrl is the SSH URL to clone the repository
	WebURL    string // WebURL is the URL to view the repository in a web browser
	Private   bool   // Private indicates whether the repository is private or public
}

ParsedPayload is a struct that contains the parsed payload data.

type ScmProvider added in v0.52.0

type ScmProvider int // ScmProvider represents the supported source code management provider.
const (
	Unknown ScmProvider = iota
	Github
	Gitlab
	Gitea
	Gogs
	Forgejo
)

Jump to

Keyboard shortcuts

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