Documentation ¶
Overview ¶
Package webhook defines a generic handler for GitHub App & Webhook events.
Example ¶
package main import ( "fmt" "net/http" "github.com/google/go-github/github" "github.com/stephen-soltesz/github-webhook-poc/githubx/webhook" ) func main() { eventHandler := &webhook.Handler{ PushEvent: func(event *github.PushEvent) error { fmt.Printf("%#v\n", event) return nil }, } mux := http.NewServeMux() mux.Handle("/event_handler", eventHandler) http.ListenAndServe(":8888", mux) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct { // WebhookSecret should match the value used to register the github webhook. WebhookSecret string // All functions accept the corresponding event type. The functions may // return an error. The `ServeHTTP` handler reports errors as HTTP 500 // failures to the caller. CheckRunEvent func(*github.CheckRunEvent) error CheckSuiteEvent func(*github.CheckSuiteEvent) error CommitCommentEvent func(*github.CommitCommentEvent) error CreateEvent func(*github.CreateEvent) error DeleteEvent func(*github.DeleteEvent) error DeploymentEvent func(*github.DeploymentEvent) error DeploymentStatusEvent func(*github.DeploymentStatusEvent) error ForkEvent func(*github.ForkEvent) error GitHubAppAuthorizationEvent func(*github.GitHubAppAuthorizationEvent) error GollumEvent func(*github.GollumEvent) error InstallationEvent func(*github.InstallationEvent) error InstallationRepositoriesEvent func(*github.InstallationRepositoriesEvent) error IssueCommentEvent func(*github.IssueCommentEvent) error IssuesEvent func(*github.IssuesEvent) error LabelEvent func(*github.LabelEvent) error MarketplacePurchaseEvent func(*github.MarketplacePurchaseEvent) error MemberEvent func(*github.MemberEvent) error MembershipEvent func(*github.MembershipEvent) error MilestoneEvent func(*github.MilestoneEvent) error OrganizationEvent func(*github.OrganizationEvent) error OrgBlockEvent func(*github.OrgBlockEvent) error PageBuildEvent func(*github.PageBuildEvent) error ProjectEvent func(*github.ProjectEvent) error ProjectCardEvent func(*github.ProjectCardEvent) error ProjectColumnEvent func(*github.ProjectColumnEvent) error PublicEvent func(*github.PublicEvent) error PullRequestEvent func(*github.PullRequestEvent) error PullRequestReviewEvent func(*github.PullRequestReviewEvent) error PullRequestReviewCommentEvent func(*github.PullRequestReviewCommentEvent) error PushEvent func(*github.PushEvent) error ReleaseEvent func(*github.ReleaseEvent) error RepositoryEvent func(*github.RepositoryEvent) error RepositoryVulnerabilityAlertEvent func(*github.RepositoryVulnerabilityAlertEvent) error StatusEvent func(*github.StatusEvent) error TeamEvent func(*github.TeamEvent) error TeamAddEvent func(*github.TeamAddEvent) error WatchEvent func(*github.WatchEvent) error // contains filtered or unexported fields }
A Handler defines parameters for implementing a GitHub webhook event handler as part of a GitHub App (https://developer.github.com/apps/) or ad-hoc Webhook server (https://developer.github.com/webhooks/).
To be useful, define at least one event handler function.
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP is an http.Handler used to respond to webhook events with the corresponding user-provided functions from the Handler.
The GitHub "ping" event is handled automatically. For every event type received in a "ping" event, ServeHTTP checks whether there is corresponding, non-nil event handler functions. If so, then the ping is successful; if not, the ping fails.