Help us shape the future of Go! Take the 2026 Go Developer Survey

ghwebhook

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

README

GHWebHook

release Build Status godoc

Say Thanks!

Create a Github WebHook in 5 seconds!

Description

  • Default port: 80
  • Default path: /postreceive
  • Default event type: push

Examples

Basic:

package main

import (
	"log"
	"net/url"

	"github.com/google/go-github/github/v29"
	ghw "github.com/ldez/ghwebhook"
)

func main() {

	eventHandlers := ghw.NewEventHandlers().
		OnIssues(func(uri *url.URL, payload *github.WebHookPayload, event *github.IssuesEvent) {
			go func() {
				log.Println(uri, event.GetAction(), event.Issue)
			}()
		}).
		OnPullRequest(func(uri *url.URL, payload *github.WebHookPayload, event *github.PullRequestEvent) {
			log.Println(uri, event.GetAction(), event.GetNumber(), event.PullRequest)
		})

	webHook := ghw.NewWebHook(eventHandlers, ghw.WithAllEventTypes)

	err := webHook.ListenAndServe()
	if err != nil {
		log.Fatal(err)
	}
}

Secured WebHook with custom port and path:

package main

import (
	"log"
	"net/url"

	"github.com/google/go-github/github/v29"
	ghw "github.com/ldez/ghwebhook"
	"github.com/ldez/ghwebhook/eventtype"
)

func main() {

	eventHandlers := ghw.NewEventHandlers().
		OnIssues(func(uri *url.URL, payload *github.WebHookPayload, event *github.IssuesEvent) {
			go func() {
				log.Println(uri, event.GetAction(), event.Issue)
			}()
		}).
		OnPullRequest(func(uri *url.URL, payload *github.WebHookPayload, event *github.PullRequestEvent) {
			log.Println(uri, event.GetAction(), event.GetNumber(), event.PullRequest)
		})

	webhook := ghw.NewWebHook(
		eventHandlers,
		ghw.WithPort(5000),
		ghw.WithPath("/github"),
		ghw.WithSecret("SECRET"),
		ghw.Debug,
		ghw.WithEventTypes(eventtype.Issues, eventtype.PullRequest))

	err := webhook.ListenAndServe()
	if err != nil {
		log.Fatal(err)
	}
}

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(server *WebHook)

Debug activate debug mode.

func WithAllEventTypes

func WithAllEventTypes(server *WebHook)

WithAllEventTypes accept all possible event types.

func WithEventTypes

func WithEventTypes(eventTypes ...string) func(*WebHook)

WithEventTypes define accepted event types.

func WithPath

func WithPath(path string) func(*WebHook)

WithPath define the HTTP handler path.

func WithPort

func WithPort(port int) func(*WebHook)

WithPort define the server port.

func WithSecret

func WithSecret(secret string) func(*WebHook)

WithSecret define the GitHub secret.

Types

type ContentReference

type ContentReference struct {
	ID        *int64  `json:"id,omitempty"`
	NodeID    *string `json:"node_id,omitempty"`
	Reference *string `json:"reference,omitempty"`
}

ContentReference represents a GitHub Content Reference.

func (*ContentReference) GetID

func (c *ContentReference) GetID() int64

GetID returns the ID field if it's non-nil, zero value otherwise.

func (*ContentReference) GetNodeID

func (c *ContentReference) GetNodeID() string

GetNodeID returns the NodeID field if it's non-nil, zero value otherwise.

func (*ContentReference) GetReference

func (c *ContentReference) GetReference() string

GetReference returns the Reference field if it's non-nil, zero value otherwise.

type ContentReferenceEvent

type ContentReferenceEvent struct {
	Action           *string            `json:"action,omitempty"`
	ContentReference *ContentReference  `json:"content_reference,omitempty"`
	Repo             *github.Repository `json:"repository,omitempty"`
	Sender           *github.User       `json:"sender,omitempty"`
	Installation     *github.App        `json:"installation,omitempty"`
}

ContentReferenceEvent is triggered when the body or comment of an issue or pull request includes a URL that matches a configured content reference domain. Only GitHub Apps can receive this event.

