Fork of https://github.com/go-playground/webhooks with support for Gitea
Go to file
Anton Krivenko 59fb74817c Update README.md 2021-01-05 02:33:20 +03:00
_examples cleanup examples and README 2018-08-03 23:04:59 -07:00
bitbucket Update BitBucket payload 2019-07-02 10:07:43 +03:00
bitbucket-server Added support for Bitbucket server `pr:from_ref_updated` event. 2020-05-27 19:55:08 -07:00
docker #53 removing logging, remove extraneous comments 2018-11-28 11:11:43 -08:00
github Merge branch 'v5' into v5 2021-01-04 22:39:52 +03:00
gitlab Merge pull request #114 from takirala/tga/add-labels-support 2020-11-10 23:20:39 +03:00
gogs misc updates 2018-07-31 08:49:07 -07:00
testdata Merge pull request #106 from wrewolf/patch-1 2021-01-04 22:37:19 +03:00
.gitignore ignore IDEA 2018-03-19 14:26:32 +08:00
.travis.yml Merge branch 'v5' into v5 2021-01-04 22:39:52 +03:00
LICENSE Initial commit 2015-10-25 13:38:13 -04:00
Makefile misc updates 2018-07-31 08:49:07 -07:00
README.md Update README.md 2021-01-05 02:33:20 +03:00
logo.png Update README 2016-02-18 16:48:04 -05:00

README.md

Library webhooks

Project status Build Status 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 gopkg.in/go-playground/webhooks.v5

Then import the package into your own code.

import "gopkg.in/go-playground/webhooks.v5"

Usage and Documentation

Please see http://godoc.org/gopkg.in/go-playground/webhooks.v5 for detailed usage docs.

Examples:
package main

import (
	"fmt"

	"net/http"

	"gopkg.in/go-playground/webhooks.v5/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.