Compare commits
16 Commits
v1
...
debug-issue8
| Author | SHA1 | Date | |
|---|---|---|---|
| 19138534b5 | |||
| fccbba5986 | |||
| 0d7e42cf96 | |||
| c9ac93f3b3 | |||
| 2d256610b0 | |||
| 05a2f7cd8d | |||
| 5ed22cdd66 | |||
| 2e471dc89c | |||
| 64819086ff | |||
| fe7552fcf4 | |||
| ca13186bfa | |||
| 1e0ece40df | |||
| 60d6ca11e3 | |||
| 622d26f48f | |||
| 53781ac0e7 | |||
| 16a6ac7a61 |
@@ -1,14 +1,13 @@
|
|||||||
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/v3/logo.png">
|
||||||

|
[](https://semaphoreci.com/joeybloggs/webhooks)
|
||||||
[](https://semaphoreci.com/joeybloggs/webhooks)
|
[](https://coveralls.io/github/go-playground/webhooks?branch=v3)
|
||||||
[](https://coveralls.io/github/go-playground/webhooks?branch=v1)
|
|
||||||
[](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.v3)
|
||||||

|

|
||||||
|
|
||||||
Library webhooks allows for easy recieving and parsing of GitHub & Bitbucket Webhook Events
|
Library webhooks allows for easy receiving and parsing of GitHub, Bitbucket and GitLab Webhook Events
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
|
|
||||||
@@ -17,27 +16,25 @@ Features:
|
|||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
* Github - Currently only accepting json payloads.
|
* Currently only accepting json payloads.
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Use go get.
|
Use go get.
|
||||||
|
|
||||||
go get gopkg.in/go-playground/webhooks.v1
|
```shell
|
||||||
|
go get -u gopkg.in/go-playground/webhooks.v3
|
||||||
|
```
|
||||||
|
|
||||||
or to update
|
Then import the package into your own code.
|
||||||
|
|
||||||
go get -u gopkg.in/go-playground/webhooks.v1
|
import "gopkg.in/go-playground/webhooks.v3"
|
||||||
|
|
||||||
Then import the validator package into your own code.
|
Usage and Documentation
|
||||||
|
|
||||||
import "gopkg.in/go-playground/webhooks.v1"
|
|
||||||
|
|
||||||
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.v3 for detailed usage docs.
|
||||||
|
|
||||||
##### Examples:
|
##### Examples:
|
||||||
|
|
||||||
@@ -49,8 +46,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v3"
|
||||||
"gopkg.in/go-playground/webhooks.v1/github"
|
"gopkg.in/go-playground/webhooks.v3/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -59,6 +56,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,14 +68,14 @@ 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")
|
||||||
|
|
||||||
pl := payload.(github.ReleasePayload)
|
pl := payload.(github.ReleasePayload)
|
||||||
|
|
||||||
// only want to compile on full releases
|
// only want to compile on full releases
|
||||||
if pl.Release.Draft || pl.Release.Prelelease || pl.Release.TargetCommitish != "master" {
|
if pl.Release.Draft || pl.Release.Prerelease || pl.Release.TargetCommitish != "master" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +84,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")
|
||||||
|
|
||||||
@@ -105,8 +103,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v3"
|
||||||
"gopkg.in/go-playground/webhooks.v1/github"
|
"gopkg.in/go-playground/webhooks.v3/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -115,6 +113,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 +124,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..")
|
||||||
|
|
||||||
@@ -147,14 +146,9 @@ func HandleMultiple(payload interface{}) {
|
|||||||
Contributing
|
Contributing
|
||||||
------
|
------
|
||||||
|
|
||||||
Pull requests for other service like BitBucket are welcome!
|
Pull requests for other services are welcome!
|
||||||
|
|
||||||
There will always be a development branch for each version i.e. `v1-development`. In order to contribute,
|
If the changes being proposed or requested are breaking changes, please create an issue for discussion.
|
||||||
please make your pull requests against those branches.
|
|
||||||
|
|
||||||
If the changes being proposed or requested are breaking changes, please create an issue, for discussion
|
|
||||||
or create a pull request against the highest development branch for example this package has a
|
|
||||||
v1 and v1-development branch however, there will also be a v2-development branch even though v2 doesn't exist yet.
|
|
||||||
|
|
||||||
License
|
License
|
||||||
------
|
------
|
||||||
|
|||||||
+48
-41
@@ -5,7 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Webhook instance contains all methods needed to process events
|
// Webhook instance contains all methods needed to process events
|
||||||
@@ -25,23 +25,24 @@ type Event string
|
|||||||
|
|
||||||
// Bitbucket hook types
|
// Bitbucket hook types
|
||||||
const (
|
const (
|
||||||
RepoPushEvent Event = "repo:push"
|
RepoPushEvent Event = "repo:push"
|
||||||
RepoForkEvent Event = "repo:fork"
|
RepoForkEvent Event = "repo:fork"
|
||||||
RepoCommitCommentCreatedEvent Event = "repo:commit_comment_created"
|
RepoUpdatedEvent Event = "repo:updated"
|
||||||
RepoCommitStatusCreatedEvent Event = "repo:commit_status_created"
|
RepoCommitCommentCreatedEvent Event = "repo:commit_comment_created"
|
||||||
RepoCommitStatusUpdatedEvent Event = "repo:commit_status_updated"
|
RepoCommitStatusCreatedEvent Event = "repo:commit_status_created"
|
||||||
IssueCreatedEvent Event = "issue:created"
|
RepoCommitStatusUpdatedEvent Event = "repo:commit_status_updated"
|
||||||
IssueUpdatedEvent Event = "issue:updated"
|
IssueCreatedEvent Event = "issue:created"
|
||||||
IssueCommentCreatedEvent Event = "issue:comment_created"
|
IssueUpdatedEvent Event = "issue:updated"
|
||||||
PullRequestCreatedEvent Event = "pullrequest:created"
|
IssueCommentCreatedEvent Event = "issue:comment_created"
|
||||||
PullRequestUpdatedEvent Event = "pullrequest:updated"
|
PullRequestCreatedEvent Event = "pullrequest:created"
|
||||||
PullRequestApprovedEvent Event = "pullrequest:approved"
|
PullRequestUpdatedEvent Event = "pullrequest:updated"
|
||||||
PullRequestApprovalRemovedEvent Event = "pullrequest:unapproved"
|
PullRequestApprovedEvent Event = "pullrequest:approved"
|
||||||
PullRequestMergedEvent Event = "pullrequest:fulfilled"
|
PullRequestUnapprovedEvent Event = "pullrequest:unapproved"
|
||||||
PullRequestDeclinedEvent Event = "pullrequest:rejected"
|
PullRequestMergedEvent Event = "pullrequest:fulfilled"
|
||||||
PullRequestCommentCreatedEvent Event = "pullrequest:comment_created"
|
PullRequestDeclinedEvent Event = "pullrequest:rejected"
|
||||||
PullRequestCommentUpdatedEvent Event = "pullrequest:comment_updated"
|
PullRequestCommentCreatedEvent Event = "pullrequest:comment_created"
|
||||||
PullRequestCommentDeletedEvent Event = "pull_request:comment_deleted"
|
PullRequestCommentUpdatedEvent Event = "pullrequest:comment_updated"
|
||||||
|
PullRequestCommentDeletedEvent Event = "pull_request:comment_deleted"
|
||||||
)
|
)
|
||||||
|
|
||||||
// New creates and returns a WebHook instance denoted by the Provider type
|
// New creates and returns a WebHook instance denoted by the Provider type
|
||||||
@@ -100,80 +101,86 @@ 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 RepoUpdatedEvent:
|
||||||
|
var pl RepoUpdatedPayload
|
||||||
|
json.Unmarshal([]byte(payload), &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 PullRequestUnapprovedEvent:
|
||||||
var pl PullRequestApprovalRemovedPayload
|
var pl PullRequestUnapprovedPayload
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|||||||
+183
-27
@@ -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.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NOTES:
|
// NOTES:
|
||||||
@@ -24,12 +24,12 @@ import (
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
const (
|
const (
|
||||||
port = 3010
|
port = 3009
|
||||||
path = "/webhooks"
|
path = "/webhooks"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandlePayload handles GitHub event(s)
|
// HandlePayload handles GitHub event(s)
|
||||||
func HandlePayload(payload interface{}) {
|
func HandlePayload(payload interface{}, header webhooks.Header) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,10 +39,30 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
// setup
|
// setup
|
||||||
hook = New(&Config{UUID: "MY_UUID"})
|
hook = New(&Config{UUID: "MY_UUID"})
|
||||||
hook.RegisterEvents(HandlePayload, RepoPushEvent, RepoForkEvent, RepoCommitCommentCreatedEvent, RepoCommitStatusCreatedEvent, RepoCommitStatusUpdatedEvent, IssueCreatedEvent, IssueUpdatedEvent, IssueCommentCreatedEvent, PullRequestCreatedEvent, PullRequestUpdatedEvent, PullRequestApprovedEvent, PullRequestApprovalRemovedEvent, PullRequestMergedEvent, PullRequestDeclinedEvent, PullRequestCommentCreatedEvent, PullRequestCommentUpdatedEvent, PullRequestCommentDeletedEvent)
|
hook.RegisterEvents(
|
||||||
|
HandlePayload,
|
||||||
|
RepoPushEvent,
|
||||||
|
RepoForkEvent,
|
||||||
|
RepoUpdatedEvent,
|
||||||
|
RepoCommitCommentCreatedEvent,
|
||||||
|
RepoCommitStatusCreatedEvent,
|
||||||
|
RepoCommitStatusUpdatedEvent,
|
||||||
|
IssueCreatedEvent,
|
||||||
|
IssueUpdatedEvent,
|
||||||
|
IssueCommentCreatedEvent,
|
||||||
|
PullRequestCreatedEvent,
|
||||||
|
PullRequestUpdatedEvent,
|
||||||
|
PullRequestApprovedEvent,
|
||||||
|
PullRequestUnapprovedEvent,
|
||||||
|
PullRequestMergedEvent,
|
||||||
|
PullRequestDeclinedEvent,
|
||||||
|
PullRequestCommentCreatedEvent,
|
||||||
|
PullRequestCommentUpdatedEvent,
|
||||||
|
PullRequestCommentDeletedEvent,
|
||||||
|
)
|
||||||
|
|
||||||
go webhooks.Run(hook, "127.0.0.1:"+strconv.Itoa(port), path)
|
go webhooks.Run(hook, "127.0.0.1:"+strconv.Itoa(port), path)
|
||||||
time.Sleep(5000)
|
time.Sleep(time.Millisecond * 500)
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|
||||||
@@ -56,7 +76,7 @@ func TestProvider(t *testing.T) {
|
|||||||
func TestUUIDMissingEvent(t *testing.T) {
|
func TestUUIDMissingEvent(t *testing.T) {
|
||||||
payload := "{}"
|
payload := "{}"
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Event-Key", "noneexistant_event")
|
req.Header.Set("X-Event-Key", "noneexistant_event")
|
||||||
|
|
||||||
@@ -74,7 +94,7 @@ func TestUUIDMissingEvent(t *testing.T) {
|
|||||||
func TestUUIDDoesNotMatchEvent(t *testing.T) {
|
func TestUUIDDoesNotMatchEvent(t *testing.T) {
|
||||||
payload := "{}"
|
payload := "{}"
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "THIS_DOES_NOT_MATCH")
|
req.Header.Set("X-Hook-UUID", "THIS_DOES_NOT_MATCH")
|
||||||
|
|
||||||
@@ -92,7 +112,7 @@ func TestUUIDDoesNotMatchEvent(t *testing.T) {
|
|||||||
func TestBadNoEventHeader(t *testing.T) {
|
func TestBadNoEventHeader(t *testing.T) {
|
||||||
payload := "{}"
|
payload := "{}"
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
|
|
||||||
@@ -110,7 +130,7 @@ func TestBadNoEventHeader(t *testing.T) {
|
|||||||
func TestUnsubscribedEvent(t *testing.T) {
|
func TestUnsubscribedEvent(t *testing.T) {
|
||||||
payload := "{}"
|
payload := "{}"
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "noneexistant_event")
|
req.Header.Set("X-Event-Key", "noneexistant_event")
|
||||||
@@ -129,7 +149,7 @@ func TestUnsubscribedEvent(t *testing.T) {
|
|||||||
func TestBadBody(t *testing.T) {
|
func TestBadBody(t *testing.T) {
|
||||||
payload := ""
|
payload := ""
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "repo:push")
|
req.Header.Set("X-Event-Key", "repo:push")
|
||||||
@@ -355,7 +375,7 @@ func TestRepoPush(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "repo:push")
|
req.Header.Set("X-Event-Key", "repo:push")
|
||||||
@@ -429,7 +449,7 @@ func TestRepoFork(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "repo:fork")
|
req.Header.Set("X-Event-Key", "repo:fork")
|
||||||
@@ -445,6 +465,142 @@ func TestRepoFork(t *testing.T) {
|
|||||||
Equal(t, resp.StatusCode, http.StatusOK)
|
Equal(t, resp.StatusCode, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRepoUpdated(t *testing.T) {
|
||||||
|
|
||||||
|
payload := `{
|
||||||
|
"actor": {
|
||||||
|
"type": "user",
|
||||||
|
"username": "emmap1",
|
||||||
|
"display_name": "Emma",
|
||||||
|
"uuid": "{a54f16da-24e9-4d7f-a3a7-b1ba2cd98aa3}",
|
||||||
|
"links": {
|
||||||
|
"self": {
|
||||||
|
"href": "https://api.bitbucket.org/api/2.0/users/emmap1"
|
||||||
|
},
|
||||||
|
"html": {
|
||||||
|
"href": "https://api.bitbucket.org/emmap1"
|
||||||
|
},
|
||||||
|
"avatar": {
|
||||||
|
"href": "https://bitbucket-api-assetroot.s3.amazonaws.com/c/photos/2015/Feb/26/3613917261-0-emmap1-avatar_avatar.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "repository",
|
||||||
|
"links": {
|
||||||
|
"self": {
|
||||||
|
"href": "https://api.bitbucket.org/api/2.0/repositories/bitbucket/bitbucket"
|
||||||
|
},
|
||||||
|
"html": {
|
||||||
|
"href": "https://api.bitbucket.org/bitbucket/bitbucket"
|
||||||
|
},
|
||||||
|
"avatar": {
|
||||||
|
"href": "https://api-staging-assetroot.s3.amazonaws.com/c/photos/2014/Aug/01/bitbucket-logo-2629490769-3_avatar.png"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"uuid": "{673a6070-3421-46c9-9d48-90745f7bfe8e}",
|
||||||
|
"project": {
|
||||||
|
"type": "project",
|
||||||
|
"project": "Untitled project",
|
||||||
|
"uuid": "{3b7898dc-6891-4225-ae60-24613bb83080}",
|
||||||
|
"links": {
|
||||||
|
"html": {
|
||||||
|
"href": "https://bitbucket.org/account/user/teamawesome/projects/proj"
|
||||||
|
},
|
||||||
|
"avatar": {
|
||||||
|
"href": "https://bitbucket.org/account/user/teamawesome/projects/proj/avatar/32"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"key": "proj"
|
||||||
|
},
|
||||||
|
"full_name": "team_name/repo_name",
|
||||||
|
"name": "repo_name",
|
||||||
|
"website": "https://mywebsite.com/",
|
||||||
|
"owner": {
|
||||||
|
"type": "user",
|
||||||
|
"username": "emmap1",
|
||||||
|
"display_name": "Emma",
|
||||||
|
"uuid": "{a54f16da-24e9-4d7f-a3a7-b1ba2cd98aa3}",
|
||||||
|
"links": {
|
||||||
|
"self": {
|
||||||
|
"href": "https://api.bitbucket.org/api/2.0/users/emmap1"
|
||||||
|
},
|
||||||
|
"html": {
|
||||||
|
"href": "https://api.bitbucket.org/emmap1"
|
||||||
|
},
|
||||||
|
"avatar": {
|
||||||
|
"href": "https://bitbucket-api-assetroot.s3.amazonaws.com/c/photos/2015/Feb/26/3613917261-0-emmap1-avatar_avatar.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scm": "git",
|
||||||
|
"is_private": true
|
||||||
|
},
|
||||||
|
"changes": {
|
||||||
|
"name": {
|
||||||
|
"new": "repository",
|
||||||
|
"old": "repository_name"
|
||||||
|
},
|
||||||
|
"website": {
|
||||||
|
"new": "http://www.example.com/",
|
||||||
|
"old": ""
|
||||||
|
},
|
||||||
|
"language": {
|
||||||
|
"new": "java",
|
||||||
|
"old": ""
|
||||||
|
},
|
||||||
|
"links": {
|
||||||
|
"new": {
|
||||||
|
"avatar": {
|
||||||
|
"href": "https://bitbucket.org/teamawesome/repository/avatar/32/"
|
||||||
|
},
|
||||||
|
"self": {
|
||||||
|
"href": "https://api.bitbucket.org/2.0/repositories/teamawesome/repository"
|
||||||
|
},
|
||||||
|
"html": {
|
||||||
|
"href": "https://bitbucket.org/teamawesome/repository"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"old": {
|
||||||
|
"avatar": {
|
||||||
|
"href": "https://bitbucket.org/teamawesome/repository_name/avatar/32/"
|
||||||
|
},
|
||||||
|
"self": {
|
||||||
|
"href": "https://api.bitbucket.org/2.0/repositories/teamawesome/repository_name"
|
||||||
|
},
|
||||||
|
"html": {
|
||||||
|
"href": "https://bitbucket.org/teamawesome/repository_name"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"new": "This is a better description.",
|
||||||
|
"old": "This is a description."
|
||||||
|
},
|
||||||
|
"full_name": {
|
||||||
|
"new": "teamawesome/repository",
|
||||||
|
"old": "teamawesome/repository_name"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
|
req.Header.Set("X-Event-Key", "repo:updated")
|
||||||
|
|
||||||
|
Equal(t, err, nil)
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
Equal(t, err, nil)
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
Equal(t, resp.StatusCode, http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
func TestRepoCommitCommentCreated(t *testing.T) {
|
func TestRepoCommitCommentCreated(t *testing.T) {
|
||||||
|
|
||||||
payload := `{
|
payload := `{
|
||||||
@@ -514,7 +670,7 @@ func TestRepoCommitCommentCreated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "repo:commit_comment_created")
|
req.Header.Set("X-Event-Key", "repo:commit_comment_created")
|
||||||
@@ -588,7 +744,7 @@ func TestRepoCommitStatusCreated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "repo:commit_status_created")
|
req.Header.Set("X-Event-Key", "repo:commit_status_created")
|
||||||
@@ -662,7 +818,7 @@ func TestRepoCommitStatusUpdated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "repo:commit_status_updated")
|
req.Header.Set("X-Event-Key", "repo:commit_status_updated")
|
||||||
@@ -747,7 +903,7 @@ func TestIssueCreated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "issue:created")
|
req.Header.Set("X-Event-Key", "issue:created")
|
||||||
@@ -864,7 +1020,7 @@ func TestIssueUpdated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "issue:updated")
|
req.Header.Set("X-Event-Key", "issue:updated")
|
||||||
@@ -975,7 +1131,7 @@ func TestIssueCommentCreated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "issue:comment_created")
|
req.Header.Set("X-Event-Key", "issue:comment_created")
|
||||||
@@ -1172,7 +1328,7 @@ func TestPullRequestCreated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "pullrequest:created")
|
req.Header.Set("X-Event-Key", "pullrequest:created")
|
||||||
@@ -1369,7 +1525,7 @@ func TestPullRequestUpdated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "pullrequest:updated")
|
req.Header.Set("X-Event-Key", "pullrequest:updated")
|
||||||
@@ -1585,7 +1741,7 @@ func TestPullRequestApproved(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "pullrequest:approved")
|
req.Header.Set("X-Event-Key", "pullrequest:approved")
|
||||||
@@ -1801,7 +1957,7 @@ func TestPullRequestApprovalRemoved(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "pullrequest:unapproved")
|
req.Header.Set("X-Event-Key", "pullrequest:unapproved")
|
||||||
@@ -1998,7 +2154,7 @@ func TestPullRequestMerged(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "pullrequest:fulfilled")
|
req.Header.Set("X-Event-Key", "pullrequest:fulfilled")
|
||||||
@@ -2195,7 +2351,7 @@ func TestPullRequestDeclined(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "pullrequest:rejected")
|
req.Header.Set("X-Event-Key", "pullrequest:rejected")
|
||||||
@@ -2418,7 +2574,7 @@ func TestPullRequestCommentCreated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "pullrequest:comment_created")
|
req.Header.Set("X-Event-Key", "pullrequest:comment_created")
|
||||||
@@ -2641,7 +2797,7 @@ func TestPullRequestCommentUpdated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "pullrequest:comment_updated")
|
req.Header.Set("X-Event-Key", "pullrequest:comment_updated")
|
||||||
@@ -2864,7 +3020,7 @@ func TestPullRequestCommentDeleted(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
req.Header.Set("X-Hook-UUID", "MY_UUID")
|
||||||
req.Header.Set("X-Event-Key", "pull_request:comment_deleted")
|
req.Header.Set("X-Event-Key", "pull_request:comment_deleted")
|
||||||
|
|||||||
+457
-337
@@ -2,388 +2,508 @@ package bitbucket
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
// PullRequestCommentDeletedPayload is the Bitbucket pull_request:comment_deleted payload
|
// RepoPushPayload is the Bitbucket repo:push payload
|
||||||
type PullRequestCommentDeletedPayload struct {
|
type RepoPushPayload struct {
|
||||||
Actor User `json:"actor"`
|
Actor Owner `json:"actor"`
|
||||||
Repository Repository `json:"repository"`
|
|
||||||
PullRequest PullRequest `json:"pullrequest"`
|
|
||||||
Comment Comment `json:"comment"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PullRequestCommentUpdatedPayload is the Bitbucket pullrequest:comment_updated payload
|
|
||||||
type PullRequestCommentUpdatedPayload struct {
|
|
||||||
Actor User `json:"actor"`
|
|
||||||
Repository Repository `json:"repository"`
|
|
||||||
PullRequest PullRequest `json:"pullrequest"`
|
|
||||||
Comment Comment `json:"comment"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PullRequestCommentCreatedPayload is the Bitbucket pullrequest:comment_created payload
|
|
||||||
type PullRequestCommentCreatedPayload struct {
|
|
||||||
Actor User `json:"actor"`
|
|
||||||
Repository Repository `json:"repository"`
|
|
||||||
PullRequest PullRequest `json:"pullrequest"`
|
|
||||||
Comment Comment `json:"comment"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PullRequestDeclinedPayload is the Bitbucket pullrequest:rejected payload
|
|
||||||
type PullRequestDeclinedPayload struct {
|
|
||||||
Actor User `json:"actor"`
|
|
||||||
PullRequest PullRequest `json:"pullrequest"`
|
|
||||||
Repository Repository `json:"repository"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PullRequestMergedPayload is the Bitbucket pullrequest:fulfilled payload
|
|
||||||
type PullRequestMergedPayload struct {
|
|
||||||
Actor User `json:"actor"`
|
|
||||||
PullRequest PullRequest `json:"pullrequest"`
|
|
||||||
Repository Repository `json:"repository"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PullRequestApprovalRemovedPayload is the Bitbucket pullrequest:unapproved payload
|
|
||||||
type PullRequestApprovalRemovedPayload struct {
|
|
||||||
Actor User `json:"actor"`
|
|
||||||
PullRequest PullRequest `json:"pullrequest"`
|
|
||||||
Repository Repository `json:"repository"`
|
|
||||||
Approval Approval `json:"approval"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PullRequestApprovedPayload is the Bitbucket pullrequest:approved payload
|
|
||||||
type PullRequestApprovedPayload struct {
|
|
||||||
Actor User `json:"actor"`
|
|
||||||
PullRequest PullRequest `json:"pullrequest"`
|
|
||||||
Repository Repository `json:"repository"`
|
|
||||||
Approval Approval `json:"approval"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PullRequestUpdatedPayload is the Bitbucket pullrequest:updated payload
|
|
||||||
type PullRequestUpdatedPayload struct {
|
|
||||||
Actor User `json:"actor"`
|
|
||||||
PullRequest PullRequest `json:"pullrequest"`
|
|
||||||
Repository Repository `json:"repository"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PullRequestCreatedPayload is the Bitbucket pullrequest:created payload
|
|
||||||
type PullRequestCreatedPayload struct {
|
|
||||||
Actor User `json:"actor"`
|
|
||||||
PullRequest PullRequest `json:"pullrequest"`
|
|
||||||
Repository Repository `json:"repository"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// IssueCommentCreatedPayload is the Bitbucket issue:comment_created payload
|
|
||||||
type IssueCommentCreatedPayload struct {
|
|
||||||
Actor User `json:"actor"`
|
|
||||||
Repository Repository `json:"repository"`
|
Repository Repository `json:"repository"`
|
||||||
Issue Issue `json:"issue"`
|
Push struct {
|
||||||
Comment Comment `json:"comment"`
|
Changes []struct {
|
||||||
}
|
New struct {
|
||||||
|
Type string `json:"type"`
|
||||||
// IssueUpdatedPayload is the Bitbucket issue:updated payload
|
Name string `json:"name"`
|
||||||
type IssueUpdatedPayload struct {
|
Target struct {
|
||||||
Actor User `json:"actor"`
|
Type string `json:"type"`
|
||||||
Issue Issue `json:"issue"`
|
Hash string `json:"hash"`
|
||||||
Repository Repository `json:"repository"`
|
Author Owner `json:"author"`
|
||||||
Comment Comment `json:"comment"`
|
Message string `json:"message"`
|
||||||
Changes IssueChanges `json:"changes"`
|
Date time.Time `json:"date"`
|
||||||
}
|
Parents []struct {
|
||||||
|
Type string `json:"type"`
|
||||||
// IssueCreatedPayload is the Bitbucket issue:created payload
|
Hash string `json:"hash"`
|
||||||
type IssueCreatedPayload struct {
|
Links struct {
|
||||||
Actor User `json:"actor"`
|
Self struct {
|
||||||
Issue Issue `json:"issue"`
|
Href string `json:"href"`
|
||||||
Repository Repository `json:"repository"`
|
} `json:"self"`
|
||||||
}
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
// RepoCommitStatusUpdatedPayload is the Bitbucket repo:commit_status_updated payload
|
} `json:"html"`
|
||||||
type RepoCommitStatusUpdatedPayload struct {
|
} `json:"links"`
|
||||||
Actor User `json:"actor"`
|
} `json:"parents"`
|
||||||
Repository Repository `json:"repository"`
|
Links struct {
|
||||||
CommitStatus CommitStatus `json:"commit_status"`
|
Self struct {
|
||||||
}
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
// RepoCommitStatusCreatedPayload is the Bitbucket repo:commit_status_created payload
|
HTML struct {
|
||||||
type RepoCommitStatusCreatedPayload struct {
|
Href string `json:"href"`
|
||||||
Actor User `json:"actor"`
|
} `json:"html"`
|
||||||
Repository Repository `json:"repository"`
|
} `json:"links"`
|
||||||
CommitStatus CommitStatus `json:"commit_status"`
|
} `json:"target"`
|
||||||
}
|
Links struct {
|
||||||
|
Self struct {
|
||||||
// RepoCommitCommentCreatedPayload is the Bitbucket repo:commit_comment_created payload
|
Href string `json:"href"`
|
||||||
type RepoCommitCommentCreatedPayload struct {
|
} `json:"self"`
|
||||||
Actor User `json:"actor"`
|
Commits struct {
|
||||||
Comment Comment `json:"comment"`
|
Href string `json:"href"`
|
||||||
Repository Repository `json:"repository"`
|
} `json:"commits"`
|
||||||
Commit CommitHash `json:"commit"`
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
} `json:"links"`
|
||||||
|
} `json:"new"`
|
||||||
|
Old struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Target struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
Author Owner `json:"author"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Date time.Time `json:"date"`
|
||||||
|
Parents []struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
Links struct {
|
||||||
|
Self struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
} `json:"links"`
|
||||||
|
} `json:"parents"`
|
||||||
|
Links struct {
|
||||||
|
Self struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
} `json:"links"`
|
||||||
|
} `json:"target"`
|
||||||
|
Links struct {
|
||||||
|
Self struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
|
Commits struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"commits"`
|
||||||
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
} `json:"links"`
|
||||||
|
} `json:"old"`
|
||||||
|
Links struct {
|
||||||
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
Diff struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"diff"`
|
||||||
|
Commits struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"commits"`
|
||||||
|
} `json:"links"`
|
||||||
|
Created bool `json:"created"`
|
||||||
|
Forced bool `json:"forced"`
|
||||||
|
Closed bool `json:"closed"`
|
||||||
|
Commits []struct {
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Author Owner `json:"author"`
|
||||||
|
Links struct {
|
||||||
|
Self struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
} `json:"links"`
|
||||||
|
} `json:"commits"`
|
||||||
|
Truncated bool `json:"truncated"`
|
||||||
|
} `json:"changes"`
|
||||||
|
} `json:"push"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepoForkPayload is the Bitbucket repo:fork payload
|
// RepoForkPayload is the Bitbucket repo:fork payload
|
||||||
type RepoForkPayload struct {
|
type RepoForkPayload struct {
|
||||||
Actor User `json:"actor"`
|
Actor Owner `json:"actor"`
|
||||||
Repository Repository `json:"repository"`
|
Repository Repository `json:"repository"`
|
||||||
Fork Repository `json:"fork"`
|
Fork Repository `json:"fork"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepoPushPayload is the Bitbucket repo:push payload
|
// RepoUpdatedPayload is the Bitbucket repo:updated payload
|
||||||
type RepoPushPayload struct {
|
type RepoUpdatedPayload struct {
|
||||||
Actor User `json:"actor"`
|
Actor Owner `json:"actor"`
|
||||||
Repository Repository `json:"repository"`
|
Repository Repository `json:"repository"`
|
||||||
Push Push `json:"push"`
|
Changes struct {
|
||||||
|
Name struct {
|
||||||
|
New string `json:"new"`
|
||||||
|
Old string `json:"old"`
|
||||||
|
} `json:"name"`
|
||||||
|
Website struct {
|
||||||
|
New string `json:"new"`
|
||||||
|
Old string `json:"old"`
|
||||||
|
} `json:"website"`
|
||||||
|
Language struct {
|
||||||
|
New string `json:"new"`
|
||||||
|
Old string `json:"old"`
|
||||||
|
} `json:"language"`
|
||||||
|
Links struct {
|
||||||
|
New struct {
|
||||||
|
Avatar struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"avatar"`
|
||||||
|
Self struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
} `json:"new"`
|
||||||
|
Old struct {
|
||||||
|
Avatar struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"avatar"`
|
||||||
|
Self struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
} `json:"old"`
|
||||||
|
} `json:"links"`
|
||||||
|
Description struct {
|
||||||
|
New string `json:"new"`
|
||||||
|
Old string `json:"old"`
|
||||||
|
} `json:"description"`
|
||||||
|
FullName struct {
|
||||||
|
New string `json:"new"`
|
||||||
|
Old string `json:"old"`
|
||||||
|
} `json:"full_name"`
|
||||||
|
} `json:"changes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Approval is the common Bitbucket Issue Approval Sub Entity
|
// RepoCommitCommentCreatedPayload is the Bitbucket repo:commit_comment_created payload
|
||||||
type Approval struct {
|
type RepoCommitCommentCreatedPayload struct {
|
||||||
Date time.Time `json:"date"`
|
Actor Owner `json:"actor"`
|
||||||
User User `json:"user"`
|
Comment Comment `json:"comment"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Commit struct {
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
} `json:"commit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IssueChanges is the common Bitbucket Issue Changes Sub Entity
|
// RepoCommitStatusCreatedPayload is the Bitbucket repo:commit_status_created payload
|
||||||
type IssueChanges struct {
|
type RepoCommitStatusCreatedPayload struct {
|
||||||
Status IssueChangeStatus `json:"status"`
|
Actor Owner `json:"actor"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
CommitStatus struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
State string `json:"state"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
CreatedOn time.Time `json:"created_on"`
|
||||||
|
UpdatedOn time.Time `json:"updated_on"`
|
||||||
|
Links struct {
|
||||||
|
Commit struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"commit"`
|
||||||
|
Self struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
|
} `json:"links"`
|
||||||
|
} `json:"commit_status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IssueChangeStatus is the common Bitbucket Issue Change Status Sub Entity
|
// RepoCommitStatusUpdatedPayload is the Bitbucket repo:commit_status_updated payload
|
||||||
type IssueChangeStatus struct {
|
type RepoCommitStatusUpdatedPayload struct {
|
||||||
Old string `json:"old"`
|
Actor Owner `json:"actor"`
|
||||||
New string `json:"new"`
|
Repository Repository `json:"repository"`
|
||||||
|
CommitStatus struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
State string `json:"state"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
CreatedOn time.Time `json:"created_on"`
|
||||||
|
UpdatedOn time.Time `json:"updated_on"`
|
||||||
|
Links struct {
|
||||||
|
Commit struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"commit"`
|
||||||
|
Self struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
|
} `json:"links"`
|
||||||
|
} `json:"commit_status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommitStatus is the common Bitbucket CommitStatus Sub Entity
|
// IssueCreatedPayload is the Bitbucket issue:created payload
|
||||||
type CommitStatus struct {
|
type IssueCreatedPayload struct {
|
||||||
Name string `json:"name"`
|
Actor Owner `json:"actor"`
|
||||||
Description string `json:"description"`
|
Issue Issue `json:"issue"`
|
||||||
State string `json:"state"`
|
Repository Repository `json:"repository"`
|
||||||
Key string `json:"key"`
|
|
||||||
URL string `json:"url"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
CreatedOn time.Time `json:"created_on"`
|
|
||||||
UpdatedOn time.Time `json:"updated_on"`
|
|
||||||
Links LinksSelfCommit `json:"links"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push is the common Bitbucket Push Sub Entity
|
// IssueUpdatedPayload is the Bitbucket issue:updated payload
|
||||||
type Push struct {
|
type IssueUpdatedPayload struct {
|
||||||
Changes []Change `json:"changes"`
|
Actor Owner `json:"actor"`
|
||||||
|
Issue Issue `json:"issue"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Comment Comment `json:"comment"`
|
||||||
|
Changes struct {
|
||||||
|
Status struct {
|
||||||
|
Old string `json:"old"`
|
||||||
|
New string `json:"new"`
|
||||||
|
} `json:"status"`
|
||||||
|
} `json:"changes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change is the common Bitbucket Change Sub Entity
|
// IssueCommentCreatedPayload is the Bitbucket pullrequest:created payload
|
||||||
type Change struct {
|
type IssueCommentCreatedPayload struct {
|
||||||
New ChangeData `json:"new"`
|
Actor Owner `json:"actor"`
|
||||||
Old ChangeData `json:"old"`
|
Repository Repository `json:"repository"`
|
||||||
Links LinksHTMLDiffCommits `json:"links"`
|
Issue Issue `json:"issue"`
|
||||||
Created bool `json:"created"`
|
Comment Comment `json:"comment"`
|
||||||
Forced bool `json:"forced"`
|
|
||||||
Closed bool `json:"closed"`
|
|
||||||
Commits []Commit `json:"commits"`
|
|
||||||
Truncated bool `json:"truncated"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangeData is the common Bitbucket ChangeData Sub Entity
|
// PullRequestCreatedPayload is the Bitbucket pullrequest:created payload
|
||||||
type ChangeData struct {
|
type PullRequestCreatedPayload struct {
|
||||||
Type string `json:"type"`
|
Actor Owner `json:"actor"`
|
||||||
Name string `json:"name"`
|
PullRequest PullRequest `json:"pullrequest"`
|
||||||
Target Target `json:"target"`
|
Repository Repository `json:"repository"`
|
||||||
Links LinksHTMLSelfCommits `json:"links"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Target is the common Bitbucket Target Sub Entity
|
// PullRequestUpdatedPayload is the Bitbucket pullrequest:updated payload
|
||||||
type Target struct {
|
type PullRequestUpdatedPayload struct {
|
||||||
Type string `json:"type"`
|
Actor Owner `json:"actor"`
|
||||||
Hash string `json:"hash"`
|
PullRequest PullRequest `json:"pullrequest"`
|
||||||
Author User `json:"author"`
|
Repository Repository `json:"repository"`
|
||||||
Message string `json:"message"`
|
|
||||||
Date time.Time `json:"date"`
|
|
||||||
Parents []Parent `json:"parents"`
|
|
||||||
Links LinksHTMLSelf `json:"links"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parent is the common Bitbucket Parent Sub Entity
|
// PullRequestApprovedPayload is the Bitbucket pullrequest:approved payload
|
||||||
type Parent struct {
|
type PullRequestApprovedPayload struct {
|
||||||
Type string `json:"type"`
|
Actor Owner `json:"actor"`
|
||||||
Hash string `json:"hash"`
|
PullRequest PullRequest `json:"pullrequest"`
|
||||||
Links LinksHTMLSelf `json:"links"`
|
Repository Repository `json:"repository"`
|
||||||
|
Approval struct {
|
||||||
|
Date time.Time `json:"date"`
|
||||||
|
User Owner `json:"user"`
|
||||||
|
} `json:"approval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit is the common Bitbucket Commit Sub Entity
|
// PullRequestUnapprovedPayload is the Bitbucket pullrequest:unapproved payload
|
||||||
type Commit struct {
|
type PullRequestUnapprovedPayload struct {
|
||||||
Hash string `json:"hash"`
|
Actor Owner `json:"actor"`
|
||||||
Type string `json:"type"`
|
PullRequest PullRequest `json:"pullrequest"`
|
||||||
Message string `json:"message"`
|
Repository Repository `json:"repository"`
|
||||||
Author User `json:"author"`
|
Approval struct {
|
||||||
Links LinksHTMLSelf `json:"links"`
|
Date time.Time `json:"date"`
|
||||||
|
User Owner `json:"user"`
|
||||||
|
} `json:"approval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// User is the common Bitbucket User Entity
|
// PullRequestMergedPayload is the Bitbucket pullrequest:fulfilled payload
|
||||||
type User struct {
|
type PullRequestMergedPayload struct {
|
||||||
|
Actor Owner `json:"actor"`
|
||||||
|
PullRequest PullRequest `json:"pullrequest"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PullRequestDeclinedPayload is the Bitbucket pullrequest:rejected payload
|
||||||
|
type PullRequestDeclinedPayload struct {
|
||||||
|
Actor Owner `json:"actor"`
|
||||||
|
PullRequest PullRequest `json:"pullrequest"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PullRequestCommentCreatedPayload is the Bitbucket pullrequest:comment_updated payload
|
||||||
|
type PullRequestCommentCreatedPayload struct {
|
||||||
|
Actor Owner `json:"actor"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
PullRequest PullRequest `json:"pullrequest"`
|
||||||
|
Comment Comment `json:"comment"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PullRequestCommentUpdatedPayload is the Bitbucket pullrequest:comment_created payload
|
||||||
|
type PullRequestCommentUpdatedPayload struct {
|
||||||
|
Actor Owner `json:"actor"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
PullRequest PullRequest `json:"pullrequest"`
|
||||||
|
Comment Comment `json:"comment"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PullRequestCommentDeletedPayload is the Bitbucket pullrequest:comment_deleted payload
|
||||||
|
type PullRequestCommentDeletedPayload struct {
|
||||||
|
Actor Owner `json:"actor"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
PullRequest PullRequest `json:"pullrequest"`
|
||||||
|
Comment Comment `json:"comment"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Owner is the common Bitbucket Owner Sub Entity
|
||||||
|
type Owner struct {
|
||||||
|
Type string `json:"type"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name"`
|
||||||
UUID string `json:"uuid"`
|
UUID string `json:"uuid"`
|
||||||
Links Links `json:"links"`
|
Links struct {
|
||||||
|
Self struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
Avatar struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"avatar"`
|
||||||
|
} `json:"links"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repository is the common Bitbucket Repository Entity
|
// Repository is the common Bitbucket Repository Sub Entity
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
Links Links `json:"links"`
|
Type string `json:"type"`
|
||||||
UUID string `json:"uuid"`
|
Links struct {
|
||||||
FullName string `json:"full_name"`
|
Self struct {
|
||||||
Name string `json:"name"`
|
Href string `json:"href"`
|
||||||
Scm string `json:"scm"`
|
} `json:"self"`
|
||||||
IsPrivate bool `json:"is_private"`
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
Avatar struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"avatar"`
|
||||||
|
} `json:"links"`
|
||||||
|
UUID string `json:"uuid"`
|
||||||
|
Project Project `json:"project"`
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Website string `json:"website"`
|
||||||
|
Owner Owner `json:"owner"`
|
||||||
|
Scm string `json:"scm"`
|
||||||
|
IsPrivate bool `json:"is_private"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue is the common Bitbucket Issue Entity
|
// Project is the common Bitbucket Project Sub Entity
|
||||||
|
type Project struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Project string `json:"project"`
|
||||||
|
UUID string `json:"uuid"`
|
||||||
|
Links struct {
|
||||||
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
Avatar struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"avatar"`
|
||||||
|
} `json:"links"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Issue is the common Bitbucket Issue Sub Entity
|
||||||
type Issue struct {
|
type Issue struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Component string `json:"component"`
|
Component string `json:"component"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Content Content `json:"content"`
|
Content struct {
|
||||||
Priority string `json:"priority"`
|
Raw string `json:"raw"`
|
||||||
State string `json:"state"`
|
HTML string `json:"html"`
|
||||||
Type string `json:"type"`
|
Markup string `json:"markup"`
|
||||||
Milestone Milestone `json:"milestone"`
|
} `json:"content"`
|
||||||
Version Version `json:"version"`
|
Priority string `json:"priority"`
|
||||||
CreatedOn time.Time `json:"created_on"`
|
State string `json:"state"`
|
||||||
UpdatedOn time.Time `json:"updated_on"`
|
Type string `json:"type"`
|
||||||
Links LinksHTMLSelf `json:"links"`
|
Milestone struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"milestone"`
|
||||||
|
Version struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"version"`
|
||||||
|
CreatedOn time.Time `json:"created_on"`
|
||||||
|
UpdatedOn time.Time `json:"updated_on"`
|
||||||
|
Links struct {
|
||||||
|
Self struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
} `json:"links"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comment is the common Bitbucket Comment Entity
|
// Comment is the common Bitbucket Comment Sub Entity
|
||||||
type Comment struct {
|
type Comment struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Parent ParentID `json:"parent"`
|
Parent struct {
|
||||||
Content Content `json:"content"`
|
ID int64 `json:"id"`
|
||||||
Inline Inline `json:"inline"`
|
} `json:"parent"`
|
||||||
CreatedOn time.Time `json:"created_on"`
|
Content struct {
|
||||||
UpdatedOn time.Time `json:"updated_on"`
|
Raw string `json:"raw"`
|
||||||
Links LinksHTMLSelf `json:"links"`
|
HTML string `json:"html"`
|
||||||
|
Markup string `json:"markup"`
|
||||||
|
} `json:"content"`
|
||||||
|
Inline struct {
|
||||||
|
Path string `json:"path"`
|
||||||
|
From *int64 `json:"from"`
|
||||||
|
To int64 `json:"to"`
|
||||||
|
} `json:"inline"`
|
||||||
|
CreatedOn time.Time `json:"created_on"`
|
||||||
|
UpdatedOn time.Time `json:"updated_on"`
|
||||||
|
Links struct {
|
||||||
|
Self struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
|
HTML struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
} `json:"html"`
|
||||||
|
} `json:"links"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PullRequest is the common Bitbucket PullRequest Entity
|
// PullRequest is the common Bitbucket Pull Request Sub Entity
|
||||||
type PullRequest struct {
|
type PullRequest struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
Author User `json:"author"`
|
Author Owner `json:"author"`
|
||||||
Source Source `json:"source"`
|
Source struct {
|
||||||
Destination Destination `json:"destination"`
|
Branch struct {
|
||||||
MergeCommit CommitHash `json:"merge_commit"`
|
Name string `json:"name"`
|
||||||
Participants []User `json:"participants"`
|
} `json:"branch"`
|
||||||
Reviewers []User `json:"reviewers"`
|
Commit struct {
|
||||||
CloseSourceBranch bool `json:"close_source_branch"`
|
Hash string `json:"hash"`
|
||||||
ClosedBy User `json:"closed_by"`
|
} `json:"commit"`
|
||||||
Reason string `json:"reason"`
|
Repository Repository `json:"repository"`
|
||||||
CreatedOn time.Time `json:"created_on"`
|
} `json:"source"`
|
||||||
UpdatedOn time.Time `json:"updated_on"`
|
Destination struct {
|
||||||
Links LinksHTMLSelf `json:"links"`
|
Branch struct {
|
||||||
}
|
Name string `json:"name"`
|
||||||
|
} `json:"branch"`
|
||||||
// Destination is the common Bitbucket Destination Sub Entity
|
Commit struct {
|
||||||
type Destination struct {
|
Hash string `json:"hash"`
|
||||||
Branch Branch `json:"branch"`
|
} `json:"commit"`
|
||||||
Commit CommitHash `json:"commit"`
|
Repository Repository `json:"repository"`
|
||||||
Repository Repository `json:"repository"`
|
} `json:"destination"`
|
||||||
}
|
MergeCommit struct {
|
||||||
|
Hash string `json:"hash"`
|
||||||
// Source is the common Bitbucket Source Sub Entity
|
} `json:"merge_commit"`
|
||||||
type Source struct {
|
Participants []Owner `json:"participants"`
|
||||||
Branch Branch `json:"branch"`
|
Reviewers []Owner `json:"reviewers"`
|
||||||
Commit CommitHash `json:"commit"`
|
CloseSourceBranch bool `json:"close_source_branch"`
|
||||||
Repository Repository `json:"repository"`
|
ClosedBy Owner `json:"closed_by"`
|
||||||
}
|
Reason string `json:"reason"`
|
||||||
|
CreatedOn time.Time `json:"created_on"`
|
||||||
// Branch is the common Bitbucket Branch Sub Entity
|
UpdatedOn time.Time `json:"updated_on"`
|
||||||
type Branch struct {
|
Links struct {
|
||||||
Name string `json:"name"`
|
Self struct {
|
||||||
}
|
Href string `json:"href"`
|
||||||
|
} `json:"self"`
|
||||||
// CommitHash is the common Bitbucket CommitHash Sub Entity
|
HTML struct {
|
||||||
type CommitHash struct {
|
Href string `json:"href"`
|
||||||
Hash string `json:"hash"`
|
} `json:"html"`
|
||||||
}
|
} `json:"links"`
|
||||||
|
|
||||||
// Inline is the common Bitbucket Inline Sub Entity
|
|
||||||
type Inline struct {
|
|
||||||
Path string `json:"path"`
|
|
||||||
From *int64 `json:"from"`
|
|
||||||
To int64 `json:"to"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParentID is the common Bitbucket ParentID Sub Entity
|
|
||||||
type ParentID struct {
|
|
||||||
ID int64 `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Avatar is the common Bitbucket Avatar Sub Entity
|
|
||||||
type Avatar struct {
|
|
||||||
HREF string `json:"href"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTML is the common Bitbucket HTML Sub Entity
|
|
||||||
type HTML struct {
|
|
||||||
HREF string `json:"href"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Self is the common Bitbucket Self Sub Entity
|
|
||||||
type Self struct {
|
|
||||||
HREF string `json:"href"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Diff is the common Bitbucket Diff Sub Entity
|
|
||||||
type Diff struct {
|
|
||||||
HREF string `json:"href"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commits is the common Bitbucket Commits Sub Entity
|
|
||||||
type Commits struct {
|
|
||||||
HREF string `json:"href"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinksSelfCommit is the common Bitbucket LinksSelfCommit Sub Entity
|
|
||||||
type LinksSelfCommit struct {
|
|
||||||
Self Self `json:"self"`
|
|
||||||
Commit Commits `json:"commit"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinksHTMLSelfCommits is the common Bitbucket LinksHTMLSelfCommits Sub Entity
|
|
||||||
type LinksHTMLSelfCommits struct {
|
|
||||||
Self Self `json:"self"`
|
|
||||||
Commits Commits `json:"commits"`
|
|
||||||
HTML HTML `json:"html"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinksHTMLDiffCommits is the common Bitbucket LinksHTMLDiffCommits Sub Entity
|
|
||||||
type LinksHTMLDiffCommits struct {
|
|
||||||
HTML HTML `json:"html"`
|
|
||||||
Diff Diff `json:"diff"`
|
|
||||||
Commits Commits `json:"commits"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Links is the common Bitbucket Links Sub Entity
|
|
||||||
type Links struct {
|
|
||||||
Avatar Avatar `json:"avatar"`
|
|
||||||
HTML HTML `json:"html"`
|
|
||||||
Self Self `json:"self"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinksHTMLSelf is the common Bitbucket LinksHTMLSelf Sub Entity
|
|
||||||
type LinksHTMLSelf struct {
|
|
||||||
HTML HTML `json:"html"`
|
|
||||||
Self Self `json:"self"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Content is the common Bitbucket Content Sub Entity
|
|
||||||
type Content struct {
|
|
||||||
HTML string `json:"html"`
|
|
||||||
Markup string `json:"markup"`
|
|
||||||
Raw string `json:"raw"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Milestone is the common Bitbucket Milestone Sub Entity
|
|
||||||
type Milestone struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Version is the common Bitbucket Version Sub Entity
|
|
||||||
type Version struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v3"
|
||||||
"gopkg.in/go-playground/webhooks.v1/github"
|
"gopkg.in/go-playground/webhooks.v3/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,14 +26,14 @@ 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")
|
||||||
|
|
||||||
pl := payload.(github.ReleasePayload)
|
pl := payload.(github.ReleasePayload)
|
||||||
|
|
||||||
// only want to compile on full releases
|
// only want to compile on full releases
|
||||||
if pl.Release.Draft || pl.Release.Prelelease || pl.Release.TargetCommitish != "master" {
|
if pl.Release.Draft || pl.Release.Prerelease || pl.Release.TargetCommitish != "master" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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.v3"
|
||||||
"gopkg.in/go-playground/webhooks.v1/github"
|
"gopkg.in/go-playground/webhooks.v3/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..")
|
||||||
|
|
||||||
|
|||||||
+212
-52
@@ -6,9 +6,10 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"gopkg.in/go-playground/webhooks.v1"
|
"gopkg.in/go-playground/webhooks.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Webhook instance contains all methods needed to process events
|
// Webhook instance contains all methods needed to process events
|
||||||
@@ -37,16 +38,25 @@ const (
|
|||||||
GollumEvent Event = "gollum"
|
GollumEvent Event = "gollum"
|
||||||
IssueCommentEvent Event = "issue_comment"
|
IssueCommentEvent Event = "issue_comment"
|
||||||
IssuesEvent Event = "issues"
|
IssuesEvent Event = "issues"
|
||||||
|
LabelEvent Event = "label"
|
||||||
MemberEvent Event = "member"
|
MemberEvent Event = "member"
|
||||||
MembershipEvent Event = "membership"
|
MembershipEvent Event = "membership"
|
||||||
|
MilestoneEvent Event = "milestone"
|
||||||
|
OrganizationEvent Event = "organization"
|
||||||
|
OrgBlockEvent Event = "org_block"
|
||||||
PageBuildEvent Event = "page_build"
|
PageBuildEvent Event = "page_build"
|
||||||
|
ProjectCardEvent Event = "project_card"
|
||||||
|
ProjectColumnEvent Event = "project_column"
|
||||||
|
ProjectEvent Event = "project"
|
||||||
PublicEvent Event = "public"
|
PublicEvent Event = "public"
|
||||||
PullRequestReviewCommentEvent Event = "pull_request_review_comment"
|
|
||||||
PullRequestEvent Event = "pull_request"
|
PullRequestEvent Event = "pull_request"
|
||||||
|
PullRequestReviewEvent Event = "pull_request_review"
|
||||||
|
PullRequestReviewCommentEvent Event = "pull_request_review_comment"
|
||||||
PushEvent Event = "push"
|
PushEvent Event = "push"
|
||||||
RepositoryEvent Event = "repository"
|
|
||||||
ReleaseEvent Event = "release"
|
ReleaseEvent Event = "release"
|
||||||
|
RepositoryEvent Event = "repository"
|
||||||
StatusEvent Event = "status"
|
StatusEvent Event = "status"
|
||||||
|
TeamEvent Event = "team"
|
||||||
TeamAddEvent Event = "team_add"
|
TeamAddEvent Event = "team_add"
|
||||||
WatchEvent Event = "watch"
|
WatchEvent Event = "watch"
|
||||||
)
|
)
|
||||||
@@ -88,6 +98,7 @@ func (hook Webhook) RegisterEvents(fn webhooks.ProcessPayloadFunc, events ...Eve
|
|||||||
// ParsePayload parses and verifies the payload and fires off the mapped function, if it exists.
|
// ParsePayload parses and verifies the payload and fires off the mapped function, if it exists.
|
||||||
func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
|
func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
log.Println("Gettting X-GitHub-Event")
|
||||||
event := r.Header.Get("X-GitHub-Event")
|
event := r.Header.Get("X-GitHub-Event")
|
||||||
if len(event) == 0 {
|
if len(event) == 0 {
|
||||||
http.Error(w, "400 Bad Request - Missing X-GitHub-Event Header", http.StatusBadRequest)
|
http.Error(w, "400 Bad Request - Missing X-GitHub-Event Header", http.StatusBadRequest)
|
||||||
@@ -96,21 +107,27 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
gitHubEvent := Event(event)
|
gitHubEvent := Event(event)
|
||||||
|
|
||||||
|
log.Println("Looking for Hook:", gitHubEvent)
|
||||||
fn, ok := hook.eventFuncs[gitHubEvent]
|
fn, ok := hook.eventFuncs[gitHubEvent]
|
||||||
// if no event registered
|
// if no event registered
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("READING PAYLOAD FROM BODY")
|
||||||
|
|
||||||
payload, err := ioutil.ReadAll(r.Body)
|
payload, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil || len(payload) == 0 {
|
if err != nil || len(payload) == 0 {
|
||||||
http.Error(w, "Error reading Body", http.StatusInternalServerError)
|
http.Error(w, "Error reading Body", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("Checking GitHub secret")
|
||||||
|
|
||||||
// If we have a Secret set, we should check the MAC
|
// If we have a Secret set, we should check the MAC
|
||||||
if len(hook.secret) > 0 {
|
if len(hook.secret) > 0 {
|
||||||
|
|
||||||
|
log.Println("Get GitHub signature")
|
||||||
signature := r.Header.Get("X-Hub-Signature")
|
signature := r.Header.Get("X-Hub-Signature")
|
||||||
|
|
||||||
if len(signature) == 0 {
|
if len(signature) == 0 {
|
||||||
@@ -123,102 +140,245 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
expectedMAC := hex.EncodeToString(mac.Sum(nil))
|
expectedMAC := hex.EncodeToString(mac.Sum(nil))
|
||||||
|
|
||||||
|
log.Println("Checking HMAC Equality")
|
||||||
|
|
||||||
if !hmac.Equal([]byte(signature[5:]), []byte(expectedMAC)) {
|
if !hmac.Equal([]byte(signature[5:]), []byte(expectedMAC)) {
|
||||||
http.Error(w, "403 Forbidden - HMAC verification failed", http.StatusForbidden)
|
http.Error(w, "403 Forbidden - HMAC verification failed", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("HMAC Equal")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make headers available to ProcessPayloadFunc as a webhooks type
|
||||||
|
hd := webhooks.Header(r.Header)
|
||||||
|
var pl interface{}
|
||||||
|
|
||||||
|
log.Println("Unmarshal based on GitHub event:", gitHubEvent)
|
||||||
|
|
||||||
switch gitHubEvent {
|
switch gitHubEvent {
|
||||||
case CommitCommentEvent:
|
case CommitCommentEvent:
|
||||||
|
|
||||||
var cc CommitCommentPayload
|
var cc CommitCommentPayload
|
||||||
json.Unmarshal([]byte(payload), &cc)
|
|
||||||
hook.runProcessPayloadFunc(fn, cc)
|
err = json.Unmarshal([]byte(payload), &cc)
|
||||||
|
pl = cc
|
||||||
|
|
||||||
case CreateEvent:
|
case CreateEvent:
|
||||||
|
|
||||||
var c CreatePayload
|
var c CreatePayload
|
||||||
json.Unmarshal([]byte(payload), &c)
|
|
||||||
hook.runProcessPayloadFunc(fn, c)
|
err = json.Unmarshal([]byte(payload), &c)
|
||||||
|
pl = c
|
||||||
|
|
||||||
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)
|
|
||||||
hook.runProcessPayloadFunc(fn, d)
|
err = json.Unmarshal([]byte(payload), &d)
|
||||||
|
pl = d
|
||||||
|
|
||||||
case DeploymentStatusEvent:
|
case DeploymentStatusEvent:
|
||||||
|
|
||||||
var d DeploymentStatusPayload
|
var d DeploymentStatusPayload
|
||||||
json.Unmarshal([]byte(payload), &d)
|
|
||||||
hook.runProcessPayloadFunc(fn, d)
|
err = json.Unmarshal([]byte(payload), &d)
|
||||||
|
pl = d
|
||||||
|
|
||||||
case ForkEvent:
|
case ForkEvent:
|
||||||
|
|
||||||
var f ForkPayload
|
var f ForkPayload
|
||||||
json.Unmarshal([]byte(payload), &f)
|
|
||||||
hook.runProcessPayloadFunc(fn, f)
|
err = json.Unmarshal([]byte(payload), &f)
|
||||||
|
pl = f
|
||||||
|
|
||||||
case GollumEvent:
|
case GollumEvent:
|
||||||
|
|
||||||
var g GollumPayload
|
var g GollumPayload
|
||||||
json.Unmarshal([]byte(payload), &g)
|
|
||||||
hook.runProcessPayloadFunc(fn, g)
|
err = json.Unmarshal([]byte(payload), &g)
|
||||||
|
pl = g
|
||||||
|
|
||||||
case IssueCommentEvent:
|
case IssueCommentEvent:
|
||||||
|
|
||||||
var i IssueCommentPayload
|
var i IssueCommentPayload
|
||||||
json.Unmarshal([]byte(payload), &i)
|
|
||||||
hook.runProcessPayloadFunc(fn, i)
|
err = json.Unmarshal([]byte(payload), &i)
|
||||||
|
pl = i
|
||||||
|
|
||||||
case IssuesEvent:
|
case IssuesEvent:
|
||||||
|
|
||||||
var i IssuesPayload
|
var i IssuesPayload
|
||||||
json.Unmarshal([]byte(payload), &i)
|
|
||||||
hook.runProcessPayloadFunc(fn, i)
|
err = json.Unmarshal([]byte(payload), &i)
|
||||||
|
pl = i
|
||||||
|
|
||||||
|
case LabelEvent:
|
||||||
|
|
||||||
|
var l LabelPayload
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(payload), &l)
|
||||||
|
pl = l
|
||||||
|
|
||||||
case MemberEvent:
|
case MemberEvent:
|
||||||
|
|
||||||
var m MemberPayload
|
var m MemberPayload
|
||||||
json.Unmarshal([]byte(payload), &m)
|
|
||||||
hook.runProcessPayloadFunc(fn, m)
|
err = json.Unmarshal([]byte(payload), &m)
|
||||||
|
pl = m
|
||||||
|
|
||||||
case MembershipEvent:
|
case MembershipEvent:
|
||||||
|
|
||||||
var m MembershipPayload
|
var m MembershipPayload
|
||||||
json.Unmarshal([]byte(payload), &m)
|
|
||||||
hook.runProcessPayloadFunc(fn, m)
|
err = json.Unmarshal([]byte(payload), &m)
|
||||||
|
pl = m
|
||||||
|
|
||||||
|
case MilestoneEvent:
|
||||||
|
|
||||||
|
var m MilestonePayload
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(payload), &m)
|
||||||
|
pl = m
|
||||||
|
|
||||||
|
case OrganizationEvent:
|
||||||
|
|
||||||
|
var o OrganizationPayload
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(payload), &o)
|
||||||
|
pl = o
|
||||||
|
|
||||||
|
case OrgBlockEvent:
|
||||||
|
|
||||||
|
var o OrgBlockPayload
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(payload), &o)
|
||||||
|
pl = o
|
||||||
|
|
||||||
case PageBuildEvent:
|
case PageBuildEvent:
|
||||||
|
|
||||||
var p PageBuildPayload
|
var p PageBuildPayload
|
||||||
json.Unmarshal([]byte(payload), &p)
|
|
||||||
hook.runProcessPayloadFunc(fn, p)
|
err = json.Unmarshal([]byte(payload), &p)
|
||||||
|
pl = p
|
||||||
|
|
||||||
|
case ProjectCardEvent:
|
||||||
|
|
||||||
|
var p ProjectCardPayload
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(payload), &p)
|
||||||
|
pl = p
|
||||||
|
|
||||||
|
case ProjectColumnEvent:
|
||||||
|
|
||||||
|
var p ProjectColumnPayload
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(payload), &p)
|
||||||
|
pl = p
|
||||||
|
|
||||||
|
case ProjectEvent:
|
||||||
|
|
||||||
|
var p ProjectPayload
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(payload), &p)
|
||||||
|
pl = p
|
||||||
|
|
||||||
case PublicEvent:
|
case PublicEvent:
|
||||||
|
|
||||||
var p PublicPayload
|
var p PublicPayload
|
||||||
json.Unmarshal([]byte(payload), &p)
|
|
||||||
hook.runProcessPayloadFunc(fn, p)
|
err = json.Unmarshal([]byte(payload), &p)
|
||||||
case PullRequestReviewCommentEvent:
|
pl = p
|
||||||
var p PullRequestReviewCommentPayload
|
|
||||||
json.Unmarshal([]byte(payload), &p)
|
|
||||||
hook.runProcessPayloadFunc(fn, p)
|
|
||||||
case PullRequestEvent:
|
case PullRequestEvent:
|
||||||
|
|
||||||
var p PullRequestPayload
|
var p PullRequestPayload
|
||||||
json.Unmarshal([]byte(payload), &p)
|
|
||||||
hook.runProcessPayloadFunc(fn, p)
|
err = json.Unmarshal([]byte(payload), &p)
|
||||||
|
pl = p
|
||||||
|
|
||||||
|
case PullRequestReviewEvent:
|
||||||
|
|
||||||
|
var p PullRequestReviewPayload
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(payload), &p)
|
||||||
|
pl = p
|
||||||
|
|
||||||
|
case PullRequestReviewCommentEvent:
|
||||||
|
|
||||||
|
var p PullRequestReviewCommentPayload
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(payload), &p)
|
||||||
|
pl = p
|
||||||
|
|
||||||
case PushEvent:
|
case PushEvent:
|
||||||
|
|
||||||
var p PushPayload
|
var p PushPayload
|
||||||
json.Unmarshal([]byte(payload), &p)
|
|
||||||
hook.runProcessPayloadFunc(fn, p)
|
err = json.Unmarshal([]byte(payload), &p)
|
||||||
case RepositoryEvent:
|
pl = p
|
||||||
var r RepositoryPayload
|
|
||||||
json.Unmarshal([]byte(payload), &r)
|
|
||||||
hook.runProcessPayloadFunc(fn, r)
|
|
||||||
case ReleaseEvent:
|
case ReleaseEvent:
|
||||||
|
|
||||||
var r ReleasePayload
|
var r ReleasePayload
|
||||||
json.Unmarshal([]byte(payload), &r)
|
|
||||||
hook.runProcessPayloadFunc(fn, r)
|
err = json.Unmarshal([]byte(payload), &r)
|
||||||
|
pl = r
|
||||||
|
|
||||||
|
case RepositoryEvent:
|
||||||
|
|
||||||
|
var r RepositoryPayload
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(payload), &r)
|
||||||
|
pl = r
|
||||||
|
|
||||||
case StatusEvent:
|
case StatusEvent:
|
||||||
|
|
||||||
var s StatusPayload
|
var s StatusPayload
|
||||||
json.Unmarshal([]byte(payload), &s)
|
|
||||||
hook.runProcessPayloadFunc(fn, s)
|
err = json.Unmarshal([]byte(payload), &s)
|
||||||
|
pl = s
|
||||||
|
|
||||||
|
case TeamEvent:
|
||||||
|
|
||||||
|
var t TeamPayload
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(payload), &t)
|
||||||
|
pl = t
|
||||||
|
|
||||||
case TeamAddEvent:
|
case TeamAddEvent:
|
||||||
|
|
||||||
var t TeamAddPayload
|
var t TeamAddPayload
|
||||||
json.Unmarshal([]byte(payload), &t)
|
|
||||||
hook.runProcessPayloadFunc(fn, t)
|
err = json.Unmarshal([]byte(payload), &t)
|
||||||
|
pl = t
|
||||||
|
|
||||||
case WatchEvent:
|
case WatchEvent:
|
||||||
|
|
||||||
var w WatchPayload
|
var w WatchPayload
|
||||||
json.Unmarshal([]byte(payload), &w)
|
|
||||||
hook.runProcessPayloadFunc(fn, w)
|
err = json.Unmarshal([]byte(payload), &w)
|
||||||
|
pl = w
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println("There was an erro parsing JSON:", err)
|
||||||
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Running runProcessPayloadFunc")
|
||||||
|
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)
|
log.Println("Calling hook function")
|
||||||
}(fn, results)
|
fn(results, header)
|
||||||
|
}(fn, results, header)
|
||||||
}
|
}
|
||||||
|
|||||||
+2170
-634
File diff suppressed because it is too large
Load Diff
+4920
-659
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,144 @@
|
|||||||
|
package gitlab
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"gopkg.in/go-playground/webhooks.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Webhook instance contains all methods needed to process events
|
||||||
|
type Webhook struct {
|
||||||
|
provider webhooks.Provider
|
||||||
|
secret string
|
||||||
|
eventFuncs map[Event]webhooks.ProcessPayloadFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config defines the configuration to create a new GitHub Webhook instance
|
||||||
|
type Config struct {
|
||||||
|
Secret string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Event defines a GitHub hook event type
|
||||||
|
type Event string
|
||||||
|
|
||||||
|
// GitLab hook types
|
||||||
|
const (
|
||||||
|
PushEvents Event = "Push Hook"
|
||||||
|
TagEvents Event = "Tag Push Hook"
|
||||||
|
IssuesEvents Event = "Issue Hook"
|
||||||
|
CommentEvents Event = "Note Hook"
|
||||||
|
MergeRequestEvents Event = "Merge Request Hook"
|
||||||
|
WikiPageEvents Event = "Wiki Page Hook"
|
||||||
|
PipelineEvents Event = "Pipeline Hook"
|
||||||
|
BuildEvents Event = "Build Hook"
|
||||||
|
)
|
||||||
|
|
||||||
|
// New creates and returns a WebHook instance denoted by the Provider type
|
||||||
|
func New(config *Config) *Webhook {
|
||||||
|
return &Webhook{
|
||||||
|
provider: webhooks.GitLab,
|
||||||
|
secret: config.Secret,
|
||||||
|
eventFuncs: map[Event]webhooks.ProcessPayloadFunc{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Provider returns the current hooks provider ID
|
||||||
|
func (hook Webhook) Provider() webhooks.Provider {
|
||||||
|
return hook.provider
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterEvents registers the function to call when the specified event(s) are encountered
|
||||||
|
func (hook Webhook) RegisterEvents(fn webhooks.ProcessPayloadFunc, events ...Event) {
|
||||||
|
|
||||||
|
for _, event := range events {
|
||||||
|
hook.eventFuncs[event] = fn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParsePayload parses and verifies the payload and fires off the mapped function, if it exists.
|
||||||
|
func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
event := r.Header.Get("X-Gitlab-Event")
|
||||||
|
if len(event) == 0 {
|
||||||
|
http.Error(w, "400 Bad Request - Missing X-Gitlab-Event Header", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
gitLabEvent := Event(event)
|
||||||
|
|
||||||
|
fn, ok := hook.eventFuncs[gitLabEvent]
|
||||||
|
// if no event registered
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
payload, err := ioutil.ReadAll(r.Body)
|
||||||
|
if err != nil || len(payload) == 0 {
|
||||||
|
http.Error(w, "Error reading Body", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have a Secret set, we should check the MAC
|
||||||
|
if len(hook.secret) > 0 {
|
||||||
|
|
||||||
|
signature := r.Header.Get("X-Gitlab-Token")
|
||||||
|
|
||||||
|
if signature != hook.secret {
|
||||||
|
http.Error(w, "403 Forbidden - Token missmatch", http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make headers available to ProcessPayloadFunc as a webhooks type
|
||||||
|
hd := webhooks.Header(r.Header)
|
||||||
|
|
||||||
|
switch gitLabEvent {
|
||||||
|
case PushEvents:
|
||||||
|
var pe PushEventPayload
|
||||||
|
json.Unmarshal([]byte(payload), &pe)
|
||||||
|
hook.runProcessPayloadFunc(fn, pe, hd)
|
||||||
|
|
||||||
|
case TagEvents:
|
||||||
|
var te TagEventPayload
|
||||||
|
json.Unmarshal([]byte(payload), &te)
|
||||||
|
hook.runProcessPayloadFunc(fn, te, hd)
|
||||||
|
|
||||||
|
case IssuesEvents:
|
||||||
|
var ie IssueEventPayload
|
||||||
|
json.Unmarshal([]byte(payload), &ie)
|
||||||
|
hook.runProcessPayloadFunc(fn, ie, hd)
|
||||||
|
|
||||||
|
case CommentEvents:
|
||||||
|
var ce CommentEventPayload
|
||||||
|
json.Unmarshal([]byte(payload), &ce)
|
||||||
|
hook.runProcessPayloadFunc(fn, ce, hd)
|
||||||
|
|
||||||
|
case MergeRequestEvents:
|
||||||
|
var mre MergeRequestEventPayload
|
||||||
|
json.Unmarshal([]byte(payload), &mre)
|
||||||
|
hook.runProcessPayloadFunc(fn, mre, hd)
|
||||||
|
|
||||||
|
case WikiPageEvents:
|
||||||
|
var wpe WikiPageEventPayload
|
||||||
|
json.Unmarshal([]byte(payload), &wpe)
|
||||||
|
hook.runProcessPayloadFunc(fn, wpe, hd)
|
||||||
|
|
||||||
|
case PipelineEvents:
|
||||||
|
var pe PipelineEventPayload
|
||||||
|
json.Unmarshal([]byte(payload), &pe)
|
||||||
|
hook.runProcessPayloadFunc(fn, pe, hd)
|
||||||
|
|
||||||
|
case BuildEvents:
|
||||||
|
var be BuildEventPayload
|
||||||
|
json.Unmarshal([]byte(payload), &be)
|
||||||
|
hook.runProcessPayloadFunc(fn, be, hd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hook Webhook) runProcessPayloadFunc(fn webhooks.ProcessPayloadFunc, results interface{}, header webhooks.Header) {
|
||||||
|
go func(fn webhooks.ProcessPayloadFunc, results interface{}, header webhooks.Header) {
|
||||||
|
fn(results, header)
|
||||||
|
}(fn, results, header)
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,404 @@
|
|||||||
|
package gitlab
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type customTime struct {
|
||||||
|
time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *customTime) UnmarshalJSON(b []byte) (err error) {
|
||||||
|
layout := []string{
|
||||||
|
"2006-01-02 15:04:05 MST",
|
||||||
|
"2006-01-02 15:04:05 Z07:00",
|
||||||
|
"2006-01-02 15:04:05 Z0700",
|
||||||
|
time.RFC3339,
|
||||||
|
}
|
||||||
|
s := strings.Trim(string(b), "\"")
|
||||||
|
if s == "null" {
|
||||||
|
t.Time = time.Time{}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, l := range layout {
|
||||||
|
t.Time, err = time.Parse(l, s)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueEventPayload contains the information for GitLab's issue event
|
||||||
|
type IssueEventPayload struct {
|
||||||
|
ObjectKind string `json:"object_kind"`
|
||||||
|
User User `json:"user"`
|
||||||
|
Project Project `json:"project"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
ObjectAttributes ObjectAttributes `json:"object_attributes"`
|
||||||
|
Assignee Assignee `json:"assignee"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MergeRequestEventPayload contains the information for GitLab's merge request event
|
||||||
|
type MergeRequestEventPayload struct {
|
||||||
|
ObjectKind string `json:"object_kind"`
|
||||||
|
User User `json:"user"`
|
||||||
|
ObjectAttributes ObjectAttributes `json:"object_attributes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushEventPayload contains the information for GitLab's push event
|
||||||
|
type PushEventPayload struct {
|
||||||
|
ObjectKind string `json:"object_kind"`
|
||||||
|
Before string `json:"before"`
|
||||||
|
After string `json:"after"`
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
CheckoutSHA string `json:"checkout_sha"`
|
||||||
|
UserID int64 `json:"user_id"`
|
||||||
|
UserName string `json:"user_name"`
|
||||||
|
UserEmail string `json:"user_email"`
|
||||||
|
UserAvatar string `json:"user_avatar"`
|
||||||
|
ProjectID int64 `json:"project_id"`
|
||||||
|
Project Project `json:"Project"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Commits []Commit `json:"commits"`
|
||||||
|
TotalCommitsCount int64 `json:"total_commits_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TagEventPayload contains the information for GitLab's tag push event
|
||||||
|
type TagEventPayload struct {
|
||||||
|
ObjectKind string `json:"object_kind"`
|
||||||
|
Before string `json:"before"`
|
||||||
|
After string `json:"after"`
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
CheckoutSHA string `json:"checkout_sha"`
|
||||||
|
UserID int64 `json:"user_id"`
|
||||||
|
UserName string `json:"user_name"`
|
||||||
|
UserAvatar string `json:"user_avatar"`
|
||||||
|
ProjectID int64 `json:"project_id"`
|
||||||
|
Project Project `json:"Project"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Commits []Commit `json:"commits"`
|
||||||
|
TotalCommitsCount int64 `json:"total_commits_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// WikiPageEventPayload contains the information for GitLab's wiki created/updated event
|
||||||
|
type WikiPageEventPayload struct {
|
||||||
|
ObjectKind string `json:"object_kind"`
|
||||||
|
User User `json:"user"`
|
||||||
|
Project Project `json:"project"`
|
||||||
|
Wiki Wiki `json:"wiki"`
|
||||||
|
ObjectAttributes ObjectAttributes `json:"object_attributes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PipelineEventPayload contains the information for GitLab's pipeline status change event
|
||||||
|
type PipelineEventPayload struct {
|
||||||
|
ObjectKind string `json:"object_kind"`
|
||||||
|
User User `json:"user"`
|
||||||
|
Project Project `json:"project"`
|
||||||
|
Commit Commit `json:"commit"`
|
||||||
|
ObjectAttributes ObjectAttributes `json:"object_attributes"`
|
||||||
|
Builds []Build `json:"builds"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CommentEventPayload contains the information for GitLab's comment event
|
||||||
|
type CommentEventPayload struct {
|
||||||
|
ObjectKind string `json:"object_kind"`
|
||||||
|
User User `json:"user"`
|
||||||
|
ProjectID int64 `json:"project_id"`
|
||||||
|
Project Project `json:"project"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
ObjectAttributes ObjectAttributes `json:"object_attributes"`
|
||||||
|
MergeRequest MergeRequest `json:"merge_request"`
|
||||||
|
Commit Commit `json:"commit"`
|
||||||
|
Issue Issue `json:"issue"`
|
||||||
|
Snippet Snippet `json:"snippet"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuildEventPayload contains the information for GitLab's build status change event
|
||||||
|
type BuildEventPayload struct {
|
||||||
|
ObjectKind string `json:"object_kind"`
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
Tag bool `json:"tag"`
|
||||||
|
BeforeSHA string `json:"before_sha"`
|
||||||
|
SHA string `json:"sha"`
|
||||||
|
BuildID int64 `json:"build_id"`
|
||||||
|
BuildName string `json:"build_name"`
|
||||||
|
BuildStage string `json:"build_stage"`
|
||||||
|
BuildStatus string `json:"build_status"`
|
||||||
|
BuildStartedAt customTime `json:"build_started_at"`
|
||||||
|
BuildFinishedAt customTime `json:"build_finished_at"`
|
||||||
|
BuildDuration int64 `json:"build_duration"`
|
||||||
|
BuildAllowFailure bool `json:"build_allow_failure"`
|
||||||
|
ProjectID int64 `json:"project_id"`
|
||||||
|
ProjectName string `json:"project_name"`
|
||||||
|
User User `json:"user"`
|
||||||
|
Commit BuildCommit `json:"commit"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Issue contains all of the GitLab issue information
|
||||||
|
type Issue struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
AssigneeID int64 `json:"assignee_id"`
|
||||||
|
AuthorID int64 `json:"author_id"`
|
||||||
|
ProjectID int64 `json:"project_id"`
|
||||||
|
CreatedAt customTime `json:"created_at"`
|
||||||
|
UpdatedAt customTime `json:"updated_at"`
|
||||||
|
Position int64 `json:"position"`
|
||||||
|
BranchName string `json:"branch_name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
MilestoneID int64 `json:"milestone_id"`
|
||||||
|
State string `json:"state"`
|
||||||
|
IID int64 `json:"iid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build contains all of the GitLab build information
|
||||||
|
type Build struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Stage string `json:"stage"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
CreatedAt customTime `json:"created_at"`
|
||||||
|
StartedAt customTime `json:"started_at"`
|
||||||
|
FinishedAt customTime `json:"finished_at"`
|
||||||
|
When string `json:"when"`
|
||||||
|
Manual bool `json:"manual"`
|
||||||
|
User User `json:"user"`
|
||||||
|
Runner string `json:"runner"`
|
||||||
|
ArtifactsFile ArtifactsFile `json:"artifactsfile"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ArtifactsFile contains all of the GitLab artifact information
|
||||||
|
type ArtifactsFile struct {
|
||||||
|
Filename string `json:"filename"`
|
||||||
|
Size string `json:"size"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wiki contains all of the GitLab wiki information
|
||||||
|
type Wiki struct {
|
||||||
|
WebURL string `json:"web_url"`
|
||||||
|
GitSSHURL string `json:"git_ssh_url"`
|
||||||
|
GitHTTPURL string `json:"git_http_url"`
|
||||||
|
PathWithNamespace string `json:"path_with_namespace"`
|
||||||
|
DefaultBranch string `json:"default_branch"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit contains all of the GitLab commit information
|
||||||
|
type Commit struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Timestamp customTime `json:"timestamp"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Author Author `json:"author"`
|
||||||
|
Added []string `json:"added"`
|
||||||
|
Modified []string `json:"modified"`
|
||||||
|
Removed []string `json:"removed"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuildCommit contains all of the GitLab build commit information
|
||||||
|
type BuildCommit struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
SHA string `json:"sha"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
AuthorName string `json:"auuthor_name"`
|
||||||
|
AuthorEmail string `json:"author_email"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Duration int64 `json:"duration"`
|
||||||
|
StartedAt customTime `json:"started_at"`
|
||||||
|
FinishedAt customTime `json:"finished_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Snippet contains all of the GitLab snippet information
|
||||||
|
type Snippet struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
AuthorID int64 `json:"author_id"`
|
||||||
|
ProjectID int64 `json:"project_id"`
|
||||||
|
CreatedAt customTime `json:"created_at"`
|
||||||
|
UpdatedAt customTime `json:"updated_at"`
|
||||||
|
FileName string `json:"file_name"`
|
||||||
|
ExpiresAt customTime `json:"expires_at"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
VisibilityLevel int64 `json:"visibility_level"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// User contains all of the GitLab user information
|
||||||
|
type User struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
UserName string `json:"username"`
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Project contains all of the GitLab project information
|
||||||
|
type Project struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
WebURL string `json:"web_url"`
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
GitSSSHURL string `json:"git_ssh_url"`
|
||||||
|
GitHTTPURL string `json:"git_http_url"`
|
||||||
|
Namespace string `json:"namespace"`
|
||||||
|
VisibilityLevel int64 `json:"visibility_level"`
|
||||||
|
PathWithNamespace string `json:"path_with_namespace"`
|
||||||
|
DefaultBranch string `json:"default_branch"`
|
||||||
|
Homepage string `json:"homepage"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
SSHURL string `json:"ssh_url"`
|
||||||
|
HTTPURL string `json:"http_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Repository contains all of the GitLab repository information
|
||||||
|
type Repository struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Homepage string `json:"homepage"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ObjectAttributes contains all of the GitLab object attributes information
|
||||||
|
type ObjectAttributes struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
AssigneeID int64 `json:"assignee_id"`
|
||||||
|
AuthorID int64 `json:"author_id"`
|
||||||
|
ProjectID int64 `json:"project_id"`
|
||||||
|
CreatedAt customTime `json:"created_at"`
|
||||||
|
UpdatedAt customTime `json:"updated_at"`
|
||||||
|
Position int64 `json:"position"`
|
||||||
|
BranchName string `json:"branch_name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
MilestoneID int64 `json:"milestone_id"`
|
||||||
|
State string `json:"state"`
|
||||||
|
IID int64 `json:"iid"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Action string `json:"action"`
|
||||||
|
TargetBranch string `json:"target_branch"`
|
||||||
|
SourceBranch string `json:"source_branch"`
|
||||||
|
SourceProjectID int64 `json:"source_project_id"`
|
||||||
|
TargetProjectID int64 `json:"target_project_id"`
|
||||||
|
StCommits string `json:"st_commits"`
|
||||||
|
MergeStatus string `json:"merge_status"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
Format string `json:"format"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
Tag bool `json:"tag"`
|
||||||
|
SHA string `json:"sha"`
|
||||||
|
BeforeSHA string `json:"before_sha"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Stages []string `json:"stages"`
|
||||||
|
Duration int64 `json:"duration"`
|
||||||
|
Note string `json:"note"`
|
||||||
|
NotebookType string `json:"noteable_type"`
|
||||||
|
At customTime `json:"attachment"`
|
||||||
|
LineCode string `json:"line_code"`
|
||||||
|
CommitID string `json:"commit_id"`
|
||||||
|
NoteableID int64 `json:"noteable_id"`
|
||||||
|
System bool `json:"system"`
|
||||||
|
WorkInProgress bool `json:"work_in_progress"`
|
||||||
|
StDiffs []StDiff `json:"st_diffs"`
|
||||||
|
Source Source `json:"source"`
|
||||||
|
Target Target `json:"target"`
|
||||||
|
LastCommit LastCommit `json:"last_commit"`
|
||||||
|
Assignee Assignee `json:"assignee"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MergeRequest contains all of the GitLab merge request information
|
||||||
|
type MergeRequest struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
TargetBranch string `json:"target_branch"`
|
||||||
|
SourceBranch string `json:"source_branch"`
|
||||||
|
SourceProjectID string `json:"source_project_id"`
|
||||||
|
AssigneeID int64 `json:"assignee_id"`
|
||||||
|
AuthorID int64 `json:"author_id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
CreatedAt customTime `json:"created_at"`
|
||||||
|
UpdatedAt customTime `json:"updated_at"`
|
||||||
|
MilestoneID int64 `json:"milestone_id"`
|
||||||
|
State string `json:"state"`
|
||||||
|
MergeStatus string `json:"merge_status"`
|
||||||
|
TargetProjectID int64 `json:"target_project_id"`
|
||||||
|
IID int64 `json:"iid"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Position int64 `json:"position"`
|
||||||
|
LockedAt customTime `json:"locked_at"`
|
||||||
|
Source Source `json:"source"`
|
||||||
|
Target Target `json:"target"`
|
||||||
|
LastCommit LastCommit `json:"last_commit"`
|
||||||
|
WorkInProgress bool `json:"work_in_progress"`
|
||||||
|
Assignee Assignee `json:"assignee"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assignee contains all of the GitLab assignee information
|
||||||
|
type Assignee struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// StDiff contains all of the GitLab diff information
|
||||||
|
type StDiff struct {
|
||||||
|
Diff string `json:"diff"`
|
||||||
|
NewPath string `json:"new_path"`
|
||||||
|
OldPath string `json:"old_path"`
|
||||||
|
AMode string `json:"a_mode"`
|
||||||
|
BMode string `json:"b_mode"`
|
||||||
|
NewFile bool `json:"new_file"`
|
||||||
|
RenamedFile bool `json:"renamed_file"`
|
||||||
|
DeletedFile bool `json:"deleted_file"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Source contains all of the GitLab source information
|
||||||
|
type Source struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
WebURL string `json:"web_url"`
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
GitSSHURL string `json:"git_ssh_url"`
|
||||||
|
GitHTTPURL string `json:"git_http_url"`
|
||||||
|
Namespace string `json:"namespace"`
|
||||||
|
VisibilityLevel int64 `json:"visibility_level"`
|
||||||
|
PathWithNamespace string `json:"path_with_namespace"`
|
||||||
|
DefaultBranch string `json:"default_branch"`
|
||||||
|
Homepage string `json:"homepage"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
SSHURL string `json:"ssh_url"`
|
||||||
|
HTTPURL string `json:"http_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Target contains all of the GitLab target information
|
||||||
|
type Target struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
WebURL string `json:"web_url"`
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
GitSSHURL string `json:"git_ssh_url"`
|
||||||
|
GitHTTPURL string `json:"git_http_url"`
|
||||||
|
Namespace string `json:"namespace"`
|
||||||
|
VisibilityLevel int64 `json:"visibility_level"`
|
||||||
|
PathWithNamespace string `json:"path_with_namespace"`
|
||||||
|
DefaultBranch string `json:"default_branch"`
|
||||||
|
Homepage string `json:"homepage"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
SSHURL string `json:"ssh_url"`
|
||||||
|
HTTPURL string `json:"http_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastCommit contains all of the GitLab last commit information
|
||||||
|
type LastCommit struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Timestamp customTime `json:"timestamp"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Author Author `json:"author"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Author contains all of the GitLab author information
|
||||||
|
type Author struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
}
|
||||||
+21
-5
@@ -1,6 +1,12 @@
|
|||||||
package webhooks
|
package webhooks
|
||||||
|
|
||||||
import "net/http"
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Header 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
|
||||||
@@ -11,6 +17,8 @@ func (p Provider) String() string {
|
|||||||
return "GitHub"
|
return "GitHub"
|
||||||
case Bitbucket:
|
case Bitbucket:
|
||||||
return "Bitbucket"
|
return "Bitbucket"
|
||||||
|
case GitLab:
|
||||||
|
return "GitLab"
|
||||||
default:
|
default:
|
||||||
return "Unknown"
|
return "Unknown"
|
||||||
}
|
}
|
||||||
@@ -20,9 +28,10 @@ func (p Provider) String() string {
|
|||||||
const (
|
const (
|
||||||
GitHub Provider = iota
|
GitHub Provider = iota
|
||||||
Bitbucket
|
Bitbucket
|
||||||
|
GitLab
|
||||||
)
|
)
|
||||||
|
|
||||||
// Webhook interface defines a webhook to recieve events
|
// Webhook interface defines a webhook to receive events
|
||||||
type Webhook interface {
|
type Webhook interface {
|
||||||
Provider() Provider
|
Provider() Provider
|
||||||
ParsePayload(w http.ResponseWriter, r *http.Request)
|
ParsePayload(w http.ResponseWriter, r *http.Request)
|
||||||
@@ -34,7 +43,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 {
|
||||||
@@ -64,7 +73,7 @@ func RunServer(s *http.Server, hook Webhook, path string) error {
|
|||||||
// RunTLSServer runs a custom server with TLS configuration.
|
// RunTLSServer runs a custom server with TLS configuration.
|
||||||
// NOTE: http.Server Handler will be overridden by this library, just set it to nil.
|
// NOTE: http.Server Handler will be overridden by this library, just set it to nil.
|
||||||
// Setting the Certificates can be done in the http.Server.TLSConfig.Certificates
|
// Setting the Certificates can be done in the http.Server.TLSConfig.Certificates
|
||||||
// see example here: https://gopkg.in/go-playground/webhooks.v1/blob/master/webhooks_test.go#L178
|
// see example here: https://github.com/go-playground/webhooks/blob/v2/webhooks_test.go#L178
|
||||||
func RunTLSServer(s *http.Server, hook Webhook, path string) error {
|
func RunTLSServer(s *http.Server, hook Webhook, path string) error {
|
||||||
|
|
||||||
srv := &server{
|
srv := &server{
|
||||||
@@ -79,16 +88,23 @@ func RunTLSServer(s *http.Server, hook Webhook, path string) error {
|
|||||||
|
|
||||||
// ServeHTTP is the Handler for every posted WebHook Event
|
// ServeHTTP is the Handler for every posted WebHook Event
|
||||||
func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
defer r.Body.Close()
|
defer func() {
|
||||||
|
log.Println("Closing Request Body")
|
||||||
|
r.Body.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
log.Println("HTTP METHOD:", r.Method)
|
||||||
if r.Method != "POST" {
|
if r.Method != "POST" {
|
||||||
http.Error(w, "405 Method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "405 Method not allowed", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("Chking that paths match:", r.URL.Path == s.path)
|
||||||
if r.URL.Path != s.path {
|
if r.URL.Path != s.path {
|
||||||
http.Error(w, "404 Not found", http.StatusNotFound)
|
http.Error(w, "404 Not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("Parsing Payload")
|
||||||
s.hook.ParsePayload(w, r)
|
s.hook.ParsePayload(w, r)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,5 +236,6 @@ func TestProviderString(t *testing.T) {
|
|||||||
|
|
||||||
Equal(t, GitHub.String(), "GitHub")
|
Equal(t, GitHub.String(), "GitHub")
|
||||||
Equal(t, Bitbucket.String(), "Bitbucket")
|
Equal(t, Bitbucket.String(), "Bitbucket")
|
||||||
|
Equal(t, GitLab.String(), "GitLab")
|
||||||
Equal(t, Provider(999999).String(), "Unknown")
|
Equal(t, Provider(999999).String(), "Unknown")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user