Fork of https://github.com/go-playground/webhooks with support for Gitea
Go to file
Dean Karn 4f72f9c366
Update README.md
2022-04-29 21:59:45 -07:00
.github/workflows Windows support to be checked... 2021-01-23 04:33:26 +03:00
_examples Preparations for the go modules way of work 2021-01-10 01:30:18 +03:00
bitbucket Preparations for the go modules way of work 2021-01-10 01:30:18 +03:00
bitbucket-server Preparations for the go modules way of work 2021-01-10 01:30:18 +03:00
docker Preparations for the go modules way of work 2021-01-10 01:30:18 +03:00
github Fixed test for integration installation events. 2022-03-08 11:04:06 +05:30
gitlab Merge pull request #135 from thedemoncat/v6 2021-11-16 19:55:58 +03:00
gogs misc updates 2018-07-31 08:49:07 -07:00
testdata Fixed test for integration installation events. 2022-03-08 11:04:06 +05:30
.gitignore ignore IDEA 2018-03-19 14:26:32 +08:00
.golangci.yml Preparations for the go modules way of work 2021-01-10 01:30:18 +03:00
LICENSE Initial commit 2015-10-25 13:38:13 -04:00
Makefile Fixed tests & minor changes in Makefile 2021-01-23 03:58:58 +03:00
README.md Update README.md 2022-04-29 21:59:45 -07:00
go.mod Preparations for the go modules way of work 2021-01-10 01:30:18 +03:00
go.sum Preparations for the go modules way of work 2021-01-10 01:30:18 +03:00
logo.png Update README 2016-02-18 16:48:04 -05:00

README.md

Library webhooks

Project status Test Coverage Status Go Report Card GoDoc License

Library webhooks allows for easy receiving and parsing of GitHub, Bitbucket and GitLab Webhook Events

Features:

  • Parses the entire payload, not just a few fields.
  • Fields + Schema directly lines up with webhook posted json

Notes:

  • Currently only accepting json payloads.

Installation

Use go get.

go get -u github.com/go-playground/webhooks/v6

Then import the package into your own code.

import "github.com/go-playground/webhooks/v6"

Usage and Documentation

Please see http://godoc.org/github.com/go-playground/webhooks/v6 for detailed usage docs.

Examples:
package main

import (
	"fmt"

	"net/http"

	"github.com/go-playground/webhooks/v6/github"
)

const (
	path = "/webhooks"
)

func main() {
	hook, _ := github.New(github.Options.Secret("MyGitHubSuperSecretSecrect...?"))

	http.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
		payload, err := hook.Parse(r, github.ReleaseEvent, github.PullRequestEvent)
		if err != nil {
			if err == github.ErrEventNotFound {
				// ok event wasn;t one of the ones asked to be parsed
			}
		}
		switch payload.(type) {

		case github.ReleasePayload:
			release := payload.(github.ReleasePayload)
			// Do whatever you want from here...
			fmt.Printf("%+v", release)

		case github.PullRequestPayload:
			pullRequest := payload.(github.PullRequestPayload)
			// Do whatever you want from here...
			fmt.Printf("%+v", pullRequest)
		}
	})
	http.ListenAndServe(":3000", nil)
}

Contributing

Pull requests for other services are welcome!

If the changes being proposed or requested are breaking changes, please create an issue for discussion.

License

Distributed under MIT License, please see license file in code for more details.