GitHub API docs: https://developer.github.com/v3/activity/events/types/#contentreferenceevent

func (*ContentReferenceEvent) GetAction

func (c *ContentReferenceEvent) GetAction() string

GetAction returns the Action field if it's non-nil, zero value otherwise.

func (*ContentReferenceEvent) GetContentReference

func (c *ContentReferenceEvent) GetContentReference() *ContentReference

GetContentReference returns the ContentReference field.

func (*ContentReferenceEvent) GetInstallation

func (c *ContentReferenceEvent) GetInstallation() *github.App

GetInstallation returns the Installation field.

func (*ContentReferenceEvent) GetRepo

func (c *ContentReferenceEvent) GetRepo() *github.Repository

GetRepo returns the Repo field.

func (*ContentReferenceEvent) GetSender

func (c *ContentReferenceEvent) GetSender() *github.User

GetSender returns the Sender field.

type EventHandlers

type EventHandlers struct {
	// contains filtered or unexported fields
}

EventHandlers all event handlers

func NewEventHandlers

func NewEventHandlers() *EventHandlers

NewEventHandlers create a new event handlers.

func (*EventHandlers) OnCheckRun

func (c *EventHandlers) OnCheckRun(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.CheckRunEvent)) *EventHandlers

OnCheckRun CheckRun handler.

func (*EventHandlers) OnCheckSuite

func (c *EventHandlers) OnCheckSuite(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.CheckSuiteEvent)) *EventHandlers

OnCheckSuite CheckSuite handler.

func (*EventHandlers) OnCommitComment

func (c *EventHandlers) OnCommitComment(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.CommitCommentEvent)) *EventHandlers

OnCommitComment CommitComment handler.

func (*EventHandlers) OnContentReference

func (c *EventHandlers) OnContentReference(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *ContentReferenceEvent)) *EventHandlers

OnContentReference ContentReference handler.

func (*EventHandlers) OnCreate

func (c *EventHandlers) OnCreate(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.CreateEvent)) *EventHandlers

OnCreate Create handler.

func (*EventHandlers) OnDelete

func (c *EventHandlers) OnDelete(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.DeleteEvent)) *EventHandlers

OnDelete Delete handler.

func (*EventHandlers) OnDeployment

func (c *EventHandlers) OnDeployment(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.DeploymentEvent)) *EventHandlers

OnDeployment Deployment handler.

func (*EventHandlers) OnDeploymentStatus

func (c *EventHandlers) OnDeploymentStatus(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.DeploymentStatusEvent)) *EventHandlers

OnDeploymentStatus DeploymentStatus handler.

func (*EventHandlers) OnFork

func (c *EventHandlers) OnFork(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.ForkEvent)) *EventHandlers

OnFork Fork handler.

func (*EventHandlers) OnGollum

func (c *EventHandlers) OnGollum(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.GollumEvent)) *EventHandlers

OnGollum Gollum handler.

func (*EventHandlers) OnInstallation

func (c *EventHandlers) OnInstallation(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.InstallationEvent)) *EventHandlers

OnInstallation Installation handler.

func (*EventHandlers) OnInstallationRepositories

func (c *EventHandlers) OnInstallationRepositories(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.InstallationRepositoriesEvent)) *EventHandlers

OnInstallationRepositories InstallationRepositories handler.

func (*EventHandlers) OnIssueComment

func (c *EventHandlers) OnIssueComment(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.IssueCommentEvent)) *EventHandlers

OnIssueComment IssueComment handler.

func (*EventHandlers) OnIssues

func (c *EventHandlers) OnIssues(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.IssuesEvent)) *EventHandlers

OnIssues Issues handler.

func (*EventHandlers) OnLabel

func (c *EventHandlers) OnLabel(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.LabelEvent)) *EventHandlers

OnLabel Label handler.

func (*EventHandlers) OnMarketplacePurchase

func (c *EventHandlers) OnMarketplacePurchase(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.MarketplacePurchaseEvent)) *EventHandlers

