forked from go-playground/webhooks
/
main.go
51 lines (38 loc) · 1.13 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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)
}