webhook

package
v0.115.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 13 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",
	OCIRegistry: "X-Doco-OCI-Event",
}

ScmProviderEventHeaders maps ScmProvider to their respective event header names.

View Source
var ScmProviderNames = map[ScmProvider]string{
	Unknown:     "Unknown",
	Github:      "GitHub",
	Gitlab:      "GitLab",
	Gitea:       "Gitea",
	Gogs:        "Gogs",
	Forgejo:     "Forgejo",
	OCIRegistry: "OCI Registry",
}

ScmProviderNames maps ScmProvider to their human-readable 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",
	OCIRegistry: "X-Doco-OCI-Signature-256",
}

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 OCIArtifactPayload added in v0.89.0

type OCIArtifactPayload struct {
	Source   string `json:"source"`
	Digest   string `json:"digest"`
	Artifact string `json:"artifact"`
}

OCIArtifactPayload is a generic webhook payload for OCI artifact events.

type ParsedPayload

type ParsedPayload struct {
	Source    PayloadSource
	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    plumbing.Hash // Before is the hash of the commit before the push
	After     plumbing.Hash // After is the hash of the commit after the push
	CommitSHA plumbing.Hash // CommitSHA is the SHA of the commit that triggered the webhook
	Trigger   string        // Trigger is the value that triggered the deployment (e.g., "poll", commit SHA, or OCI digest)
	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
	Artifact  string        // Artifact is the OCI artifact reference that triggered the webhook
	Digest    string        // Digest is the OCI digest that triggered the webhook
}

ParsedPayload is a struct that contains the parsed payload data.

func (ParsedPayload) CommitSHAString added in v0.107.0

func (p ParsedPayload) CommitSHAString() string

CommitSHAString returns the CommitSHA as a string. If the CommitSHA is empty, it returns an empty string.

func (ParsedPayload) RevisionString added in v0.107.0

func (p ParsedPayload) RevisionString() string

RevisionString returns the revision string for the payload. For Git payloads, it returns the CommitSHA. For OCI payloads, it returns the Digest.

func (ParsedPayload) TriggerString added in v0.107.0

func (p ParsedPayload) TriggerString() string

TriggerString returns the trigger value for the payload. For Git payloads, it returns the CommitSHA. For OCI payloads, it returns the Digest.

type PayloadSource added in v0.89.0

type PayloadSource string
const (
	PayloadSourceGit PayloadSource = "git"
	PayloadSourceOCI PayloadSource = "oci"
)

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
	OCIRegistry
)

func (ScmProvider) String added in v0.89.0

func (p ScmProvider) String() string

String returns the human-readable name of the ScmProvider.

Jump to

Keyboard shortcuts

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