Skip to content

pongsatt/webhooks

This branch is 2 commits ahead of, 52 commits behind go-playground/webhooks:v5.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d300518 Â· Jun 14, 2019
Aug 4, 2018
Mar 31, 2019
Aug 9, 2018
Nov 28, 2018
Jun 14, 2019
May 22, 2019
May 20, 2019
Jul 31, 2018
Jun 14, 2019
Mar 19, 2018
Mar 31, 2019
Oct 25, 2015
Jul 31, 2018
May 23, 2019
Jun 9, 2019
Jun 14, 2019
Feb 18, 2016

Repository files navigation

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.

About

🎣 Webhook receiver for GitHub, Bitbucket and GitLab

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.8%
  • Makefile 0.2%