OnMarketplacePurchase MarketplacePurchase handler.

func (*EventHandlers) OnMember

func (c *EventHandlers) OnMember(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.MemberEvent)) *EventHandlers

OnMember Member handler.

func (*EventHandlers) OnMembership

func (c *EventHandlers) OnMembership(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.MembershipEvent)) *EventHandlers

OnMembership Membership handler.

func (*EventHandlers) OnMilestone

func (c *EventHandlers) OnMilestone(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.MilestoneEvent)) *EventHandlers

OnMilestone Milestone handler.

func (*EventHandlers) OnOrgBlock

func (c *EventHandlers) OnOrgBlock(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.OrgBlockEvent)) *EventHandlers

OnOrgBlock OrgBlock handler.

func (*EventHandlers) OnOrganization

func (c *EventHandlers) OnOrganization(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.OrganizationEvent)) *EventHandlers

OnOrganization Organization handler.

func (*EventHandlers) OnPageBuild

func (c *EventHandlers) OnPageBuild(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.PageBuildEvent)) *EventHandlers

OnPageBuild PageBuild handler.

func (*EventHandlers) OnPing

func (c *EventHandlers) OnPing(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.PingEvent)) *EventHandlers

OnPing Ping handler.

func (*EventHandlers) OnProject

func (c *EventHandlers) OnProject(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.ProjectEvent)) *EventHandlers

OnProject Project handler.

func (*EventHandlers) OnProjectCard

func (c *EventHandlers) OnProjectCard(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.ProjectCardEvent)) *EventHandlers

OnProjectCard ProjectCard handler.

func (*EventHandlers) OnProjectColumn

func (c *EventHandlers) OnProjectColumn(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.ProjectColumnEvent)) *EventHandlers

OnProjectColumn ProjectColumn handler.

func (*EventHandlers) OnPublic

func (c *EventHandlers) OnPublic(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.PublicEvent)) *EventHandlers

OnPublic Public handler.

func (*EventHandlers) OnPullRequest

func (c *EventHandlers) OnPullRequest(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.PullRequestEvent)) *EventHandlers

OnPullRequest PullRequest handler.

func (*EventHandlers) OnPullRequestReview

func (c *EventHandlers) OnPullRequestReview(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.PullRequestReviewEvent)) *EventHandlers

OnPullRequestReview PullRequestReview handler.

func (*EventHandlers) OnPullRequestReviewComment

func (c *EventHandlers) OnPullRequestReviewComment(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.PullRequestReviewCommentEvent)) *EventHandlers

OnPullRequestReviewComment PullRequestReviewComment handler.

func (*EventHandlers) OnPush

func (c *EventHandlers) OnPush(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.PushEvent)) *EventHandlers

OnPush Push handler.

func (*EventHandlers) OnRelease

func (c *EventHandlers) OnRelease(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.ReleaseEvent)) *EventHandlers

OnRelease Release handler.

func (*EventHandlers) OnRepository

func (c *EventHandlers) OnRepository(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.RepositoryEvent)) *EventHandlers

OnRepository Repository handler.

func (*EventHandlers) OnRepositoryImport

func (c *EventHandlers) OnRepositoryImport(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *RepositoryImportEvent)) *EventHandlers

OnRepositoryImport RepositoryImport handler.

func (*EventHandlers) OnRepositoryVulnerabilityAlert

func (c *EventHandlers) OnRepositoryVulnerabilityAlert(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.RepositoryVulnerabilityAlertEvent)) *EventHandlers

OnRepositoryVulnerabilityAlert RepositoryVulnerabilityAlert handler.

func (*EventHandlers) OnSecurityAdvisory

func (c *EventHandlers) OnSecurityAdvisory(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *SecurityAdvisoryEvent)) *EventHandlers

OnSecurityAdvisory SecurityAdvisory handler.

func (*EventHandlers) OnStatus

func (c *EventHandlers) OnStatus(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.StatusEvent)) *EventHandlers

OnStatus Status handler.

func (*EventHandlers) OnTeam

