From 1d0289a3ae8e7ea7aad36c9040dc9f40528fa576 Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Thu, 26 Jul 2018 08:54:32 -0700 Subject: [PATCH] temp checkin --- .travis.yml | 13 +- Makefile | 17 + {examples => _examples}/custom-logger/main.go | 0 .../multiple-handlers/main.go | 0 .../single-handler/main.go | 0 bitbucket/bitbucket.go | 21 +- bitbucket/bitbucket_test.go | 5454 +++++++++-------- github/github.go | 14 +- github/github_test.go | 2 +- gitlab/gitlab.go | 22 +- gitlab/gitlab_test.go | 31 +- gogs/gogs.go | 22 +- logger.go | 44 - 13 files changed, 2806 insertions(+), 2834 deletions(-) create mode 100644 Makefile rename {examples => _examples}/custom-logger/main.go (100%) rename {examples => _examples}/multiple-handlers/main.go (100%) rename {examples => _examples}/single-handler/main.go (100%) delete mode 100644 logger.go diff --git a/.travis.yml b/.travis.yml index ffcf684..85b0687 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,8 +16,6 @@ before_install: - go get -u github.com/go-playground/overalls - go get -u github.com/mattn/goveralls - go get -u golang.org/x/tools/cmd/cover - - go get -u github.com/golang/lint/golint - - go get -u github.com/gordonklaus/ineffassign - mkdir -p $GOPATH/src/gopkg.in - ln -s $GOPATH/src/github.com/$TRAVIS_REPO_SLUG $GOPATH/src/gopkg.in/webhooks.v2 - ln -s $GOPATH/src/github.com/$TRAVIS_REPO_SLUG $GOPATH/src/gopkg.in/webhooks.v3 @@ -25,16 +23,13 @@ before_install: - ln -s $GOPATH/src/github.com/$TRAVIS_REPO_SLUG $GOPATH/src/gopkg.in/webhooks.v5 before_script: - - go vet ./... + - go get -t ./... script: - - gofmt -d -s . - - golint ./... - - ineffassign ./ - - go test -v ./... - - go test -race + - make lint + - make test after_success: | [ $TRAVIS_GO_VERSION = 1.10.3 ] && - overalls -project="github.com/go-playground/webhooks" -covermode=count -ignore=.git,examples -debug && + overalls -project="github.com/go-playground/webhooks" -covermode=count -ignore=.git,_examples,testdata -debug && goveralls -coverprofile=overalls.coverprofile -service travis-ci -repotoken $COVERALLS_TOKEN diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dce22a3 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +GOCMD=go + +linters-install: + @gometalinter --version >/dev/null 2>&1 || { \ + echo "installing linting tools..."; \ + $(GOCMD) get github.com/alecthomas/gometalinter; \ + gometalinter --install; \ + } + +lint: linters-install + @gofmt -l . >gofmt.test 2>&1 && if [ -s gofmt.test ]; then echo "Fix formatting using 'gofmt -s -w .' for:"; cat gofmt.test; exit 1; fi && rm gofmt.test + gometalinter --vendor --disable-all --enable=vet --enable=vetshadow --enable=golint --enable=maligned --enable=megacheck --enable=ineffassign --enable=misspell --enable=errcheck --enable=goconst ./... + +test: + $(GOCMD) test -cover -race ./... + +.PHONY: test lint linters-install \ No newline at end of file diff --git a/examples/custom-logger/main.go b/_examples/custom-logger/main.go similarity index 100% rename from examples/custom-logger/main.go rename to _examples/custom-logger/main.go diff --git a/examples/multiple-handlers/main.go b/_examples/multiple-handlers/main.go similarity index 100% rename from examples/multiple-handlers/main.go rename to _examples/multiple-handlers/main.go diff --git a/examples/single-handler/main.go b/_examples/single-handler/main.go similarity index 100% rename from examples/single-handler/main.go rename to _examples/single-handler/main.go diff --git a/bitbucket/bitbucket.go b/bitbucket/bitbucket.go index cd4ff76..54bbb22 100644 --- a/bitbucket/bitbucket.go +++ b/bitbucket/bitbucket.go @@ -9,14 +9,14 @@ import ( "net/http" ) -// parse errros +// parse errors var ( - ErrEventNotSpecifiedToParse = errors.New("No Event specified to parse") - ErrInvalidHTTPMethod = errors.New("Invalid HTTP Method") - ErrMissingHookUUIDHeader = errors.New("Missing X-Hook-UUID Header") - ErrMissingEventKeyHeader = errors.New("Missing X-Event-Key Header") - ErrEventNotFound = errors.New("Event not defined to be parsed") - ErrParsingPayload = errors.New("Error parsing payload") + ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse") + ErrInvalidHTTPMethod = errors.New("invalid HTTP Method") + ErrMissingHookUUIDHeader = errors.New("missing X-Hook-UUID Header") + ErrMissingEventKeyHeader = errors.New("missing X-Event-Key Header") + ErrEventNotFound = errors.New("event not defined to be parsed") + ErrParsingPayload = errors.New("error parsing payload") ErrUUIDVerificationFailed = errors.New("UUID verification failed") ) @@ -96,15 +96,16 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) if uuid == "" { return nil, ErrMissingHookUUIDHeader } - if len(hook.uuid) > 0 && uuid != hook.uuid { - return nil, ErrUUIDVerificationFailed - } event := r.Header.Get("X-Event-Key") if event == "" { return nil, ErrMissingEventKeyHeader } + if len(hook.uuid) > 0 && uuid != hook.uuid { + return nil, ErrUUIDVerificationFailed + } + bitbucketEvent := Event(event) var found bool diff --git a/bitbucket/bitbucket_test.go b/bitbucket/bitbucket_test.go index 5351422..e8a81a6 100644 --- a/bitbucket/bitbucket_test.go +++ b/bitbucket/bitbucket_test.go @@ -2,14 +2,13 @@ package bitbucket import ( "bytes" + "log" "net/http" + "net/http/httptest" "os" - "strconv" "testing" - "time" . "gopkg.in/go-playground/assert.v1" - "gopkg.in/go-playground/webhooks.v5" ) // NOTES: @@ -24,59 +23,41 @@ import ( // // const ( - port = 3009 path = "/webhooks" ) -// HandlePayload handles GitHub event(s) -func HandlePayload(payload interface{}, header webhooks.Header) { - -} - var hook *Webhook func TestMain(m *testing.M) { // setup - hook = New(&Config{UUID: "MY_UUID"}) - 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) - time.Sleep(time.Millisecond * 500) - + var err error + hook, err = New(Options.UUID("MY_UUID")) + if err != nil { + log.Fatal(err) + } os.Exit(m.Run()) // teardown } -func TestProvider(t *testing.T) { - Equal(t, hook.Provider(), webhooks.Bitbucket) +func newServer(handler http.HandlerFunc) *httptest.Server { + mux := http.NewServeMux() + mux.HandleFunc(path, handler) + return httptest.NewServer(mux) } func TestUUIDMissingEvent(t *testing.T) { payload := "{}" + var parseError error + server := newServer(func(w http.ResponseWriter, r *http.Request) { + _, parseError = hook.Parse(r, RepoPushEvent) + }) + defer server.Close() + + req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) + Equal(t, err, nil) - 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-Event-Key", "noneexistant_event") @@ -85,34 +66,47 @@ func TestUUIDMissingEvent(t *testing.T) { client := &http.Client{} resp, err := client.Do(req) Equal(t, err, nil) - - defer resp.Body.Close() - - Equal(t, resp.StatusCode, http.StatusBadRequest) + Equal(t, resp.StatusCode, http.StatusOK) + Equal(t, parseError, ErrMissingHookUUIDHeader) } func TestUUIDDoesNotMatchEvent(t *testing.T) { payload := "{}" - req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload))) + var parseError error + server := newServer(func(w http.ResponseWriter, r *http.Request) { + _, parseError = hook.Parse(r, RepoPushEvent) + }) + defer server.Close() + + req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) + Equal(t, err, nil) + req.Header.Set("Content-Type", "application/json") req.Header.Set("X-Hook-UUID", "THIS_DOES_NOT_MATCH") + req.Header.Set("X-Event-Key", "repo:push") 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.StatusForbidden) + Equal(t, resp.StatusCode, http.StatusOK) + Equal(t, parseError, ErrUUIDVerificationFailed) } func TestBadNoEventHeader(t *testing.T) { payload := "{}" - req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload))) + var parseError error + server := newServer(func(w http.ResponseWriter, r *http.Request) { + _, parseError = hook.Parse(r, RepoPushEvent) + }) + defer server.Close() + + req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) + Equal(t, err, nil) + req.Header.Set("Content-Type", "application/json") req.Header.Set("X-Hook-UUID", "MY_UUID") @@ -121,35 +115,22 @@ func TestBadNoEventHeader(t *testing.T) { client := &http.Client{} resp, err := client.Do(req) Equal(t, err, nil) - - defer resp.Body.Close() - - Equal(t, resp.StatusCode, http.StatusBadRequest) -} - -func TestUnsubscribedEvent(t *testing.T) { - 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("X-Hook-UUID", "MY_UUID") - req.Header.Set("X-Event-Key", "noneexistant_event") - - 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) + Equal(t, parseError, ErrMissingEventKeyHeader) } func TestBadBody(t *testing.T) { payload := "" - req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload))) + var parseError error + server := newServer(func(w http.ResponseWriter, r *http.Request) { + _, parseError = hook.Parse(r, RepoPushEvent) + }) + defer server.Close() + + req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) + Equal(t, err, nil) + req.Header.Set("Content-Type", "application/json") req.Header.Set("X-Hook-UUID", "MY_UUID") req.Header.Set("X-Event-Key", "repo:push") @@ -159,10 +140,33 @@ func TestBadBody(t *testing.T) { client := &http.Client{} resp, err := client.Do(req) Equal(t, err, nil) + Equal(t, resp.StatusCode, http.StatusOK) + Equal(t, parseError, ErrParsingPayload) +} - defer resp.Body.Close() +func TestUnsubscribedEvent(t *testing.T) { + payload := "{}" - Equal(t, resp.StatusCode, http.StatusInternalServerError) + var parseError error + server := newServer(func(w http.ResponseWriter, r *http.Request) { + _, parseError = hook.Parse(r, RepoPushEvent) + }) + defer server.Close() + + req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) + Equal(t, err, nil) + + req.Header.Set("Content-Type", "application/json") + req.Header.Set("X-Hook-UUID", "MY_UUID") + req.Header.Set("X-Event-Key", "noneexistant_event") + + Equal(t, err, nil) + + client := &http.Client{} + resp, err := client.Do(req) + Equal(t, err, nil) + Equal(t, resp.StatusCode, http.StatusOK) + Equal(t, parseError, ErrEventNotFound) } func TestRepoPush(t *testing.T) { @@ -375,7 +379,15 @@ func TestRepoPush(t *testing.T) { } ` - req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload))) + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, RepoPushEvent) + }) + defer server.Close() + + req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) + Equal(t, err, nil) req.Header.Set("Content-Type", "application/json") req.Header.Set("X-Hook-UUID", "MY_UUID") req.Header.Set("X-Event-Key", "repo:push") @@ -385,2653 +397,2653 @@ func TestRepoPush(t *testing.T) { client := &http.Client{} resp, err := client.Do(req) Equal(t, err, nil) - - defer resp.Body.Close() - Equal(t, resp.StatusCode, http.StatusOK) + Equal(t, parseError, nil) + _, ok := results.(RepoPushPayload) + Equal(t, ok, true) } -func TestRepoFork(t *testing.T) { - - payload := `{ - "actor":{ - "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":{ - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - }, - "fork":{ - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } -} -` - - 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:fork") - - 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 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) { - - payload := `{ - "actor":{ - "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" - } - } - }, - "comment":{ - "id":17, - "parent":{ - "id":16 - }, - "content":{ - "raw":"Comment text", - "html":"

