Documentation
¶
Index ¶
- Variables
- func GenerateHMAC(payload []byte, secretKey string) string
- func IsBranchOrTagDeletionEvent(r *http.Request, payload ParsedPayload, provider ScmProvider) (bool, error)
- func Parse(r *http.Request, secretKey string) (ScmProvider, ParsedPayload, error)
- type GithubPushPayload
- type GitlabPushPayload
- type OCIArtifactPayload
- type ParsedPayload
- type PayloadSource
- type ScmProvider
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidHTTPMethod = errors.New("invalid http method") ErrParsingPayload = errors.New("failed to parse payload") )
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") )
var ErrUnknownProvider = errors.New("unknown SCM provider")
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.
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.
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 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.