Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
gopkg.in/go-playground/webhooks.v3
Library webhooks allows for easy receiving and parsing of GitHub, Bitbucket and GitLab Webhook Events
Features:
Notes:
Use go get.
go get -u gopkg.in/go-playground/webhooks.v3
Then import the package into your own code.
import "gopkg.in/go-playground/webhooks.v3"
Please see http://godoc.org/gopkg.in/go-playground/webhooks.v3 for detailed usage docs.
Multiple Handlers for each event you subscribe to
package main
import (
"fmt"
"strconv"
"gopkg.in/go-playground/webhooks.v3"
"gopkg.in/go-playground/webhooks.v3/github"
)
const (
path = "/webhooks"
port = 3016
)
func main() {
hook := github.New(&github.Config{Secret: "MyGitHubSuperSecretSecrect...?"})
hook.RegisterEvents(HandleRelease, github.ReleaseEvent)
hook.RegisterEvents(HandlePullRequest, github.PullRequestEvent)
err := webhooks.Run(hook, ":"+strconv.Itoa(port), path)
if err != nil {
fmt.Println(err)
}
}
// HandleRelease handles GitHub release events
func HandleRelease(payload interface{}, header webhooks.Header) {
fmt.Println("Handling Release")
pl := payload.(github.ReleasePayload)
// only want to compile on full releases
if pl.Release.Draft || pl.Release.Prerelease || pl.Release.TargetCommitish != "master" {
return
}
// Do whatever you want from here...
fmt.Printf("%+v", pl)
}
// HandlePullRequest handles GitHub pull_request events
func HandlePullRequest(payload interface{}, header webhooks.Header) {
fmt.Println("Handling Pull Request")
pl := payload.(github.PullRequestPayload)
// Do whatever you want from here...
fmt.Printf("%+v", pl)
}
Single receiver for events you subscribe to
package main
import (
"fmt"
"strconv"
"gopkg.in/go-playground/webhooks.v3"
"gopkg.in/go-playground/webhooks.v3/github"
)
const (
path = "/webhooks"
port = 3016
)
func main() {
hook := github.New(&github.Config{Secret: "MyGitHubSuperSecretSecrect...?"})
hook.RegisterEvents(HandleMultiple, github.ReleaseEvent, github.PullRequestEvent) // Add as many as you want
err := webhooks.Run(hook, ":"+strconv.Itoa(port), path)
if err != nil {
fmt.Println(err)
}
}
// HandleMultiple handles multiple GitHub events
func HandleMultiple(payload interface{}, header webhooks.Header) {
fmt.Println("Handling Payload..")
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)
}
}
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.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.