Comment text

", - "markup":"markdown" - }, - "inline":{ - "path":"path/to/file", - "from":null, - "to":10 - }, - "created_on":"2015-04-06T16:52:29.982346+00:00", - "updated_on":"2015-04-06T16:52:29.983730+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/comments/comment_id" - }, - "html":{ - "href":"https://api.bitbucket.org/comment_id" - } - } - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - }, - "commit":{ - "hash":"d3022fc0ca3d65c7f6654eea129d6bf0cf0ee08e" - } -} -` - - 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:commit_comment_created") - - 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 TestRepoCommitStatusCreated(t *testing.T) { - - payload := `{ - "actor":{ - "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":{ - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - }, - "commit_status":{ - "name":"Unit Tests (Python)", - "description":"Build started", - "state":"INPROGRESS", - "key":"mybuildtool", - "url":"https://my-build-tool.com/builds/MY-PROJECT/BUILD-777", - "type":"build", - "created_on":"2015-11-19T20:37:35.547563+00:00", - "updated_on":"2015-11-19T20:37:35.547563+00:00", - "links":{ - "commit":{ - "href":"http://api.bitbucket.org/2.0/repositories/tk/test/commit/9fec847784abb10b2fa567ee63b85bd238955d0e" - }, - "self":{ - "href":"http://api.bitbucket.org/2.0/repositories/tk/test/commit/9fec847784abb10b2fa567ee63b85bd238955d0e/statuses/build/mybuildtool" - } - } - } -} -` - - 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:commit_status_created") - - 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 TestRepoCommitStatusUpdated(t *testing.T) { - - payload := `{ - "actor":{ - "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":{ - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - }, - "commit_status":{ - "name":"Unit Tests (Python)", - "description":"All tests passed", - "state":"SUCCESSFUL", - "key":"mybuildtool", - "url":"https://my-build-tool.com/builds/MY-PROJECT/BUILD-792", - "type":"build", - "created_on":"2015-11-19T20:37:35.547563+00:00", - "updated_on":"2015-11-20T08:01:16.433108+00:00", - "links":{ - "commit":{ - "href":"http://api.bitbucket.org/2.0/repositories/tk/test/commit/9fec847784abb10b2fa567ee63b85bd238955d0e" - }, - "self":{ - "href":"http://api.bitbucket.org/2.0/repositories/tk/test/commit/9fec847784abb10b2fa567ee63b85bd238955d0e/statuses/build/mybuildtool" - } - } - } -} -` - - 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:commit_status_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 TestIssueCreated(t *testing.T) { - - payload := `{ - "actor":{ - "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" - } - } - }, - "issue":{ - "id":1, - "component":"component", - "title":"Issue title", - "content":{ - "raw":"Issue description", - "html":"

