Documentation
¶
Overview ¶
Package webhooks validates GitHub webhook signatures and parses the pull_request, team, and membership events the application handles.
Index ¶
- Constants
- func Sign(payload []byte, secret string) string
- func ValidateSignature(payload []byte, signature, secret string) error
- type MembershipEvent
- type PullRequestEvent
- func (e *PullRequestEvent) GetBaseBranch() string
- func (e *PullRequestEvent) GetNumber() int
- func (e *PullRequestEvent) GetRepoFullName() string
- func (e *PullRequestEvent) GetRepoName() string
- func (e *PullRequestEvent) GetRepoOwner() string
- func (e PullRequestEvent) GetSenderLogin() string
- func (e PullRequestEvent) GetSenderType() string
- func (e *PullRequestEvent) IsMerged() bool
- type TeamChanges
- type TeamEvent
Constants ¶
const ( EventPing = "ping" EventPullRequest = "pull_request" EventTeam = "team" EventMembership = "membership" )
Event types the application handles.
Variables ¶
This section is empty.
Functions ¶
func ValidateSignature ¶ added in v1.0.0
ValidateSignature verifies the X-Hub-Signature-256 HMAC of a payload. An empty secret is rejected, so a missing configuration never accepts unsigned requests.
Types ¶
type MembershipEvent ¶
type MembershipEvent struct {
Action string `json:"action"`
Scope string `json:"scope"`
Member *github.User `json:"member"`
Team *github.Team `json:"team"`
Organization *github.Organization `json:"organization"`
// contains filtered or unexported fields
}
MembershipEvent represents a GitHub membership webhook payload.
func ParseMembershipEvent ¶
func ParseMembershipEvent(payload []byte) (*MembershipEvent, error)
ParseMembershipEvent unmarshals and validates a membership webhook.
func (*MembershipEvent) GetOrgLogin ¶ added in v1.0.0
func (e *MembershipEvent) GetOrgLogin() string
GetOrgLogin returns the login of the organization the team belongs to.
func (MembershipEvent) GetSenderLogin ¶
func (e MembershipEvent) GetSenderLogin() string
GetSenderLogin returns the login of the user who triggered the event.
func (MembershipEvent) GetSenderType ¶
func (e MembershipEvent) GetSenderType() string
GetSenderType returns the type of the sender, such as User or Bot.
func (*MembershipEvent) GetTeamSlug ¶
func (e *MembershipEvent) GetTeamSlug() string
GetTeamSlug returns the team's slug.
func (*MembershipEvent) IsTeamScope ¶
func (e *MembershipEvent) IsTeamScope() bool
IsTeamScope returns true if the membership event is for a team.
type PullRequestEvent ¶
type PullRequestEvent struct {
Action string `json:"action"`
Number int `json:"number"`
PullRequest *github.PullRequest `json:"pull_request"`
Repository *github.Repository `json:"repository"`
// contains filtered or unexported fields
}
PullRequestEvent represents a GitHub pull_request webhook payload.
func ParsePullRequestEvent ¶
func ParsePullRequestEvent(payload []byte) (*PullRequestEvent, error)
ParsePullRequestEvent unmarshals and validates a pull_request webhook.
func (*PullRequestEvent) GetBaseBranch ¶
func (e *PullRequestEvent) GetBaseBranch() string
GetBaseBranch returns the target branch name.
func (*PullRequestEvent) GetNumber ¶ added in v1.0.0
func (e *PullRequestEvent) GetNumber() int
GetNumber returns the PR number.
func (*PullRequestEvent) GetRepoFullName ¶
func (e *PullRequestEvent) GetRepoFullName() string
GetRepoFullName returns the repository in owner/name format.
func (*PullRequestEvent) GetRepoName ¶
func (e *PullRequestEvent) GetRepoName() string
GetRepoName returns the repository name without owner.
func (*PullRequestEvent) GetRepoOwner ¶
func (e *PullRequestEvent) GetRepoOwner() string
GetRepoOwner returns the repository owner login.
func (PullRequestEvent) GetSenderLogin ¶ added in v1.0.0
func (e PullRequestEvent) GetSenderLogin() string
GetSenderLogin returns the login of the user who triggered the event.
func (PullRequestEvent) GetSenderType ¶ added in v1.0.0
func (e PullRequestEvent) GetSenderType() string
GetSenderType returns the type of the sender, such as User or Bot.
func (*PullRequestEvent) IsMerged ¶
func (e *PullRequestEvent) IsMerged() bool
IsMerged returns true if the PR was closed via merge.
type TeamChanges ¶
type TeamChanges struct {
Name *struct {
From string `json:"from"`
} `json:"name,omitempty"`
}
TeamChanges holds the previous values of an edited team's fields.
type TeamEvent ¶
type TeamEvent struct {
Action string `json:"action"`
Team *github.Team `json:"team"`
Changes *TeamChanges `json:"changes,omitempty"`
Organization *github.Organization `json:"organization"`
// contains filtered or unexported fields
}
TeamEvent represents a GitHub team webhook payload.
func ParseTeamEvent ¶
ParseTeamEvent unmarshals and validates a team webhook.
func (*TeamEvent) AffectsMembership ¶ added in v1.0.0
AffectsMembership returns true if the change can affect which team the sync maps a group to: a team was created, deleted, or renamed. Changes to a team's description, privacy, or repository access cannot.
func (*TeamEvent) GetOrgLogin ¶ added in v1.0.0
GetOrgLogin returns the login of the organization the team belongs to.
func (*TeamEvent) GetPreviousTeamSlug ¶ added in v1.0.0
GetPreviousTeamSlug returns the slug the team had before it was renamed, or "".
func (TeamEvent) GetSenderLogin ¶
func (e TeamEvent) GetSenderLogin() string
GetSenderLogin returns the login of the user who triggered the event.
func (TeamEvent) GetSenderType ¶
func (e TeamEvent) GetSenderType() string
GetSenderType returns the type of the sender, such as User or Bot.
func (*TeamEvent) GetTeamSlug ¶
GetTeamSlug returns the team's slug.