Categorygithub.com/ldez/ghwebhook/v2
modulepackage
2.1.0
Repository: https://github.com/ldez/ghwebhook.git
Documentation: pkg.go.dev

# 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

# Packages

No description provided by the author

# Functions

Debug activate debug mode.
NewEventHandlers create a new event handlers.
NewWebHook create a new server as a GitHub WebHook.
WithAllEventTypes accept all possible event types.
WithEventTypes define accepted event types.
WithPath define the HTTP handler path.
WithPort define the server port.
WithSecret define the GitHub secret.

# Structs

ContentReference represents a GitHub Content Reference.
ContentReferenceEvent is triggered when the body or comment of an issue or pull request includes a URL that matches a configured content reference domain.
EventHandlers all event handlers.
FirstPatchedVersion represents a GitHub Security Advisory First Patched Version.
Identifiers represents a GitHub Security Advisory Identifiers.
Package represents a GitHub Security Advisory Package.
References represents a GitHub Security Advisory References.
RepositoryImportEvent is triggered when a successful, canceled, or failed repository import finishes for a GitHub organization or a personal repository.
SecurityAdvisory represents a GitHub Security Advisory.
SecurityAdvisoryEvent is triggered when a new security advisory is published, updated, or withdrawn.
Vulnerabilities represents a GitHub Security Advisory Vulnerabilities.
WebHook server.