Issue description

", - "markup":"markdown" - }, - "priority":"trivial|minor|major|critical|blocker", - "state":"new|open|on hold|resolved|duplicate|invalid|wontfix|closed", - "type":"bug|enhancement|proposal|task", - "milestone":{ - "name":"milestone 1" - }, - "version":{ - "name":"version 1" - }, - "created_on":"2015-04-06T15:23:38.179678+00:00", - "updated_on":"2015-04-06T15:23:38.179678+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/issues/issue_id" - }, - "html":{ - "href":"https://api.bitbucket.org/issue_id" - } - } - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } -} -` - - 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", "issue:created") - - 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 TestIssueUpdated(t *testing.T) { - - payload := `{ - "actor":{ - "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" - } - } - }, - "issue":{ - "id":1, - "component":"component", - "title":"Issue title", - "content":{ - "raw":"Issue description", - "html":"

Issue description

", - "markup":"markdown" - }, - "priority":"trivial|minor|major|critical|blocker", - "state":"new|open|on hold|resolved|duplicate|invalid|wontfix|closed", - "type":"bug|enhancement|proposal|task", - "milestone":{ - "name":"milestone 1" - }, - "version":{ - "name":"version 1" - }, - "created_on":"2015-04-06T15:23:38.179678+00:00", - "updated_on":"2015-04-06T15:23:38.179678+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/issues/issue_id" - }, - "html":{ - "href":"https://api.bitbucket.org/issue_id" - } - } - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - }, - "comment":{ - "id":17, - "parent":{ - "id":16 - }, - "content":{ - "raw":"Comment text", - "html":"

Comment text

", - "markup":"markdown" - }, - "inline":{ - "path":"path/to/file", - "from":null, - "to":10 - }, - "created_on":"2015-04-06T16:52:29.982346+00:00", - "updated_on":"2015-04-06T16:52:29.983730+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/comments/comment_id" - }, - "html":{ - "href":"https://api.bitbucket.org/comment_id" - } - } - }, - "changes":{ - "status":{ - "old":"open", - "new":"on hold" - } - } -} -` - - 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", "issue: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 TestIssueCommentCreated(t *testing.T) { - - payload := `{ - "actor":{ - "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":{ - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - }, - "issue":{ - "id":1, - "component":"component", - "title":"Issue title", - "content":{ - "raw":"Issue description", - "html":"

Issue description

", - "markup":"markdown" - }, - "priority":"trivial|minor|major|critical|blocker", - "state":"new|open|on hold|resolved|duplicate|invalid|wontfix|closed", - "type":"bug|enhancement|proposal|task", - "milestone":{ - "name":"milestone 1" - }, - "version":{ - "name":"version 1" - }, - "created_on":"2015-04-06T15:23:38.179678+00:00", - "updated_on":"2015-04-06T15:23:38.179678+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/issues/issue_id" - }, - "html":{ - "href":"https://api.bitbucket.org/issue_id" - } - } - }, - "comment":{ - "id":17, - "parent":{ - "id":16 - }, - "content":{ - "raw":"Comment text", - "html":"

Comment text

