caddy_webhook

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2021 License: MIT Imports: 19 Imported by: 0

README

caddy-webhook

Caddy v2 module for serving a webhook.

Build

Installation

xcaddy build \
  --with github.com/WingLim/caddy-webhook

Usage

Now supported webhook type:

  • github
  • gitlab
  • gitee
  • bitbucket
Caddyfile Format
webhook [<url> <path>] {
    repo    <text>
    path    <text>
    branch  <text>
    depth   <int>
    type    <text>
    secret  <text>
    command <text>...
    submodule
}
  • repo - git repository url.
  • path - path to clone and update repository.
  • branch - branch to pull. Default is main.
  • depth - depth for pull. Default is 0.
  • type - webhook type. Default is github.
  • secret - secret to verify webhook request.
  • submodule - enable recurse submodules
  • command - the command run when repo initializes or get the correct webhook request
Example

The full example to run a hugo blog:

Caddyfile:

example.com

root * blog/www
file_server

route /webhook {
    webhook {
        repo https://github.com/WingLim/winglim.github.io.git
        path blog
        branch hugo
        command hugo --destination www
        submodule   
    }
}

This Caddyfile will clone https://github.com/WingLim/winglim.github.io.git to directory blog when initializes.

Then run the command hugo --destination www inside the blog to generate our blog to www.

When receive webhook request in /webhook which we set it route, will update the repo and run command again.

Documentation

Index

Constants

View Source
const (
	DefaultRemote = "origin"
	DefaultBranch = "main"
)

Variables

This section is empty.

Functions

func ValidateRequest

func ValidateRequest(r *http.Request) error

ValidateRequest validates webhook request, the webhook request should be POST.

Types

type Cmd

type Cmd struct {
	Command string
	Args    []string
	Path    string
}

func (*Cmd) AddCommand

func (c *Cmd) AddCommand(command []string, path string)

func (*Cmd) Run

func (c *Cmd) Run(logger *zap.Logger)

type Repo

type Repo struct {
	URL       string
	Path      string
	Branch    string
	Depth     int
	Secret    string
	Submodule git.SubmoduleRescursivity
	// contains filtered or unexported fields
}

Repo tells information about the git repository.

func NewRepo

func NewRepo(w *WebHook) *Repo

NewRepo creates a new repo with options.

func (*Repo) Setup

func (r *Repo) Setup(ctx context.Context) error

Setup initializes the git repository by either cloning or opening it.

func (*Repo) Update

func (r *Repo) Update(ctx context.Context) error

Update pulls updates from the remote repository into current worktree.

type WebHook

type WebHook struct {
	Repository string   `json:"repo,omitempty"`
	Path       string   `json:"path,omitempty"`
	Branch     string   `json:"branch,omitempty"`
	Type       string   `json:"type,omitempty"`
	Secret     string   `json:"secret,omitempty"`
	Depth      string   `json:"depth,omitempty"`
	Submodule  bool     `json:"submodule,omitempty"`
	Command    []string `json:"command,omitempty"`
	// contains filtered or unexported fields
}

WebHook is the module configuration.

func (*WebHook) CaddyModule

func (*WebHook) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*WebHook) Provision

func (w *WebHook) Provision(ctx caddy.Context) error

Provision set's up webhook configuration.

func (*WebHook) ServeHTTP

func (w *WebHook) ServeHTTP(rw http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*WebHook) UnmarshlCaddyfile

func (w *WebHook) UnmarshlCaddyfile(d *caddyfile.Dispenser) error

UnmarshCaddyfile configures the handler directive from Caddyfile. Syntax:

webhook [<url> <path>] {
	repo		<text>
	path 		<text>
	branch 		<text>
	depth		<int>
	type 		<text>
	secret		<text>
	command		<test>...
	submodule
}

func (*WebHook) Validate

func (w *WebHook) Validate() error

Validate ensures webhook's configuration is valid.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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