hookutil

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package hookutil holds helpers shared by the backends' webhook parsers.

Index

Constants

View Source
const MaxBodyBytes = 25 << 20

MaxBodyBytes caps how much of a delivery is read. GitHub caps webhook payloads at 25 MB and the other forges send less.

Variables

This section is empty.

Functions

func FirstHeader

func FirstHeader(r *http.Request, names ...string) string

FirstHeader returns the first non-empty value among the named headers.

func IsZeroSHA

func IsZeroSHA(sha string) bool

IsZeroSHA reports whether sha is a non-empty run of zeros, which forges send as the before or after commit of a push that creates or deletes a ref.

func IssueAsPullRequest

func IssueAsPullRequest(i forges.Issue) forges.PullRequest

IssueAsPullRequest builds a pull request from the issue representation that GitHub and Gitea send for comments on pull requests.

func Payload

func Payload(contentType string, body []byte) ([]byte, error)

Payload returns the JSON payload of a delivery. Form deliveries carry it in the payload field; JSON deliveries are the payload. A missing Content-Type is treated as JSON.

func ReadBody

func ReadBody(r *http.Request) ([]byte, error)

ReadBody reads a delivery body, failing once it passes MaxBodyBytes.

func ValidHMACSHA256

func ValidHMACSHA256(payload []byte, secret, signature string) bool

ValidHMACSHA256 reports whether signature is the hex HMAC-SHA256 of payload keyed with secret. A "sha256=" prefix is accepted.

func ValidToken

func ValidToken(token, secret string) bool

ValidToken reports whether a shared-secret token matches, in constant time.

Types

This section is empty.

Jump to

Keyboard shortcuts

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