", - "markup":"markdown" - }, - "inline":{ - "path":"path/to/file", - "from":null, - "to":10 - }, - "created_on":"2015-04-06T16:52:29.982346+00:00", - "updated_on":"2015-04-06T16:52:29.983730+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/comments/comment_id" - }, - "html":{ - "href":"https://api.bitbucket.org/comment_id" - } - } - } -} -` - - 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", "issue:comment_created") - - 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 TestPullRequestCreated(t *testing.T) { - - payload := `{ - "actor":{ - "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" - } - } - }, - "pullrequest":{ - "id":1, - "title":"Title of pull request", - "description":"Description of pull request", - "state":"OPEN|MERGED|DECLINED", - "author":{ - "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" - } - } - }, - "source":{ - "branch":{ - "name":"branch2" - }, - "commit":{ - "hash":"d3022fc0ca3d" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "destination":{ - "branch":{ - "name":"master" - }, - "commit":{ - "hash":"ce5965ddd289" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "merge_commit":{ - "hash":"764413d85e29" - }, - "participants":[ - { - "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" - } - } - } - ], - "reviewers":[ - { - "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" - } - } - } - ], - "close_source_branch":true, - "closed_by":{ - "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" - } - } - }, - "reason":"reason for declining the PR (if applicable)", - "created_on":"2015-04-06T15:23:38.179678+00:00", - "updated_on":"2015-04-06T15:23:38.205705+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" - }, - "html":{ - "href":"https://api.bitbucket.org/pullrequest_id" - } - } - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } -} -` - - 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", "pullrequest:created") - - 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 TestPullRequestUpdated(t *testing.T) { - - payload := `{ - "actor":{ - "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" - } - } - }, - "pullrequest":{ - "id":1, - "title":"Title of pull request", - "description":"Description of pull request", - "state":"OPEN|MERGED|DECLINED", - "author":{ - "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" - } - } - }, - "source":{ - "branch":{ - "name":"branch2" - }, - "commit":{ - "hash":"d3022fc0ca3d" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "destination":{ - "branch":{ - "name":"master" - }, - "commit":{ - "hash":"ce5965ddd289" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "merge_commit":{ - "hash":"764413d85e29" - }, - "participants":[ - { - "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" - } - } - } - ], - "reviewers":[ - { - "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" - } - } - } - ], - "close_source_branch":true, - "closed_by":{ - "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" - } - } - }, - "reason":"reason for declining the PR (if applicable)", - "created_on":"2015-04-06T15:23:38.179678+00:00", - "updated_on":"2015-04-06T15:23:38.205705+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" - }, - "html":{ - "href":"https://api.bitbucket.org/pullrequest_id" - } - } - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } -} -` - - 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", "pullrequest: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 TestPullRequestApproved(t *testing.T) { - - payload := `{ - "actor":{ - "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" - } - } - }, - "pullrequest":{ - "id":1, - "title":"Title of pull request", - "description":"Description of pull request", - "state":"OPEN|MERGED|DECLINED", - "author":{ - "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" - } - } - }, - "source":{ - "branch":{ - "name":"branch2" - }, - "commit":{ - "hash":"d3022fc0ca3d" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "destination":{ - "branch":{ - "name":"master" - }, - "commit":{ - "hash":"ce5965ddd289" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "merge_commit":{ - "hash":"764413d85e29" - }, - "participants":[ - { - "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" - } - } - } - ], - "reviewers":[ - { - "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" - } - } - } - ], - "close_source_branch":true, - "closed_by":{ - "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" - } - } - }, - "reason":"reason for declining the PR (if applicable)", - "created_on":"2015-04-06T15:23:38.179678+00:00", - "updated_on":"2015-04-06T15:23:38.205705+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" - }, - "html":{ - "href":"https://api.bitbucket.org/pullrequest_id" - } - } - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - }, - "approval":{ - "date":"2015-04-06T16:34:59.195330+00:00", - "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" - } - } - } - } -} -` - - 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", "pullrequest:approved") - - 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 TestPullRequestApprovalRemoved(t *testing.T) { - - payload := `{ - "actor":{ - "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" - } - } - }, - "pullrequest":{ - "id":1, - "title":"Title of pull request", - "description":"Description of pull request", - "state":"OPEN|MERGED|DECLINED", - "author":{ - "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" - } - } - }, - "source":{ - "branch":{ - "name":"branch2" - }, - "commit":{ - "hash":"d3022fc0ca3d" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "destination":{ - "branch":{ - "name":"master" - }, - "commit":{ - "hash":"ce5965ddd289" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "merge_commit":{ - "hash":"764413d85e29" - }, - "participants":[ - { - "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" - } - } - } - ], - "reviewers":[ - { - "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" - } - } - } - ], - "close_source_branch":true, - "closed_by":{ - "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" - } - } - }, - "reason":"reason for declining the PR (if applicable)", - "created_on":"2015-04-06T15:23:38.179678+00:00", - "updated_on":"2015-04-06T15:23:38.205705+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" - }, - "html":{ - "href":"https://api.bitbucket.org/pullrequest_id" - } - } - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - }, - "approval":{ - "date":"2015-04-06T16:34:59.195330+00:00", - "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" - } - } - } - } -} -` - - 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", "pullrequest:unapproved") - - 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 TestPullRequestMerged(t *testing.T) { - - payload := `{ - "actor":{ - "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" - } - } - }, - "pullrequest":{ - "id":1, - "title":"Title of pull request", - "description":"Description of pull request", - "state":"OPEN|MERGED|DECLINED", - "author":{ - "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" - } - } - }, - "source":{ - "branch":{ - "name":"branch2" - }, - "commit":{ - "hash":"d3022fc0ca3d" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "destination":{ - "branch":{ - "name":"master" - }, - "commit":{ - "hash":"ce5965ddd289" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "merge_commit":{ - "hash":"764413d85e29" - }, - "participants":[ - { - "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" - } - } - } - ], - "reviewers":[ - { - "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" - } - } - } - ], - "close_source_branch":true, - "closed_by":{ - "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" - } - } - }, - "reason":"reason for declining the PR (if applicable)", - "created_on":"2015-04-06T15:23:38.179678+00:00", - "updated_on":"2015-04-06T15:23:38.205705+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" - }, - "html":{ - "href":"https://api.bitbucket.org/pullrequest_id" - } - } - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } -} -` - - 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", "pullrequest:fulfilled") - - 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 TestPullRequestDeclined(t *testing.T) { - - payload := `{ - "actor":{ - "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" - } - } - }, - "pullrequest":{ - "id":1, - "title":"Title of pull request", - "description":"Description of pull request", - "state":"OPEN|MERGED|DECLINED", - "author":{ - "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" - } - } - }, - "source":{ - "branch":{ - "name":"branch2" - }, - "commit":{ - "hash":"d3022fc0ca3d" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "destination":{ - "branch":{ - "name":"master" - }, - "commit":{ - "hash":"ce5965ddd289" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "merge_commit":{ - "hash":"764413d85e29" - }, - "participants":[ - { - "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" - } - } - } - ], - "reviewers":[ - { - "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" - } - } - } - ], - "close_source_branch":true, - "closed_by":{ - "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" - } - } - }, - "reason":"reason for declining the PR (if applicable)", - "created_on":"2015-04-06T15:23:38.179678+00:00", - "updated_on":"2015-04-06T15:23:38.205705+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" - }, - "html":{ - "href":"https://api.bitbucket.org/pullrequest_id" - } - } - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } -} -` - - 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", "pullrequest:rejected") - - 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 TestPullRequestCommentCreated(t *testing.T) { - - payload := `{ - "actor":{ - "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":{ - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - }, - "pullrequest":{ - "id":1, - "title":"Title of pull request", - "description":"Description of pull request", - "state":"OPEN|MERGED|DECLINED", - "author":{ - "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" - } - } - }, - "source":{ - "branch":{ - "name":"branch2" - }, - "commit":{ - "hash":"d3022fc0ca3d" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "destination":{ - "branch":{ - "name":"master" - }, - "commit":{ - "hash":"ce5965ddd289" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "merge_commit":{ - "hash":"764413d85e29" - }, - "participants":[ - { - "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" - } - } - } - ], - "reviewers":[ - { - "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" - } - } - } - ], - "close_source_branch":true, - "closed_by":{ - "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" - } - } - }, - "reason":"reason for declining the PR (if applicable)", - "created_on":"2015-04-06T15:23:38.179678+00:00", - "updated_on":"2015-04-06T15:23:38.205705+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" - }, - "html":{ - "href":"https://api.bitbucket.org/pullrequest_id" - } - } - }, - "comment":{ - "id":17, - "parent":{ - "id":16 - }, - "content":{ - "raw":"Comment text", - "html":"

Comment text

", - "markup":"markdown" - }, - "inline":{ - "path":"path/to/file", - "from":null, - "to":10 - }, - "created_on":"2015-04-06T16:52:29.982346+00:00", - "updated_on":"2015-04-06T16:52:29.983730+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/comments/comment_id" - }, - "html":{ - "href":"https://api.bitbucket.org/comment_id" - } - } - } -} -` - - 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", "pullrequest:comment_created") - - 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 TestPullRequestCommentUpdated(t *testing.T) { - - payload := `{ - "actor":{ - "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":{ - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - }, - "pullrequest":{ - "id":1, - "title":"Title of pull request", - "description":"Description of pull request", - "state":"OPEN|MERGED|DECLINED", - "author":{ - "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" - } - } - }, - "source":{ - "branch":{ - "name":"branch2" - }, - "commit":{ - "hash":"d3022fc0ca3d" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "destination":{ - "branch":{ - "name":"master" - }, - "commit":{ - "hash":"ce5965ddd289" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "merge_commit":{ - "hash":"764413d85e29" - }, - "participants":[ - { - "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" - } - } - } - ], - "reviewers":[ - { - "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" - } - } - } - ], - "close_source_branch":true, - "closed_by":{ - "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" - } - } - }, - "reason":"reason for declining the PR (if applicable)", - "created_on":"2015-04-06T15:23:38.179678+00:00", - "updated_on":"2015-04-06T15:23:38.205705+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" - }, - "html":{ - "href":"https://api.bitbucket.org/pullrequest_id" - } - } - }, - "comment":{ - "id":17, - "parent":{ - "id":16 - }, - "content":{ - "raw":"Comment text", - "html":"

Comment text