func (c *EventHandlers) OnTeam(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.TeamEvent)) *EventHandlers

OnTeam Team handler.

func (*EventHandlers) OnTeamAdd

func (c *EventHandlers) OnTeamAdd(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.TeamAddEvent)) *EventHandlers

OnTeamAdd TeamAdd handler.

func (*EventHandlers) OnWatch

func (c *EventHandlers) OnWatch(eventHandler func(uri *url.URL, payload *github.WebHookPayload, event *github.WatchEvent)) *EventHandlers

OnWatch Watch handler.

type FirstPatchedVersion

type FirstPatchedVersion struct {
	Identifier *string `json:"identifier,omitempty"`
}

FirstPatchedVersion represents a GitHub Security Advisory First Patched Version.

func (*FirstPatchedVersion) GetIdentifier

func (f *FirstPatchedVersion) GetIdentifier() string

GetIdentifier returns the Identifier field if it's non-nil, zero value otherwise.

type Identifiers

type Identifiers struct {
	Value *string `json:"value,omitempty"`
	Type  *string `json:"type,omitempty"`
}

Identifiers represents a GitHub Security Advisory Identifiers.

func (*Identifiers) GetType

func (i *Identifiers) GetType() string

GetType returns the Type field if it's non-nil, zero value otherwise.

func (*Identifiers) GetValue

func (i *Identifiers) GetValue() string

GetValue returns the Value field if it's non-nil, zero value otherwise.

type Package

type Package struct {
	Ecosystem *string `json:"ecosystem,omitempty"`
	Name      *string `json:"name,omitempty"`
}

Package represents a GitHub Security Advisory Package.

func (*Package) GetEcosystem

func (p *Package) GetEcosystem() string

GetEcosystem returns the Ecosystem field if it's non-nil, zero value otherwise.

func (*Package) GetName

func (p *Package) GetName() string

GetName returns the Name field if it's non-nil, zero value otherwise.

type References

type References struct {
	URL *string `json:"url,omitempty"`
}

References represents a GitHub Security Advisory References.

func (*References) GetURL

func (r *References) GetURL() string

GetURL returns the URL field if it's non-nil, zero value otherwise.

type RepositoryImportEvent

type RepositoryImportEvent struct {
	Status       *string              `json:"status,omitempty"`
	Repo         *github.Repository   `json:"repository,omitempty"`
	Organization *github.Organization `json:"organization,omitempty"`
	Sender       *github.User         `json:"sender,omitempty"`
}

RepositoryImportEvent is triggered when a successful, canceled, or failed repository import finishes for a GitHub organization or a personal repository.

GitHub API docs: https://developer.github.com/v3/activity/events/types/#repositoryimportevent

func (*RepositoryImportEvent) GetOrganization

func (r *RepositoryImportEvent) GetOrganization() *github.Organization

GetOrganization returns the Organization field.

func (*RepositoryImportEvent) GetRepo

func (r *RepositoryImportEvent) GetRepo() *github.Repository

GetRepo returns the Repo field.

func (*RepositoryImportEvent) GetSender

func (r *RepositoryImportEvent) GetSender() *github.User

GetSender returns the Sender field.

func (*RepositoryImportEvent) GetStatus

func (r *RepositoryImportEvent) GetStatus() string

GetStatus returns the Status field if it's non-nil, zero value otherwise.

type SecurityAdvisory

type SecurityAdvisory struct {
	GhsaID          *string           `json:"ghsa_id,omitempty"`
	Summary         *string           `json:"summary,omitempty"`
	Description     *string           `json:"description,omitempty"`
	Severity        *string           `json:"severity,omitempty"`
	Identifiers     []Identifiers     `json:"identifiers,omitempty"`
	References      []References      `json:"references,omitempty"`
	PublishedAt     *github.Timestamp `json:"published_at,omitempty"`
	UpdatedAt       *github.Timestamp `json:"updated_at,omitempty"`
	WithdrawnAt     *github.Timestamp `json:"withdrawn_at,omitempty"`
	Vulnerabilities []Vulnerabilities `json:"vulnerabilities,omitempty"`
}

