go-playground/webhooks

Repository files navigation

Project statusTestCoverage StatusGo Report CardGoDocLicense

Library webhooks allows for easy receiving and parsing of , Bitbucket, GitLab, Docker Hub, Gogs and Azure DevOps 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.

Use go get.

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

Then import the package into your own code.

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

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

package main

import (
	"fmt"

	"net/http"

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

const (
	path = "/webhooks"
)

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

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

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

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

Pull requests for other services are welcome!

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

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

About

🎣 Webhook receiver for , Bitbucket, GitLab, Gogs

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 68

Languages