", - "markup":"markdown" - }, - "inline":{ - "path":"path/to/file", - "from":null, - "to":10 - }, - "created_on":"2015-04-06T16:52:29.982346+00:00", - "updated_on":"2015-04-06T16:52:29.983730+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/comments/comment_id" - }, - "html":{ - "href":"https://api.bitbucket.org/comment_id" - } - } - } -} -` - - 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", "pullrequest:comment_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 TestPullRequestCommentDeleted(t *testing.T) { - - payload := `{ - "actor":{ - "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":{ - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - }, - "pullrequest":{ - "id":1, - "title":"Title of pull request", - "description":"Description of pull request", - "state":"OPEN|MERGED|DECLINED", - "author":{ - "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" - } - } - }, - "source":{ - "branch":{ - "name":"branch2" - }, - "commit":{ - "hash":"d3022fc0ca3d" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "destination":{ - "branch":{ - "name":"master" - }, - "commit":{ - "hash":"ce5965ddd289" - }, - "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}", - "full_name":"team_name/repo_name", - "name":"repo_name", - "scm":"git", - "is_private":true - } - }, - "merge_commit":{ - "hash":"764413d85e29" - }, - "participants":[ - { - "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" - } - } - } - ], - "reviewers":[ - { - "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" - } - } - } - ], - "close_source_branch":true, - "closed_by":{ - "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" - } - } - }, - "reason":"reason for declining the PR (if applicable)", - "created_on":"2015-04-06T15:23:38.179678+00:00", - "updated_on":"2015-04-06T15:23:38.205705+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" - }, - "html":{ - "href":"https://api.bitbucket.org/pullrequest_id" - } - } - }, - "comment":{ - "id":17, - "parent":{ - "id":16 - }, - "content":{ - "raw":"Comment text", - "html":"

Comment text

", - "markup":"markdown" - }, - "inline":{ - "path":"path/to/file", - "from":null, - "to":10 - }, - "created_on":"2015-04-06T16:52:29.982346+00:00", - "updated_on":"2015-04-06T16:52:29.983730+00:00", - "links":{ - "self":{ - "href":"https://api.bitbucket.org/api/2.0/comments/comment_id" - }, - "html":{ - "href":"https://api.bitbucket.org/comment_id" - } - } - } -} -` - - 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", "pull_request:comment_deleted") - - 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 TestRepoFork(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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":{ +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// }, +// "fork":{ +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// } +// ` + +// 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:fork") + +// 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 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) { + +// payload := `{ +// "actor":{ +// "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" +// } +// } +// }, +// "comment":{ +// "id":17, +// "parent":{ +// "id":16 +// }, +// "content":{ +// "raw":"Comment text", +// "html":"

Comment text

", +// "markup":"markdown" +// }, +// "inline":{ +// "path":"path/to/file", +// "from":null, +// "to":10 +// }, +// "created_on":"2015-04-06T16:52:29.982346+00:00", +// "updated_on":"2015-04-06T16:52:29.983730+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/comments/comment_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/comment_id" +// } +// } +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// }, +// "commit":{ +// "hash":"d3022fc0ca3d65c7f6654eea129d6bf0cf0ee08e" +// } +// } +// ` + +// 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:commit_comment_created") + +// 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 TestRepoCommitStatusCreated(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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":{ +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// }, +// "commit_status":{ +// "name":"Unit Tests (Python)", +// "description":"Build started", +// "state":"INPROGRESS", +// "key":"mybuildtool", +// "url":"https://my-build-tool.com/builds/MY-PROJECT/BUILD-777", +// "type":"build", +// "created_on":"2015-11-19T20:37:35.547563+00:00", +// "updated_on":"2015-11-19T20:37:35.547563+00:00", +// "links":{ +// "commit":{ +// "href":"http://api.bitbucket.org/2.0/repositories/tk/test/commit/9fec847784abb10b2fa567ee63b85bd238955d0e" +// }, +// "self":{ +// "href":"http://api.bitbucket.org/2.0/repositories/tk/test/commit/9fec847784abb10b2fa567ee63b85bd238955d0e/statuses/build/mybuildtool" +// } +// } +// } +// } +// ` + +// 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:commit_status_created") + +// 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 TestRepoCommitStatusUpdated(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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":{ +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// }, +// "commit_status":{ +// "name":"Unit Tests (Python)", +// "description":"All tests passed", +// "state":"SUCCESSFUL", +// "key":"mybuildtool", +// "url":"https://my-build-tool.com/builds/MY-PROJECT/BUILD-792", +// "type":"build", +// "created_on":"2015-11-19T20:37:35.547563+00:00", +// "updated_on":"2015-11-20T08:01:16.433108+00:00", +// "links":{ +// "commit":{ +// "href":"http://api.bitbucket.org/2.0/repositories/tk/test/commit/9fec847784abb10b2fa567ee63b85bd238955d0e" +// }, +// "self":{ +// "href":"http://api.bitbucket.org/2.0/repositories/tk/test/commit/9fec847784abb10b2fa567ee63b85bd238955d0e/statuses/build/mybuildtool" +// } +// } +// } +// } +// ` + +// 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:commit_status_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 TestIssueCreated(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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" +// } +// } +// }, +// "issue":{ +// "id":1, +// "component":"component", +// "title":"Issue title", +// "content":{ +// "raw":"Issue description", +// "html":"

Issue description

", +// "markup":"markdown" +// }, +// "priority":"trivial|minor|major|critical|blocker", +// "state":"new|open|on hold|resolved|duplicate|invalid|wontfix|closed", +// "type":"bug|enhancement|proposal|task", +// "milestone":{ +// "name":"milestone 1" +// }, +// "version":{ +// "name":"version 1" +// }, +// "created_on":"2015-04-06T15:23:38.179678+00:00", +// "updated_on":"2015-04-06T15:23:38.179678+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/issues/issue_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/issue_id" +// } +// } +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// } +// ` + +// 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", "issue:created") + +// 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 TestIssueUpdated(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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" +// } +// } +// }, +// "issue":{ +// "id":1, +// "component":"component", +// "title":"Issue title", +// "content":{ +// "raw":"Issue description", +// "html":"

Issue description

", +// "markup":"markdown" +// }, +// "priority":"trivial|minor|major|critical|blocker", +// "state":"new|open|on hold|resolved|duplicate|invalid|wontfix|closed", +// "type":"bug|enhancement|proposal|task", +// "milestone":{ +// "name":"milestone 1" +// }, +// "version":{ +// "name":"version 1" +// }, +// "created_on":"2015-04-06T15:23:38.179678+00:00", +// "updated_on":"2015-04-06T15:23:38.179678+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/issues/issue_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/issue_id" +// } +// } +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// }, +// "comment":{ +// "id":17, +// "parent":{ +// "id":16 +// }, +// "content":{ +// "raw":"Comment text", +// "html":"

Comment text