SecurityAdvisory represents a GitHub Security Advisory.

func (*SecurityAdvisory) GetDescription

func (s *SecurityAdvisory) GetDescription() string

GetDescription returns the Description field if it's non-nil, zero value otherwise.

func (*SecurityAdvisory) GetGhsaID

func (s *SecurityAdvisory) GetGhsaID() string

GetGhsaID returns the GhsaID field if it's non-nil, zero value otherwise.

func (*SecurityAdvisory) GetPublishedAt

func (s *SecurityAdvisory) GetPublishedAt() github.Timestamp

GetPublishedAt returns the PublishedAt field if it's non-nil, zero value otherwise.

func (*SecurityAdvisory) GetSeverity

func (s *SecurityAdvisory) GetSeverity() string

GetSeverity returns the Severity field if it's non-nil, zero value otherwise.

func (*SecurityAdvisory) GetSummary

func (s *SecurityAdvisory) GetSummary() string

GetSummary returns the Summary field if it's non-nil, zero value otherwise.

func (*SecurityAdvisory) GetUpdatedAt

func (s *SecurityAdvisory) GetUpdatedAt() github.Timestamp

GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise.

func (*SecurityAdvisory) GetWithdrawnAt

func (s *SecurityAdvisory) GetWithdrawnAt() github.Timestamp

GetWithdrawnAt returns the WithdrawnAt field if it's non-nil, zero value otherwise.

type SecurityAdvisoryEvent

type SecurityAdvisoryEvent struct {
	Action           *string           `json:"action,omitempty"`
	SecurityAdvisory *SecurityAdvisory `json:"security_advisory,omitempty"`
}

SecurityAdvisoryEvent is triggered when a new security advisory is published, updated, or withdrawn. A security advisory provides information about security-related vulnerabilities in software on GitHub.

GitHub API docs: https://developer.github.com/v3/activity/events/types/#securityadvisoryevent

func (*SecurityAdvisoryEvent) GetAction

func (s *SecurityAdvisoryEvent) GetAction() string

GetAction returns the Action field if it's non-nil, zero value otherwise.

func (*SecurityAdvisoryEvent) GetSecurityAdvisory

func (s *SecurityAdvisoryEvent) GetSecurityAdvisory() *SecurityAdvisory

GetSecurityAdvisory returns the SecurityAdvisory field.

type Vulnerabilities

type Vulnerabilities struct {
	Package                *Package             `json:"package,omitempty"`
	Severity               *string              `json:"severity,omitempty"`
	VulnerableVersionRange *string              `json:"vulnerable_version_range,omitempty"`
	FirstPatchedVersion    *FirstPatchedVersion `json:"first_patched_version,omitempty"`
}

Vulnerabilities represents a GitHub Security Advisory Vulnerabilities.

func (*Vulnerabilities) GetFirstPatchedVersion

func (v *Vulnerabilities) GetFirstPatchedVersion() *FirstPatchedVersion

GetFirstPatchedVersion returns the FirstPatchedVersion field.

func (*Vulnerabilities) GetPackage

func (v *Vulnerabilities) GetPackage() *Package

GetPackage returns the Package field.

func (*Vulnerabilities) GetSeverity

func (v *Vulnerabilities) GetSeverity() string

GetSeverity returns the Severity field if it's non-nil, zero value otherwise.

func (*Vulnerabilities) GetVulnerableVersionRange

func (v *Vulnerabilities) GetVulnerableVersionRange() string

GetVulnerableVersionRange returns the VulnerableVersionRange field if it's non-nil, zero value otherwise.

type WebHook

type WebHook struct {
	// contains filtered or unexported fields
}

WebHook server

func NewWebHook

func NewWebHook(eventHandlers *EventHandlers, options ...serverOption) *WebHook

NewWebHook create a new server as a GitHub WebHook.

func (*WebHook) ListenAndServe

func (s *WebHook) ListenAndServe() error

ListenAndServe run GitHub WebHook server.

func (*WebHook) ServeHTTP

func (s *WebHook) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP HTTP server handler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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