responder

package module
v0.0.0-...-b9d1ee7 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 21 Imported by: 0

README

github-responder

Build hairyhenderson/github-responder on DockerHub

A library & CLI tool that automatically sets up GitHub WebHooks and listens for events, with automatic TLS provided by certmagic.

For example, if you want to run a command every time someone stars your repo (the watch event):

$ github-responder --repo my/repo --domain myhost.example.com -e watch ./ring-the-bell.sh
...

This will do a bunch of things:

  1. Register a new Webhook at the named repo (--repo)
  2. Start a web server to serve webhook events
  3. Run the command ring-the-bell.sh every time a watch event is received

A few more details:

  • github-responder is reasonably secure:
    • the webhook server is automatically protected by TLS, configured with a free automatically-renewing certificate from Let's Encrypt
    • the webhook listens at a randomly-generated URL - all other traffic is rejected
    • incoming events must be signed by a randomly-generated secret key - every event is verified
  • the command is provided with all event details:
    • the event type is provided as the first flag on the command line
    • the unique delivery ID is provided as the second flag on the command line (this can be used to de-duplicate events, which may be re-delivered in some cases)
    • the event payload is sent to the command as standard input (in JSON format)
  • logs are output as structured JSON, or in a slightly easier-to-read format when run in an interactive terminal
  • github-responder can be used as a library in other Go programs

License

The MIT License

Copyright (c) 2018 Dave Henderson

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MetricsRegisterer is the registry that this service's metrics will be collected
	// by. Overwrite it to use a different registry.
	MetricsRegisterer = prometheus.DefaultRegisterer

	// MetricsGatherer is the registry that this service's metrics will be collected
	// by. Overwrite it to use a different registry.
	MetricsGatherer = prometheus.DefaultGatherer
)

Functions

This section is empty.

Types

type HookHandler

type HookHandler func(ctx context.Context, eventType, deliveryID string, payload []byte)

HookHandler - A function that will be executed by the callback.

Payload is provided as []byte, and can be parsed with github.ParseWebHook if desired

type Responder

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

Responder -

func New

func New(repos []string, domain string, actions ...HookHandler) (*Responder, error)

New -

func (*Responder) Listen

func (r *Responder) Listen(ctx context.Context)

Listen for webhooks

func (*Responder) Register

func (r *Responder) Register(ctx context.Context, events []string) (func(), error)

Register a new webhook with the watched repositories for the listed events. A cleanup function is returned when the hook is successfully registered - this function must be called (usually deferred), otherwise invalid webhooks will be left behind.

func (*Responder) RegisterAndListen

func (r *Responder) RegisterAndListen(ctx context.Context, events []string) error

RegisterAndListen - unlike calling `Register` and `Listen` separately, this will block while waiting for the context to be cancelled.

func (*Responder) ServeHTTP

func (r *Responder) ServeHTTP(resp http.ResponseWriter, req *http.Request)

Directories

Path Synopsis
cmd
github-responder
The github-responder command
The github-responder command

Jump to

Keyboard shortcuts

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