", +// "markup":"markdown" +// }, +// "inline":{ +// "path":"path/to/file", +// "from":null, +// "to":10 +// }, +// "created_on":"2015-04-06T16:52:29.982346+00:00", +// "updated_on":"2015-04-06T16:52:29.983730+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/comments/comment_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/comment_id" +// } +// } +// }, +// "changes":{ +// "status":{ +// "old":"open", +// "new":"on hold" +// } +// } +// } +// ` + +// 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", "issue: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 TestIssueCommentCreated(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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":{ +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// }, +// "issue":{ +// "id":1, +// "component":"component", +// "title":"Issue title", +// "content":{ +// "raw":"Issue description", +// "html":"

Issue description

", +// "markup":"markdown" +// }, +// "priority":"trivial|minor|major|critical|blocker", +// "state":"new|open|on hold|resolved|duplicate|invalid|wontfix|closed", +// "type":"bug|enhancement|proposal|task", +// "milestone":{ +// "name":"milestone 1" +// }, +// "version":{ +// "name":"version 1" +// }, +// "created_on":"2015-04-06T15:23:38.179678+00:00", +// "updated_on":"2015-04-06T15:23:38.179678+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/issues/issue_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/issue_id" +// } +// } +// }, +// "comment":{ +// "id":17, +// "parent":{ +// "id":16 +// }, +// "content":{ +// "raw":"Comment text", +// "html":"

Comment text

", +// "markup":"markdown" +// }, +// "inline":{ +// "path":"path/to/file", +// "from":null, +// "to":10 +// }, +// "created_on":"2015-04-06T16:52:29.982346+00:00", +// "updated_on":"2015-04-06T16:52:29.983730+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/comments/comment_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/comment_id" +// } +// } +// } +// } +// ` + +// 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", "issue:comment_created") + +// 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 TestPullRequestCreated(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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" +// } +// } +// }, +// "pullrequest":{ +// "id":1, +// "title":"Title of pull request", +// "description":"Description of pull request", +// "state":"OPEN|MERGED|DECLINED", +// "author":{ +// "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" +// } +// } +// }, +// "source":{ +// "branch":{ +// "name":"branch2" +// }, +// "commit":{ +// "hash":"d3022fc0ca3d" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "destination":{ +// "branch":{ +// "name":"master" +// }, +// "commit":{ +// "hash":"ce5965ddd289" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "merge_commit":{ +// "hash":"764413d85e29" +// }, +// "participants":[ +// { +// "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" +// } +// } +// } +// ], +// "reviewers":[ +// { +// "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" +// } +// } +// } +// ], +// "close_source_branch":true, +// "closed_by":{ +// "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" +// } +// } +// }, +// "reason":"reason for declining the PR (if applicable)", +// "created_on":"2015-04-06T15:23:38.179678+00:00", +// "updated_on":"2015-04-06T15:23:38.205705+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/pullrequest_id" +// } +// } +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// } +// ` + +// 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", "pullrequest:created") + +// 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 TestPullRequestUpdated(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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" +// } +// } +// }, +// "pullrequest":{ +// "id":1, +// "title":"Title of pull request", +// "description":"Description of pull request", +// "state":"OPEN|MERGED|DECLINED", +// "author":{ +// "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" +// } +// } +// }, +// "source":{ +// "branch":{ +// "name":"branch2" +// }, +// "commit":{ +// "hash":"d3022fc0ca3d" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "destination":{ +// "branch":{ +// "name":"master" +// }, +// "commit":{ +// "hash":"ce5965ddd289" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "merge_commit":{ +// "hash":"764413d85e29" +// }, +// "participants":[ +// { +// "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" +// } +// } +// } +// ], +// "reviewers":[ +// { +// "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" +// } +// } +// } +// ], +// "close_source_branch":true, +// "closed_by":{ +// "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" +// } +// } +// }, +// "reason":"reason for declining the PR (if applicable)", +// "created_on":"2015-04-06T15:23:38.179678+00:00", +// "updated_on":"2015-04-06T15:23:38.205705+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/pullrequest_id" +// } +// } +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// } +// ` + +// 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", "pullrequest: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 TestPullRequestApproved(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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" +// } +// } +// }, +// "pullrequest":{ +// "id":1, +// "title":"Title of pull request", +// "description":"Description of pull request", +// "state":"OPEN|MERGED|DECLINED", +// "author":{ +// "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" +// } +// } +// }, +// "source":{ +// "branch":{ +// "name":"branch2" +// }, +// "commit":{ +// "hash":"d3022fc0ca3d" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "destination":{ +// "branch":{ +// "name":"master" +// }, +// "commit":{ +// "hash":"ce5965ddd289" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "merge_commit":{ +// "hash":"764413d85e29" +// }, +// "participants":[ +// { +// "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" +// } +// } +// } +// ], +// "reviewers":[ +// { +// "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" +// } +// } +// } +// ], +// "close_source_branch":true, +// "closed_by":{ +// "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" +// } +// } +// }, +// "reason":"reason for declining the PR (if applicable)", +// "created_on":"2015-04-06T15:23:38.179678+00:00", +// "updated_on":"2015-04-06T15:23:38.205705+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/pullrequest_id" +// } +// } +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// }, +// "approval":{ +// "date":"2015-04-06T16:34:59.195330+00:00", +// "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" +// } +// } +// } +// } +// } +// ` + +// 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", "pullrequest:approved") + +// 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 TestPullRequestApprovalRemoved(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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" +// } +// } +// }, +// "pullrequest":{ +// "id":1, +// "title":"Title of pull request", +// "description":"Description of pull request", +// "state":"OPEN|MERGED|DECLINED", +// "author":{ +// "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" +// } +// } +// }, +// "source":{ +// "branch":{ +// "name":"branch2" +// }, +// "commit":{ +// "hash":"d3022fc0ca3d" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "destination":{ +// "branch":{ +// "name":"master" +// }, +// "commit":{ +// "hash":"ce5965ddd289" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "merge_commit":{ +// "hash":"764413d85e29" +// }, +// "participants":[ +// { +// "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" +// } +// } +// } +// ], +// "reviewers":[ +// { +// "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" +// } +// } +// } +// ], +// "close_source_branch":true, +// "closed_by":{ +// "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" +// } +// } +// }, +// "reason":"reason for declining the PR (if applicable)", +// "created_on":"2015-04-06T15:23:38.179678+00:00", +// "updated_on":"2015-04-06T15:23:38.205705+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/pullrequest_id" +// } +// } +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// }, +// "approval":{ +// "date":"2015-04-06T16:34:59.195330+00:00", +// "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" +// } +// } +// } +// } +// } +// ` + +// 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", "pullrequest:unapproved") + +// 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 TestPullRequestMerged(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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" +// } +// } +// }, +// "pullrequest":{ +// "id":1, +// "title":"Title of pull request", +// "description":"Description of pull request", +// "state":"OPEN|MERGED|DECLINED", +// "author":{ +// "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" +// } +// } +// }, +// "source":{ +// "branch":{ +// "name":"branch2" +// }, +// "commit":{ +// "hash":"d3022fc0ca3d" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "destination":{ +// "branch":{ +// "name":"master" +// }, +// "commit":{ +// "hash":"ce5965ddd289" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "merge_commit":{ +// "hash":"764413d85e29" +// }, +// "participants":[ +// { +// "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" +// } +// } +// } +// ], +// "reviewers":[ +// { +// "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" +// } +// } +// } +// ], +// "close_source_branch":true, +// "closed_by":{ +// "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" +// } +// } +// }, +// "reason":"reason for declining the PR (if applicable)", +// "created_on":"2015-04-06T15:23:38.179678+00:00", +// "updated_on":"2015-04-06T15:23:38.205705+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/pullrequest_id" +// } +// } +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// } +// ` + +// 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", "pullrequest:fulfilled") + +// 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 TestPullRequestDeclined(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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" +// } +// } +// }, +// "pullrequest":{ +// "id":1, +// "title":"Title of pull request", +// "description":"Description of pull request", +// "state":"OPEN|MERGED|DECLINED", +// "author":{ +// "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" +// } +// } +// }, +// "source":{ +// "branch":{ +// "name":"branch2" +// }, +// "commit":{ +// "hash":"d3022fc0ca3d" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "destination":{ +// "branch":{ +// "name":"master" +// }, +// "commit":{ +// "hash":"ce5965ddd289" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "merge_commit":{ +// "hash":"764413d85e29" +// }, +// "participants":[ +// { +// "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" +// } +// } +// } +// ], +// "reviewers":[ +// { +// "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" +// } +// } +// } +// ], +// "close_source_branch":true, +// "closed_by":{ +// "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" +// } +// } +// }, +// "reason":"reason for declining the PR (if applicable)", +// "created_on":"2015-04-06T15:23:38.179678+00:00", +// "updated_on":"2015-04-06T15:23:38.205705+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/pullrequest_id" +// } +// } +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// } +// ` + +// 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", "pullrequest:rejected") + +// 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 TestPullRequestCommentCreated(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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":{ +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// }, +// "pullrequest":{ +// "id":1, +// "title":"Title of pull request", +// "description":"Description of pull request", +// "state":"OPEN|MERGED|DECLINED", +// "author":{ +// "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" +// } +// } +// }, +// "source":{ +// "branch":{ +// "name":"branch2" +// }, +// "commit":{ +// "hash":"d3022fc0ca3d" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "destination":{ +// "branch":{ +// "name":"master" +// }, +// "commit":{ +// "hash":"ce5965ddd289" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "merge_commit":{ +// "hash":"764413d85e29" +// }, +// "participants":[ +// { +// "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" +// } +// } +// } +// ], +// "reviewers":[ +// { +// "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" +// } +// } +// } +// ], +// "close_source_branch":true, +// "closed_by":{ +// "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" +// } +// } +// }, +// "reason":"reason for declining the PR (if applicable)", +// "created_on":"2015-04-06T15:23:38.179678+00:00", +// "updated_on":"2015-04-06T15:23:38.205705+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/pullrequest_id" +// } +// } +// }, +// "comment":{ +// "id":17, +// "parent":{ +// "id":16 +// }, +// "content":{ +// "raw":"Comment text", +// "html":"

