Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e0ece40df | |||
| 60d6ca11e3 | |||
| 622d26f48f | |||
| 53781ac0e7 | |||
| 16a6ac7a61 |
@@ -1,11 +1,11 @@
|
|||||||
Library webhooks
|
Library webhooks
|
||||||
================
|
================
|
||||||
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v1/logo.png">
|
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v2/logo.png">
|
||||||

|

|
||||||
[](https://semaphoreci.com/joeybloggs/webhooks)
|
[](https://semaphoreci.com/joeybloggs/webhooks)
|
||||||
[](https://coveralls.io/github/go-playground/webhooks?branch=v1)
|
[](https://coveralls.io/github/go-playground/webhooks?branch=v2)
|
||||||
[](https://goreportcard.com/report/go-playground/webhooks)
|
[](https://goreportcard.com/report/go-playground/webhooks)
|
||||||
[](https://godoc.org/gopkg.in/go-playground/webhooks.v1)
|
[](https://godoc.org/gopkg.in/go-playground/webhooks.v2)
|
||||||

|

|
||||||
|
|
||||||
Library webhooks allows for easy recieving and parsing of GitHub & Bitbucket Webhook Events
|
Library webhooks allows for easy recieving and parsing of GitHub & Bitbucket Webhook Events
|
||||||
@@ -24,20 +24,18 @@ Installation
|
|||||||
|
|
||||||
Use go get.
|
Use go get.
|
||||||
|
|
||||||
go get gopkg.in/go-playground/webhooks.v1
|
```shell
|
||||||
|
go get -u gopkg.in/go-playground/webhooks.v2
|
||||||
or to update
|
```
|
||||||
|
|
||||||
go get -u gopkg.in/go-playground/webhooks.v1
|
|
||||||
|
|
||||||
Then import the validator package into your own code.
|
Then import the validator package into your own code.
|
||||||
|
|
||||||
import "gopkg.in/go-playground/webhooks.v1"
|
import "gopkg.in/go-playground/webhooks.v2"
|
||||||
|
|
||||||
Usage and documentation
|
Usage and documentation
|
||||||
------
|
------
|
||||||
|
|
||||||
Please see http://godoc.org/gopkg.in/go-playground/webhooks.v1 for detailed usage docs.
|
Please see http://godoc.org/gopkg.in/go-playground/webhooks.v2 for detailed usage docs.
|
||||||
|
|
||||||
##### Examples:
|
##### Examples:
|
||||||
|
|
||||||
@@ -49,8 +47,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v2"
|
||||||
"gopkg.in/go-playground/webhooks.v1/github"
|
"gopkg.in/go-playground/webhooks.v2/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -59,6 +57,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
hook := github.New(&github.Config{Secret: "MyGitHubSuperSecretSecrect...?"})
|
hook := github.New(&github.Config{Secret: "MyGitHubSuperSecretSecrect...?"})
|
||||||
hook.RegisterEvents(HandleRelease, github.ReleaseEvent)
|
hook.RegisterEvents(HandleRelease, github.ReleaseEvent)
|
||||||
hook.RegisterEvents(HandlePullRequest, github.PullRequestEvent)
|
hook.RegisterEvents(HandlePullRequest, github.PullRequestEvent)
|
||||||
@@ -70,7 +69,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HandleRelease handles GitHub release events
|
// HandleRelease handles GitHub release events
|
||||||
func HandleRelease(payload interface{}) {
|
func HandleRelease(payload interface{}, header webhooks.Header) {
|
||||||
|
|
||||||
fmt.Println("Handling Release")
|
fmt.Println("Handling Release")
|
||||||
|
|
||||||
@@ -86,7 +85,7 @@ func HandleRelease(payload interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HandlePullRequest handles GitHub pull_request events
|
// HandlePullRequest handles GitHub pull_request events
|
||||||
func HandlePullRequest(payload interface{}) {
|
func HandlePullRequest(payload interface{}, header webhooks.Header) {
|
||||||
|
|
||||||
fmt.Println("Handling Pull Request")
|
fmt.Println("Handling Pull Request")
|
||||||
|
|
||||||
@@ -95,6 +94,7 @@ func HandlePullRequest(payload interface{}) {
|
|||||||
// Do whatever you want from here...
|
// Do whatever you want from here...
|
||||||
fmt.Printf("%+v", pl)
|
fmt.Printf("%+v", pl)
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Single receiver for events you subscribe to
|
Single receiver for events you subscribe to
|
||||||
@@ -105,8 +105,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v2"
|
||||||
"gopkg.in/go-playground/webhooks.v1/github"
|
"gopkg.in/go-playground/webhooks.v2/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -115,6 +115,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
hook := github.New(&github.Config{Secret: "MyGitHubSuperSecretSecrect...?"})
|
hook := github.New(&github.Config{Secret: "MyGitHubSuperSecretSecrect...?"})
|
||||||
hook.RegisterEvents(HandleMultiple, github.ReleaseEvent, github.PullRequestEvent) // Add as many as you want
|
hook.RegisterEvents(HandleMultiple, github.ReleaseEvent, github.PullRequestEvent) // Add as many as you want
|
||||||
|
|
||||||
@@ -125,7 +126,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HandleMultiple handles multiple GitHub events
|
// HandleMultiple handles multiple GitHub events
|
||||||
func HandleMultiple(payload interface{}) {
|
func HandleMultiple(payload interface{}, header webhooks.Header) {
|
||||||
|
|
||||||
fmt.Println("Handling Payload..")
|
fmt.Println("Handling Payload..")
|
||||||
|
|
||||||
|
|||||||
+24
-22
@@ -5,7 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Webhook instance contains all methods needed to process events
|
// Webhook instance contains all methods needed to process events
|
||||||
@@ -100,80 +100,82 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hd := webhooks.Header(r.Header)
|
||||||
|
|
||||||
switch bitbucketEvent {
|
switch bitbucketEvent {
|
||||||
case RepoPushEvent:
|
case RepoPushEvent:
|
||||||
var pl RepoPushPayload
|
var pl RepoPushPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case RepoForkEvent:
|
case RepoForkEvent:
|
||||||
var pl RepoForkPayload
|
var pl RepoForkPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case RepoCommitCommentCreatedEvent:
|
case RepoCommitCommentCreatedEvent:
|
||||||
var pl RepoCommitCommentCreatedPayload
|
var pl RepoCommitCommentCreatedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case RepoCommitStatusCreatedEvent:
|
case RepoCommitStatusCreatedEvent:
|
||||||
var pl RepoCommitStatusCreatedPayload
|
var pl RepoCommitStatusCreatedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case RepoCommitStatusUpdatedEvent:
|
case RepoCommitStatusUpdatedEvent:
|
||||||
var pl RepoCommitStatusUpdatedPayload
|
var pl RepoCommitStatusUpdatedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case IssueCreatedEvent:
|
case IssueCreatedEvent:
|
||||||
var pl IssueCreatedPayload
|
var pl IssueCreatedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case IssueUpdatedEvent:
|
case IssueUpdatedEvent:
|
||||||
var pl IssueUpdatedPayload
|
var pl IssueUpdatedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case IssueCommentCreatedEvent:
|
case IssueCommentCreatedEvent:
|
||||||
var pl IssueCommentCreatedPayload
|
var pl IssueCommentCreatedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case PullRequestCreatedEvent:
|
case PullRequestCreatedEvent:
|
||||||
var pl PullRequestCreatedPayload
|
var pl PullRequestCreatedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case PullRequestUpdatedEvent:
|
case PullRequestUpdatedEvent:
|
||||||
var pl PullRequestUpdatedPayload
|
var pl PullRequestUpdatedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case PullRequestApprovedEvent:
|
case PullRequestApprovedEvent:
|
||||||
var pl PullRequestApprovedPayload
|
var pl PullRequestApprovedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case PullRequestApprovalRemovedEvent:
|
case PullRequestApprovalRemovedEvent:
|
||||||
var pl PullRequestApprovalRemovedPayload
|
var pl PullRequestApprovalRemovedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case PullRequestMergedEvent:
|
case PullRequestMergedEvent:
|
||||||
var pl PullRequestMergedPayload
|
var pl PullRequestMergedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case PullRequestDeclinedEvent:
|
case PullRequestDeclinedEvent:
|
||||||
var pl PullRequestDeclinedPayload
|
var pl PullRequestDeclinedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case PullRequestCommentCreatedEvent:
|
case PullRequestCommentCreatedEvent:
|
||||||
var pl PullRequestCommentCreatedPayload
|
var pl PullRequestCommentCreatedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case PullRequestCommentUpdatedEvent:
|
case PullRequestCommentUpdatedEvent:
|
||||||
var pl PullRequestCommentUpdatedPayload
|
var pl PullRequestCommentUpdatedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
case PullRequestCommentDeletedEvent:
|
case PullRequestCommentDeletedEvent:
|
||||||
var pl PullRequestCommentDeletedPayload
|
var pl PullRequestCommentDeletedPayload
|
||||||
json.Unmarshal([]byte(payload), &pl)
|
json.Unmarshal([]byte(payload), &pl)
|
||||||
hook.runProcessPayloadFunc(fn, pl)
|
hook.runProcessPayloadFunc(fn, pl, hd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hook Webhook) runProcessPayloadFunc(fn webhooks.ProcessPayloadFunc, results interface{}) {
|
func (hook Webhook) runProcessPayloadFunc(fn webhooks.ProcessPayloadFunc, results interface{}, header webhooks.Header) {
|
||||||
go func(fn webhooks.ProcessPayloadFunc, results interface{}) {
|
go func(fn webhooks.ProcessPayloadFunc, results interface{}, header webhooks.Header) {
|
||||||
fn(results)
|
fn(results, header)
|
||||||
}(fn, results)
|
}(fn, results, header)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "gopkg.in/go-playground/assert.v1"
|
. "gopkg.in/go-playground/assert.v1"
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NOTES:
|
// NOTES:
|
||||||
@@ -29,7 +29,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// HandlePayload handles GitHub event(s)
|
// HandlePayload handles GitHub event(s)
|
||||||
func HandlePayload(payload interface{}) {
|
func HandlePayload(payload interface{}, header webhooks.Header) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v2"
|
||||||
"gopkg.in/go-playground/webhooks.v1/github"
|
"gopkg.in/go-playground/webhooks.v2/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -14,6 +14,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
hook := github.New(&github.Config{Secret: "MyGitHubSuperSecretSecrect...?"})
|
hook := github.New(&github.Config{Secret: "MyGitHubSuperSecretSecrect...?"})
|
||||||
hook.RegisterEvents(HandleRelease, github.ReleaseEvent)
|
hook.RegisterEvents(HandleRelease, github.ReleaseEvent)
|
||||||
hook.RegisterEvents(HandlePullRequest, github.PullRequestEvent)
|
hook.RegisterEvents(HandlePullRequest, github.PullRequestEvent)
|
||||||
@@ -25,7 +26,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HandleRelease handles GitHub release events
|
// HandleRelease handles GitHub release events
|
||||||
func HandleRelease(payload interface{}) {
|
func HandleRelease(payload interface{}, header webhooks.Header) {
|
||||||
|
|
||||||
fmt.Println("Handling Release")
|
fmt.Println("Handling Release")
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ func HandleRelease(payload interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HandlePullRequest handles GitHub pull_request events
|
// HandlePullRequest handles GitHub pull_request events
|
||||||
func HandlePullRequest(payload interface{}) {
|
func HandlePullRequest(payload interface{}, header webhooks.Header) {
|
||||||
|
|
||||||
fmt.Println("Handling Pull Request")
|
fmt.Println("Handling Pull Request")
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v2"
|
||||||
"gopkg.in/go-playground/webhooks.v1/github"
|
"gopkg.in/go-playground/webhooks.v2/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -14,6 +14,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
hook := github.New(&github.Config{Secret: "MyGitHubSuperSecretSecrect...?"})
|
hook := github.New(&github.Config{Secret: "MyGitHubSuperSecretSecrect...?"})
|
||||||
hook.RegisterEvents(HandleMultiple, github.ReleaseEvent, github.PullRequestEvent) // Add as many as you want
|
hook.RegisterEvents(HandleMultiple, github.ReleaseEvent, github.PullRequestEvent) // Add as many as you want
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HandleMultiple handles multiple GitHub events
|
// HandleMultiple handles multiple GitHub events
|
||||||
func HandleMultiple(payload interface{}) {
|
func HandleMultiple(payload interface{}, header webhooks.Header) {
|
||||||
|
|
||||||
fmt.Println("Handling Payload..")
|
fmt.Println("Handling Payload..")
|
||||||
|
|
||||||
|
|||||||
+29
-26
@@ -8,7 +8,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Webhook instance contains all methods needed to process events
|
// Webhook instance contains all methods needed to process events
|
||||||
@@ -129,96 +129,99 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make headers available to ProcessPayloadFunc as a webhooks type
|
||||||
|
hd := webhooks.Header(r.Header)
|
||||||
|
|
||||||
switch gitHubEvent {
|
switch gitHubEvent {
|
||||||
case CommitCommentEvent:
|
case CommitCommentEvent:
|
||||||
var cc CommitCommentPayload
|
var cc CommitCommentPayload
|
||||||
json.Unmarshal([]byte(payload), &cc)
|
json.Unmarshal([]byte(payload), &cc)
|
||||||
hook.runProcessPayloadFunc(fn, cc)
|
hook.runProcessPayloadFunc(fn, cc, hd)
|
||||||
case CreateEvent:
|
case CreateEvent:
|
||||||
var c CreatePayload
|
var c CreatePayload
|
||||||
json.Unmarshal([]byte(payload), &c)
|
json.Unmarshal([]byte(payload), &c)
|
||||||
hook.runProcessPayloadFunc(fn, c)
|
hook.runProcessPayloadFunc(fn, c, hd)
|
||||||
case DeleteEvent:
|
case DeleteEvent:
|
||||||
var d DeletePayload
|
var d DeletePayload
|
||||||
json.Unmarshal([]byte(payload), &d)
|
json.Unmarshal([]byte(payload), &d)
|
||||||
hook.runProcessPayloadFunc(fn, d)
|
hook.runProcessPayloadFunc(fn, d, hd)
|
||||||
case DeploymentEvent:
|
case DeploymentEvent:
|
||||||
var d DeploymentPayload
|
var d DeploymentPayload
|
||||||
json.Unmarshal([]byte(payload), &d)
|
json.Unmarshal([]byte(payload), &d)
|
||||||
hook.runProcessPayloadFunc(fn, d)
|
hook.runProcessPayloadFunc(fn, d, hd)
|
||||||
case DeploymentStatusEvent:
|
case DeploymentStatusEvent:
|
||||||
var d DeploymentStatusPayload
|
var d DeploymentStatusPayload
|
||||||
json.Unmarshal([]byte(payload), &d)
|
json.Unmarshal([]byte(payload), &d)
|
||||||
hook.runProcessPayloadFunc(fn, d)
|
hook.runProcessPayloadFunc(fn, d, hd)
|
||||||
case ForkEvent:
|
case ForkEvent:
|
||||||
var f ForkPayload
|
var f ForkPayload
|
||||||
json.Unmarshal([]byte(payload), &f)
|
json.Unmarshal([]byte(payload), &f)
|
||||||
hook.runProcessPayloadFunc(fn, f)
|
hook.runProcessPayloadFunc(fn, f, hd)
|
||||||
case GollumEvent:
|
case GollumEvent:
|
||||||
var g GollumPayload
|
var g GollumPayload
|
||||||
json.Unmarshal([]byte(payload), &g)
|
json.Unmarshal([]byte(payload), &g)
|
||||||
hook.runProcessPayloadFunc(fn, g)
|
hook.runProcessPayloadFunc(fn, g, hd)
|
||||||
case IssueCommentEvent:
|
case IssueCommentEvent:
|
||||||
var i IssueCommentPayload
|
var i IssueCommentPayload
|
||||||
json.Unmarshal([]byte(payload), &i)
|
json.Unmarshal([]byte(payload), &i)
|
||||||
hook.runProcessPayloadFunc(fn, i)
|
hook.runProcessPayloadFunc(fn, i, hd)
|
||||||
case IssuesEvent:
|
case IssuesEvent:
|
||||||
var i IssuesPayload
|
var i IssuesPayload
|
||||||
json.Unmarshal([]byte(payload), &i)
|
json.Unmarshal([]byte(payload), &i)
|
||||||
hook.runProcessPayloadFunc(fn, i)
|
hook.runProcessPayloadFunc(fn, i, hd)
|
||||||
case MemberEvent:
|
case MemberEvent:
|
||||||
var m MemberPayload
|
var m MemberPayload
|
||||||
json.Unmarshal([]byte(payload), &m)
|
json.Unmarshal([]byte(payload), &m)
|
||||||
hook.runProcessPayloadFunc(fn, m)
|
hook.runProcessPayloadFunc(fn, m, hd)
|
||||||
case MembershipEvent:
|
case MembershipEvent:
|
||||||
var m MembershipPayload
|
var m MembershipPayload
|
||||||
json.Unmarshal([]byte(payload), &m)
|
json.Unmarshal([]byte(payload), &m)
|
||||||
hook.runProcessPayloadFunc(fn, m)
|
hook.runProcessPayloadFunc(fn, m, hd)
|
||||||
case PageBuildEvent:
|
case PageBuildEvent:
|
||||||
var p PageBuildPayload
|
var p PageBuildPayload
|
||||||
json.Unmarshal([]byte(payload), &p)
|
json.Unmarshal([]byte(payload), &p)
|
||||||
hook.runProcessPayloadFunc(fn, p)
|
hook.runProcessPayloadFunc(fn, p, hd)
|
||||||
case PublicEvent:
|
case PublicEvent:
|
||||||
var p PublicPayload
|
var p PublicPayload
|
||||||
json.Unmarshal([]byte(payload), &p)
|
json.Unmarshal([]byte(payload), &p)
|
||||||
hook.runProcessPayloadFunc(fn, p)
|
hook.runProcessPayloadFunc(fn, p, hd)
|
||||||
case PullRequestReviewCommentEvent:
|
case PullRequestReviewCommentEvent:
|
||||||
var p PullRequestReviewCommentPayload
|
var p PullRequestReviewCommentPayload
|
||||||
json.Unmarshal([]byte(payload), &p)
|
json.Unmarshal([]byte(payload), &p)
|
||||||
hook.runProcessPayloadFunc(fn, p)
|
hook.runProcessPayloadFunc(fn, p, hd)
|
||||||
case PullRequestEvent:
|
case PullRequestEvent:
|
||||||
var p PullRequestPayload
|
var p PullRequestPayload
|
||||||
json.Unmarshal([]byte(payload), &p)
|
json.Unmarshal([]byte(payload), &p)
|
||||||
hook.runProcessPayloadFunc(fn, p)
|
hook.runProcessPayloadFunc(fn, p, hd)
|
||||||
case PushEvent:
|
case PushEvent:
|
||||||
var p PushPayload
|
var p PushPayload
|
||||||
json.Unmarshal([]byte(payload), &p)
|
json.Unmarshal([]byte(payload), &p)
|
||||||
hook.runProcessPayloadFunc(fn, p)
|
hook.runProcessPayloadFunc(fn, p, hd)
|
||||||
case RepositoryEvent:
|
case RepositoryEvent:
|
||||||
var r RepositoryPayload
|
var r RepositoryPayload
|
||||||
json.Unmarshal([]byte(payload), &r)
|
json.Unmarshal([]byte(payload), &r)
|
||||||
hook.runProcessPayloadFunc(fn, r)
|
hook.runProcessPayloadFunc(fn, r, hd)
|
||||||
case ReleaseEvent:
|
case ReleaseEvent:
|
||||||
var r ReleasePayload
|
var r ReleasePayload
|
||||||
json.Unmarshal([]byte(payload), &r)
|
json.Unmarshal([]byte(payload), &r)
|
||||||
hook.runProcessPayloadFunc(fn, r)
|
hook.runProcessPayloadFunc(fn, r, hd)
|
||||||
case StatusEvent:
|
case StatusEvent:
|
||||||
var s StatusPayload
|
var s StatusPayload
|
||||||
json.Unmarshal([]byte(payload), &s)
|
json.Unmarshal([]byte(payload), &s)
|
||||||
hook.runProcessPayloadFunc(fn, s)
|
hook.runProcessPayloadFunc(fn, s, hd)
|
||||||
case TeamAddEvent:
|
case TeamAddEvent:
|
||||||
var t TeamAddPayload
|
var t TeamAddPayload
|
||||||
json.Unmarshal([]byte(payload), &t)
|
json.Unmarshal([]byte(payload), &t)
|
||||||
hook.runProcessPayloadFunc(fn, t)
|
hook.runProcessPayloadFunc(fn, t, hd)
|
||||||
case WatchEvent:
|
case WatchEvent:
|
||||||
var w WatchPayload
|
var w WatchPayload
|
||||||
json.Unmarshal([]byte(payload), &w)
|
json.Unmarshal([]byte(payload), &w)
|
||||||
hook.runProcessPayloadFunc(fn, w)
|
hook.runProcessPayloadFunc(fn, w, hd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hook Webhook) runProcessPayloadFunc(fn webhooks.ProcessPayloadFunc, results interface{}) {
|
func (hook Webhook) runProcessPayloadFunc(fn webhooks.ProcessPayloadFunc, results interface{}, header webhooks.Header) {
|
||||||
go func(fn webhooks.ProcessPayloadFunc, results interface{}) {
|
go func(fn webhooks.ProcessPayloadFunc, results interface{}, header webhooks.Header) {
|
||||||
fn(results)
|
fn(results, header)
|
||||||
}(fn, results)
|
}(fn, results, header)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "gopkg.in/go-playground/assert.v1"
|
. "gopkg.in/go-playground/assert.v1"
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NOTES:
|
// NOTES:
|
||||||
@@ -29,7 +29,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// HandlePayload handles GitHub event(s)
|
// HandlePayload handles GitHub event(s)
|
||||||
func HandlePayload(payload interface{}) {
|
func HandlePayload(payload interface{}, header webhooks.Header) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -2,6 +2,9 @@ package webhooks
|
|||||||
|
|
||||||
import "net/http"
|
import "net/http"
|
||||||
|
|
||||||
|
// Webhook provides http.Header to minimize imports
|
||||||
|
type Header http.Header
|
||||||
|
|
||||||
// Provider defines the type of webhook
|
// Provider defines the type of webhook
|
||||||
type Provider int
|
type Provider int
|
||||||
|
|
||||||
@@ -34,7 +37,7 @@ type server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ProcessPayloadFunc is a common function for payload return values
|
// ProcessPayloadFunc is a common function for payload return values
|
||||||
type ProcessPayloadFunc func(payload interface{})
|
type ProcessPayloadFunc func(payload interface{}, header Header)
|
||||||
|
|
||||||
// Run runs a server
|
// Run runs a server
|
||||||
func Run(hook Webhook, addr string, path string) error {
|
func Run(hook Webhook, addr string, path string) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user