Documentation
¶
Overview ¶
Package hookutil holds helpers shared by the backends' webhook parsers.
Index ¶
- Constants
- func FirstHeader(r *http.Request, names ...string) string
- func IsZeroSHA(sha string) bool
- func IssueAsPullRequest(i forges.Issue) forges.PullRequest
- func Payload(contentType string, body []byte) ([]byte, error)
- func ReadBody(r *http.Request) ([]byte, error)
- func ValidHMACSHA256(payload []byte, secret, signature string) bool
- func ValidToken(token, secret string) bool
Constants ¶
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 ¶
FirstHeader returns the first non-empty value among the named headers.
func IsZeroSHA ¶
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 ¶
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 ValidHMACSHA256 ¶
ValidHMACSHA256 reports whether signature is the hex HMAC-SHA256 of payload keyed with secret. A "sha256=" prefix is accepted.
func ValidToken ¶
ValidToken reports whether a shared-secret token matches, in constant time.
Types ¶
This section is empty.