Comment text

", +// "markup":"markdown" +// }, +// "inline":{ +// "path":"path/to/file", +// "from":null, +// "to":10 +// }, +// "created_on":"2015-04-06T16:52:29.982346+00:00", +// "updated_on":"2015-04-06T16:52:29.983730+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/comments/comment_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/comment_id" +// } +// } +// } +// } +// ` + +// 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", "pullrequest:comment_created") + +// 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 TestPullRequestCommentUpdated(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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":{ +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// }, +// "pullrequest":{ +// "id":1, +// "title":"Title of pull request", +// "description":"Description of pull request", +// "state":"OPEN|MERGED|DECLINED", +// "author":{ +// "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" +// } +// } +// }, +// "source":{ +// "branch":{ +// "name":"branch2" +// }, +// "commit":{ +// "hash":"d3022fc0ca3d" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "destination":{ +// "branch":{ +// "name":"master" +// }, +// "commit":{ +// "hash":"ce5965ddd289" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "merge_commit":{ +// "hash":"764413d85e29" +// }, +// "participants":[ +// { +// "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" +// } +// } +// } +// ], +// "reviewers":[ +// { +// "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" +// } +// } +// } +// ], +// "close_source_branch":true, +// "closed_by":{ +// "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" +// } +// } +// }, +// "reason":"reason for declining the PR (if applicable)", +// "created_on":"2015-04-06T15:23:38.179678+00:00", +// "updated_on":"2015-04-06T15:23:38.205705+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/pullrequest_id" +// } +// } +// }, +// "comment":{ +// "id":17, +// "parent":{ +// "id":16 +// }, +// "content":{ +// "raw":"Comment text", +// "html":"

Comment text

", +// "markup":"markdown" +// }, +// "inline":{ +// "path":"path/to/file", +// "from":null, +// "to":10 +// }, +// "created_on":"2015-04-06T16:52:29.982346+00:00", +// "updated_on":"2015-04-06T16:52:29.983730+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/comments/comment_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/comment_id" +// } +// } +// } +// } +// ` + +// 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", "pullrequest:comment_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 TestPullRequestCommentDeleted(t *testing.T) { + +// payload := `{ +// "actor":{ +// "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":{ +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// }, +// "pullrequest":{ +// "id":1, +// "title":"Title of pull request", +// "description":"Description of pull request", +// "state":"OPEN|MERGED|DECLINED", +// "author":{ +// "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" +// } +// } +// }, +// "source":{ +// "branch":{ +// "name":"branch2" +// }, +// "commit":{ +// "hash":"d3022fc0ca3d" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "destination":{ +// "branch":{ +// "name":"master" +// }, +// "commit":{ +// "hash":"ce5965ddd289" +// }, +// "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}", +// "full_name":"team_name/repo_name", +// "name":"repo_name", +// "scm":"git", +// "is_private":true +// } +// }, +// "merge_commit":{ +// "hash":"764413d85e29" +// }, +// "participants":[ +// { +// "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" +// } +// } +// } +// ], +// "reviewers":[ +// { +// "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" +// } +// } +// } +// ], +// "close_source_branch":true, +// "closed_by":{ +// "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" +// } +// } +// }, +// "reason":"reason for declining the PR (if applicable)", +// "created_on":"2015-04-06T15:23:38.179678+00:00", +// "updated_on":"2015-04-06T15:23:38.205705+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/pullrequests/pullrequest_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/pullrequest_id" +// } +// } +// }, +// "comment":{ +// "id":17, +// "parent":{ +// "id":16 +// }, +// "content":{ +// "raw":"Comment text", +// "html":"

Comment text

