webhook

package
v0.61.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 9 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 ScmProviderSecurityHeaders = map[ScmProvider]string{
	Github: "X-Hub-Signature-256",
	Gitlab: "X-Gitlab-Token",
	Gitea:  "X-Gitea-Signature",
	Gogs:   "X-Gogs-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

Types

type GithubPushPayload

type GithubPushPayload struct {
	Ref        string `json:"ref"`
	CommitSHA  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"`
	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
	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.

func Parse

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

Parse parses the payload and returns 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
)

Jump to

Keyboard shortcuts

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