", +// "markup":"markdown" +// }, +// "inline":{ +// "path":"path/to/file", +// "from":null, +// "to":10 +// }, +// "created_on":"2015-04-06T16:52:29.982346+00:00", +// "updated_on":"2015-04-06T16:52:29.983730+00:00", +// "links":{ +// "self":{ +// "href":"https://api.bitbucket.org/api/2.0/comments/comment_id" +// }, +// "html":{ +// "href":"https://api.bitbucket.org/comment_id" +// } +// } +// } +// } +// ` + +// 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", "pull_request:comment_deleted") + +// 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) +// } diff --git a/github/github.go b/github/github.go index e9733d9..dc735bf 100644 --- a/github/github.go +++ b/github/github.go @@ -12,14 +12,14 @@ import ( "net/http" ) -// parse errros +// parse errors var ( - ErrEventNotSpecifiedToParse = errors.New("No Event specified to parse") - ErrInvalidHTTPMethod = errors.New("Invalid HTTP Method") - ErrMissingGithubEventHeader = errors.New("Missing X-GitHub-Event Header") - ErrMissingHubSignatureHeader = errors.New("Missing X-Hub-Signature Header") - ErrEventNotFound = errors.New("Event not defined to be parsed") - ErrParsingPayload = errors.New("Error parsing payload") + ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse") + ErrInvalidHTTPMethod = errors.New("invalid HTTP Method") + ErrMissingGithubEventHeader = errors.New("missing X-GitHub-Event Header") + ErrMissingHubSignatureHeader = errors.New("missing X-Hub-Signature Header") + ErrEventNotFound = errors.New("event not defined to be parsed") + ErrParsingPayload = errors.New("error parsing payload") ErrHMACVerificationFailed = errors.New("HMAC verification failed") ) diff --git a/github/github_test.go b/github/github_test.go index 096fa62..a3d70ab 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -1574,7 +1574,7 @@ func TestIssueCommentEvent(t *testing.T) { "created_at": "2015-05-05T23:40:28Z", "updated_at": "2015-05-05T23:40:28Z", "closed_at": null, - "body": "It looks like you accidently spelled 'commit' with two 't's." + "body": "It looks like you accidentally spelled 'commit' with two 't's." }, "comment": { "url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/comments/99262140", diff --git a/gitlab/gitlab.go b/gitlab/gitlab.go index 7fa4729..0c00252 100644 --- a/gitlab/gitlab.go +++ b/gitlab/gitlab.go @@ -9,6 +9,17 @@ import ( "net/http" ) +// parse errors +var ( + ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse") + ErrInvalidHTTPMethod = errors.New("invalid HTTP Method") + ErrMissingGitLabEventHeader = errors.New("missing X-Gitlab-Event Header") + ErrMissingGitLabTokenHeader = errors.New("missing X-Gitlab-Token Header") + ErrEventNotFound = errors.New("event not defined to be parsed") + ErrParsingPayload = errors.New("error parsing payload") + // ErrHMACVerificationFailed = errors.New("HMAC verification failed") +) + // GitLab hook types const ( PushEvents Event = "Push Hook" @@ -58,17 +69,6 @@ func New(options ...Option) (*Webhook, error) { return hook, nil } -// parse errros -var ( - ErrEventNotSpecifiedToParse = errors.New("No Event specified to parse") - ErrInvalidHTTPMethod = errors.New("Invalid HTTP Method") - ErrMissingGitLabEventHeader = errors.New("Missing X-Gitlab-Event Header") - ErrMissingGitLabTokenHeader = errors.New("Missing X-Gitlab-Token Header") - ErrEventNotFound = errors.New("Event not defined to be parsed") - ErrParsingPayload = errors.New("Error parsing payload") - // ErrHMACVerificationFailed = errors.New("HMAC verification failed") -) - // Parse verifies and parses the events specified and returns the payload object or an error func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) { defer func() { diff --git a/gitlab/gitlab_test.go b/gitlab/gitlab_test.go index 36d09db..fd513b4 100644 --- a/gitlab/gitlab_test.go +++ b/gitlab/gitlab_test.go @@ -2,11 +2,11 @@ package gitlab import ( "bytes" + "log" "net/http" + "net/http/httptest" "os" - "strconv" "testing" - "time" . "gopkg.in/go-playground/assert.v1" "gopkg.in/go-playground/webhooks.v5" @@ -24,7 +24,6 @@ import ( // const ( - port = 3011 path = "/webhooks" ) @@ -38,28 +37,20 @@ var hook *Webhook func TestMain(m *testing.M) { // setup - hook = New(&Config{Secret: "sampleToken!"}) - hook.RegisterEvents(HandlePayload, - PushEvents, - TagEvents, - IssuesEvents, - ConfidentialIssuesEvents, - CommentEvents, - MergeRequestEvents, - WikiPageEvents, - PipelineEvents, - BuildEvents, - ) - go webhooks.Run(hook, "127.0.0.1:"+strconv.Itoa(port), path) - time.Sleep(time.Millisecond * 500) - + var err error + hook, err = New(Options.Secret("sampleToken!!")) + if err != nil { + log.Fatal(err) + } os.Exit(m.Run()) // teardown } -func TestProvider(t *testing.T) { - Equal(t, hook.Provider(), webhooks.GitLab) +func newServer(handler http.HandlerFunc) *httptest.Server { + mux := http.NewServeMux() + mux.HandleFunc(path, handler) + return httptest.NewServer(mux) } func TestBadNoEventHeader(t *testing.T) { diff --git a/gogs/gogs.go b/gogs/gogs.go index 1a2d9b4..0f242d4 100644 --- a/gogs/gogs.go +++ b/gogs/gogs.go @@ -15,6 +15,17 @@ import ( client "github.com/gogits/go-gogs-client" ) +// parse errors +var ( + ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse") + ErrInvalidHTTPMethod = errors.New("invalid HTTP Method") + ErrMissingGogsEventHeader = errors.New("missing X-Gogs-Event Header") + ErrMissingGogsSignatureHeader = errors.New("missing X-Gogs-Signature Header") + ErrEventNotFound = errors.New("event not defined to be parsed") + ErrParsingPayload = errors.New("error parsing payload") + ErrHMACVerificationFailed = errors.New("HMAC verification failed") +) + // Option is a configuration option for the webhook type Option func(*Webhook) error @@ -63,17 +74,6 @@ func New(options ...Option) (*Webhook, error) { return hook, nil } -// parse errros -var ( - ErrEventNotSpecifiedToParse = errors.New("No Event specified to parse") - ErrInvalidHTTPMethod = errors.New("Invalid HTTP Method") - ErrMissingGogsEventHeader = errors.New("Missing X-Gogs-Event Header") - ErrMissingGogsSignatureHeader = errors.New("Missing X-Gogs-Signature Header") - ErrEventNotFound = errors.New("Event not defined to be parsed") - ErrParsingPayload = errors.New("Error parsing payload") - ErrHMACVerificationFailed = errors.New("HMAC verification failed") -) - // Parse verifies and parses the events specified and returns the payload object or an error func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) { defer func() { diff --git a/logger.go b/logger.go deleted file mode 100644 index 56eba3a..0000000 --- a/logger.go +++ /dev/null @@ -1,44 +0,0 @@ -package webhooks - -import "log" - -// DefaultLog contains the default logger for webhooks, and prints only info and error messages by default -// for debugs override DefaultLog or see NewLogger for creating one without debugs. -var DefaultLog Logger = new(logger) - -// Logger allows for customizable logging -type Logger interface { - // Info prints basic information. - Info(...interface{}) - // Error prints error information. - Error(...interface{}) - // Debug prints information usefull for debugging. - Debug(...interface{}) -} - -// NewLogger returns a new logger for use. -func NewLogger(debug bool) Logger { - return &logger{PrintDebugs: debug} -} - -type logger struct { - PrintDebugs bool -} - -// Info prints basic information. -func (l *logger) Info(msg ...interface{}) { - log.Println("INFO:", msg) -} - -// v prints error information. -func (l *logger) Error(msg ...interface{}) { - log.Println("ERROR:", msg) -} - -// Debug prints information usefull for debugging. -func (l *logger) Debug(msg ...interface{}) { - if !l.PrintDebugs { - return - } - log.Println("DEBUG:", msg) -}