diff --git a/bitbucket/bitbucket_test.go b/bitbucket/bitbucket_test.go index e8a81a6..e81eadd 100644 --- a/bitbucket/bitbucket_test.go +++ b/bitbucket/bitbucket_test.go @@ -403,2647 +403,2783 @@ func TestRepoPush(t *testing.T) { 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 + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, RepoForkEvent) + }) + 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:fork") + + 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, nil) + _, ok := results.(RepoForkPayload) + Equal(t, ok, true) +} + +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" + } + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, RepoUpdatedEvent) + }) + 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:updated") + + 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, nil) + _, ok := results.(RepoUpdatedPayload) + Equal(t, ok, true) +} + +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" + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, RepoCommitCommentCreatedEvent) + }) + 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:commit_comment_created") + + 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, nil) + _, ok := results.(RepoCommitCommentCreatedPayload) + Equal(t, ok, true) +} + +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" + } + } + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, RepoCommitStatusCreatedEvent) + }) + 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:commit_status_created") + + 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, nil) + _, ok := results.(RepoCommitStatusCreatedPayload) + Equal(t, ok, true) +} + +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" + } + } + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, RepoCommitStatusUpdatedEvent) + }) + 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:commit_status_updated") + + 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, nil) + _, ok := results.(RepoCommitStatusUpdatedPayload) + Equal(t, ok, true) +} + +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 + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, IssueCreatedEvent) + }) + 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", "issue:created") + + 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, nil) + _, ok := results.(IssueCreatedPayload) + Equal(t, ok, true) +} + +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" + } + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, IssueUpdatedEvent) + }) + 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", "issue:updated") + + 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, nil) + _, ok := results.(IssueUpdatedPayload) + Equal(t, ok, true) +} + +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" + } + } + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, IssueCommentCreatedEvent) + }) + 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", "issue:comment_created") + + 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, nil) + _, ok := results.(IssueCommentCreatedPayload) + Equal(t, ok, true) +} + +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 + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, PullRequestCreatedEvent) + }) + 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", "pullrequest:created") + + 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, nil) + _, ok := results.(PullRequestCreatedPayload) + Equal(t, ok, true) +} + +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 + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, PullRequestUpdatedEvent) + }) + 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", "pullrequest:updated") + + 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, nil) + _, ok := results.(PullRequestUpdatedPayload) + Equal(t, ok, true) +} + +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" + } + } + } + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, PullRequestApprovedEvent) + }) + 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", "pullrequest:approved") + + 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, nil) + _, ok := results.(PullRequestApprovedPayload) + Equal(t, ok, true) +} + +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" + } + } + } + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, PullRequestUnapprovedEvent) + }) + 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", "pullrequest:unapproved") + + 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, nil) + _, ok := results.(PullRequestUnapprovedPayload) + Equal(t, ok, true) +} + +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 + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, PullRequestMergedEvent) + }) + 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", "pullrequest:fulfilled") + + 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, nil) + _, ok := results.(PullRequestMergedPayload) + Equal(t, ok, true) +} + +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 + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, PullRequestDeclinedEvent) + }) + 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", "pullrequest:rejected") + + 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, nil) + _, ok := results.(PullRequestDeclinedPayload) + Equal(t, ok, true) +} + +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" + } + } + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, PullRequestCommentCreatedEvent) + }) + 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", "pullrequest:comment_created") + + 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, nil) + _, ok := results.(PullRequestCommentCreatedPayload) + Equal(t, ok, true) +} + +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" + } + } + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, PullRequestCommentUpdatedEvent) + }) + 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", "pullrequest:comment_updated") + + 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, nil) + _, ok := results.(PullRequestCommentUpdatedPayload) + Equal(t, ok, true) +} + +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" + } + } + } +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, PullRequestCommentDeletedEvent) + }) + 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", "pullrequest:comment_deleted") + + 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, nil) + _, ok := results.(PullRequestCommentDeletedPayload) + Equal(t, ok, true) +} diff --git a/github/github_test.go b/github/github_test.go index a3d70ab..d937986 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -47,14 +47,14 @@ func newServer(handler http.HandlerFunc) *httptest.Server { } func TestBadNoEventHeader(t *testing.T) { + payload := "{}" + var parseError error server := newServer(func(w http.ResponseWriter, r *http.Request) { _, parseError = hook.Parse(r, CreateEvent) }) defer server.Close() - payload := "{}" - req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) Equal(t, err, nil) @@ -68,12 +68,13 @@ func TestBadNoEventHeader(t *testing.T) { } func TestUnsubscribedEvent(t *testing.T) { + payload := "{}" + var parseError error server := newServer(func(w http.ResponseWriter, r *http.Request) { _, parseError = hook.Parse(r, CreateEvent) }) defer server.Close() - payload := "{}" req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) Equal(t, err, nil) @@ -89,12 +90,12 @@ func TestUnsubscribedEvent(t *testing.T) { } func TestBadBody(t *testing.T) { + payload := "" var parseError error server := newServer(func(w http.ResponseWriter, r *http.Request) { _, parseError = hook.Parse(r, CommitCommentEvent) }) defer server.Close() - payload := "" req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) Equal(t, err, nil) @@ -112,12 +113,13 @@ func TestBadBody(t *testing.T) { } func TestBadSignatureLength(t *testing.T) { + payload := "{}" + var parseError error server := newServer(func(w http.ResponseWriter, r *http.Request) { _, parseError = hook.Parse(r, CommitCommentEvent) }) defer server.Close() - payload := "{}" req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) Equal(t, err, nil) @@ -135,12 +137,13 @@ func TestBadSignatureLength(t *testing.T) { } func TestBadSignatureMatch(t *testing.T) { + payload := "{}" + var parseError error server := newServer(func(w http.ResponseWriter, r *http.Request) { _, parseError = hook.Parse(r, CommitCommentEvent) }) defer server.Close() - payload := "{}" req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) Equal(t, err, nil) @@ -1574,7 +1577,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 accidentally spelled 'commit' with two 't's." + "body": "It looks like you accidently 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 0c00252..e603868 100644 --- a/gitlab/gitlab.go +++ b/gitlab/gitlab.go @@ -11,12 +11,12 @@ import ( // 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") + ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse") + ErrInvalidHTTPMethod = errors.New("invalid HTTP Method") + ErrMissingGitLabEventHeader = errors.New("missing X-Gitlab-Event Header") + ErrGitLabTokenVerificationFailed = errors.New("X-Gitlab-Token validation failed") + ErrEventNotFound = errors.New("event not defined to be parsed") + ErrParsingPayload = errors.New("error parsing payload") // ErrHMACVerificationFailed = errors.New("HMAC verification failed") ) @@ -111,7 +111,7 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) if len(hook.secret) > 0 { signature := r.Header.Get("X-Gitlab-Token") if signature != hook.secret { - return nil, ErrMissingGitLabTokenHeader + return nil, ErrGitLabTokenVerificationFailed } } diff --git a/gitlab/gitlab_test.go b/gitlab/gitlab_test.go index fd513b4..bbafbff 100644 --- a/gitlab/gitlab_test.go +++ b/gitlab/gitlab_test.go @@ -9,7 +9,6 @@ import ( "testing" . "gopkg.in/go-playground/assert.v1" - "gopkg.in/go-playground/webhooks.v5" ) // NOTES: @@ -27,18 +26,13 @@ const ( path = "/webhooks" ) -// HandlePayload handles GitHub event(s) -func HandlePayload(payload interface{}, header webhooks.Header) { - -} - var hook *Webhook func TestMain(m *testing.M) { // setup var err error - hook, err = New(Options.Secret("sampleToken!!")) + hook, err = New(Options.Secret("sampleToken!")) if err != nil { log.Fatal(err) } @@ -56,7 +50,14 @@ func newServer(handler http.HandlerFunc) *httptest.Server { func TestBadNoEventHeader(t *testing.T) { payload := "{}" - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/webhooks", bytes.NewBuffer([]byte(payload))) + var parseError error + server := newServer(func(w http.ResponseWriter, r *http.Request) { + _, parseError = hook.Parse(r, PushEvents) + }) + 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") Equal(t, err, nil) @@ -64,16 +65,21 @@ 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) + Equal(t, resp.StatusCode, http.StatusOK) + Equal(t, parseError, ErrMissingGitLabEventHeader) } func TestUnsubscribedEvent(t *testing.T) { payload := "{}" - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/webhooks", bytes.NewBuffer([]byte(payload))) + var parseError error + server := newServer(func(w http.ResponseWriter, r *http.Request) { + _, parseError = hook.Parse(r, PushEvents) + }) + 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-Gitlab-Event", "noneexistant_event") @@ -82,120 +88,21 @@ func TestUnsubscribedEvent(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, ErrEventNotFound) } func TestBadBody(t *testing.T) { payload := "" - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/webhooks", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - req.Header.Set("X-Gitlab-Event", "Note Hook") + var parseError error + server := newServer(func(w http.ResponseWriter, r *http.Request) { + _, parseError = hook.Parse(r, PushEvents) + }) + defer server.Close() + req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) 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.StatusInternalServerError) -} - -func TestTokenMissmatch(t *testing.T) { - payload := "{}" - - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/webhooks", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - req.Header.Set("X-Gitlab-Event", "Note Hook") - req.Header.Set("X-Gitlab-Token", "itsnotasampleToken!") - - 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) -} - -func TestPushEvent(t *testing.T) { - - payload := `{ - "object_kind": "push", - "before": "95790bf891e76fee5e1747ab589903a6a1f80f22", - "after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", - "ref": "refs/heads/master", - "checkout_sha": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", - "user_id": 4, - "user_name": "John Smith", - "user_email": "john@example.com", - "user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80", - "project_id": 15, - "project":{ - "name":"Diaspora", - "description":"", - "web_url":"http://example.com/mike/diaspora", - "avatar_url":null, - "git_ssh_url":"git@example.com:mike/diaspora.git", - "git_http_url":"http://example.com/mike/diaspora.git", - "namespace":"Mike", - "visibility_level":0, - "path_with_namespace":"mike/diaspora", - "default_branch":"master", - "homepage":"http://example.com/mike/diaspora", - "url":"git@example.com:mike/diaspora.git", - "ssh_url":"git@example.com:mike/diaspora.git", - "http_url":"http://example.com/mike/diaspora.git" - }, - "repository":{ - "name": "Diaspora", - "url": "git@example.com:mike/diaspora.git", - "description": "", - "homepage": "http://example.com/mike/diaspora", - "git_http_url":"http://example.com/mike/diaspora.git", - "git_ssh_url":"git@example.com:mike/diaspora.git", - "visibility_level":0 - }, - "commits": [ - { - "id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", - "message": "Update Catalan translation to e38cb41.", - "timestamp": "2011-12-12T14:27:31+02:00", - "url": "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", - "author": { - "name": "Jordi Mallach", - "email": "jordi@softcatala.org" - }, - "added": ["CHANGELOG"], - "modified": ["app/controller/application.rb"], - "removed": [] - }, - { - "id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", - "message": "fixed readme", - "timestamp": "2012-01-03T23:36:29+02:00", - "url": "http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7", - "author": { - "name": "GitLab dev user", - "email": "gitlabdev@dv6700.(none)" - }, - "added": ["CHANGELOG"], - "modified": ["app/controller/application.rb"], - "removed": [] - } - ], - "total_commits_count": 4 -} -` - - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/webhooks", bytes.NewBuffer([]byte(payload))) req.Header.Set("Content-Type", "application/json") req.Header.Set("X-Gitlab-Event", "Push Hook") req.Header.Set("X-Gitlab-Token", "sampleToken!") @@ -205,55 +112,179 @@ func TestPushEvent(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, ErrParsingPayload) +} + +func TestTokenMismatch(t *testing.T) { + payload := "{}" + + var parseError error + server := newServer(func(w http.ResponseWriter, r *http.Request) { + _, parseError = hook.Parse(r, PushEvents) + }) + 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-Gitlab-Event", "Push Hook") + req.Header.Set("X-Gitlab-Token", "badsampleToken!!") + + 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, ErrGitLabTokenVerificationFailed) +} + +func TestPushEvent(t *testing.T) { + + payload := `{ + "object_kind": "push", + "before": "95790bf891e76fee5e1747ab589903a6a1f80f22", + "after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "ref": "refs/heads/master", + "checkout_sha": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "user_id": 4, + "user_name": "John Smith", + "user_email": "john@example.com", + "user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80", + "project_id": 15, + "project":{ + "name":"Diaspora", + "description":"", + "web_url":"http://example.com/mike/diaspora", + "avatar_url":null, + "git_ssh_url":"git@example.com:mike/diaspora.git", + "git_http_url":"http://example.com/mike/diaspora.git", + "namespace":"Mike", + "visibility_level":0, + "path_with_namespace":"mike/diaspora", + "default_branch":"master", + "homepage":"http://example.com/mike/diaspora", + "url":"git@example.com:mike/diaspora.git", + "ssh_url":"git@example.com:mike/diaspora.git", + "http_url":"http://example.com/mike/diaspora.git" + }, + "repository":{ + "name": "Diaspora", + "url": "git@example.com:mike/diaspora.git", + "description": "", + "homepage": "http://example.com/mike/diaspora", + "git_http_url":"http://example.com/mike/diaspora.git", + "git_ssh_url":"git@example.com:mike/diaspora.git", + "visibility_level":0 + }, + "commits": [ + { + "id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", + "message": "Update Catalan translation to e38cb41.", + "timestamp": "2011-12-12T14:27:31+02:00", + "url": "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", + "author": { + "name": "Jordi Mallach", + "email": "jordi@softcatala.org" + }, + "added": ["CHANGELOG"], + "modified": ["app/controller/application.rb"], + "removed": [] + }, + { + "id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "message": "fixed readme", + "timestamp": "2012-01-03T23:36:29+02:00", + "url": "http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "author": { + "name": "GitLab dev user", + "email": "gitlabdev@dv6700.(none)" + }, + "added": ["CHANGELOG"], + "modified": ["app/controller/application.rb"], + "removed": [] + } + ], + "total_commits_count": 4 +} +` + + var parseError error + var results interface{} + server := newServer(func(w http.ResponseWriter, r *http.Request) { + results, parseError = hook.Parse(r, PushEvents) + }) + 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-Gitlab-Event", "Push Hook") + req.Header.Set("X-Gitlab-Token", "sampleToken!") + + 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, nil) + _, ok := results.(PushEventPayload) + Equal(t, ok, true) } func TestTagEvent(t *testing.T) { payload := `{ - "object_kind": "tag_push", - "before": "0000000000000000000000000000000000000000", - "after": "82b3d5ae55f7080f1e6022629cdb57bfae7cccc7", - "ref": "refs/tags/v1.0.0", - "checkout_sha": "82b3d5ae55f7080f1e6022629cdb57bfae7cccc7", - "user_id": 1, - "user_name": "John Smith", - "user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80", - "project_id": 1, - "project":{ - "name":"Example", - "description":"", - "web_url":"http://example.com/jsmith/example", - "avatar_url":null, - "git_ssh_url":"git@example.com:jsmith/example.git", - "git_http_url":"http://example.com/jsmith/example.git", - "namespace":"Jsmith", - "visibility_level":0, - "path_with_namespace":"jsmith/example", - "default_branch":"master", - "homepage":"http://example.com/jsmith/example", - "url":"git@example.com:jsmith/example.git", - "ssh_url":"git@example.com:jsmith/example.git", - "http_url":"http://example.com/jsmith/example.git" - }, - "repository":{ - "name": "Example", - "url": "ssh://git@example.com/jsmith/example.git", - "description": "", - "homepage": "http://example.com/jsmith/example", - "git_http_url":"http://example.com/jsmith/example.git", - "git_ssh_url":"git@example.com:jsmith/example.git", - "visibility_level":0 - }, - "commits": [], - "total_commits_count": 0 + "object_kind": "tag_push", + "before": "0000000000000000000000000000000000000000", + "after": "82b3d5ae55f7080f1e6022629cdb57bfae7cccc7", + "ref": "refs/tags/v1.0.0", + "checkout_sha": "82b3d5ae55f7080f1e6022629cdb57bfae7cccc7", + "user_id": 1, + "user_name": "John Smith", + "user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80", + "project_id": 1, + "project":{ + "name":"Example", + "description":"", + "web_url":"http://example.com/jsmith/example", + "avatar_url":null, + "git_ssh_url":"git@example.com:jsmith/example.git", + "git_http_url":"http://example.com/jsmith/example.git", + "namespace":"Jsmith", + "visibility_level":0, + "path_with_namespace":"jsmith/example", + "default_branch":"master", + "homepage":"http://example.com/jsmith/example", + "url":"git@example.com:jsmith/example.git", + "ssh_url":"git@example.com:jsmith/example.git", + "http_url":"http://example.com/jsmith/example.git" + }, + "repository":{ + "name": "Example", + "url": "ssh://git@example.com/jsmith/example.git", + "description": "", + "homepage": "http://example.com/jsmith/example", + "git_http_url":"http://example.com/jsmith/example.git", + "git_ssh_url":"git@example.com:jsmith/example.git", + "visibility_level":0 + }, + "commits": [], + "total_commits_count": 0 } ` - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/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, TagEvents) + }) + 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-Gitlab-Event", "Tag Push Hook") req.Header.Set("X-Gitlab-Token", "sampleToken!") @@ -263,69 +294,77 @@ func TestTagEvent(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.(TagEventPayload) + Equal(t, ok, true) } func TestIssueEvent(t *testing.T) { payload := `{ - "object_kind": "issue", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - }, - "project":{ - "name":"Gitlab Test", - "description":"Aut reprehenderit ut est.", - "web_url":"http://example.com/gitlabhq/gitlab-test", - "avatar_url":null, - "git_ssh_url":"git@example.com:gitlabhq/gitlab-test.git", - "git_http_url":"http://example.com/gitlabhq/gitlab-test.git", - "namespace":"GitlabHQ", - "visibility_level":20, - "path_with_namespace":"gitlabhq/gitlab-test", - "default_branch":"master", - "homepage":"http://example.com/gitlabhq/gitlab-test", - "url":"http://example.com/gitlabhq/gitlab-test.git", - "ssh_url":"git@example.com:gitlabhq/gitlab-test.git", - "http_url":"http://example.com/gitlabhq/gitlab-test.git" - }, - "repository":{ - "name": "Gitlab Test", - "url": "http://example.com/gitlabhq/gitlab-test.git", - "description": "Aut reprehenderit ut est.", - "homepage": "http://example.com/gitlabhq/gitlab-test" - }, - "object_attributes": { - "id": 301, - "title": "New API: create/update/delete file", - "assignee_id": 51, - "author_id": 51, - "project_id": 14, - "created_at": "2013-12-03T17:15:43Z", - "updated_at": "2013-12-03T17:15:43Z", - "position": 0, - "branch_name": null, - "description": "Create new API for manipulations with repository", - "milestone_id": null, - "state": "opened", - "iid": 23, - "url": "http://example.com/diaspora/issues/23", - "action": "open" - }, - "assignee": { - "name": "User1", - "username": "user1", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - } + "object_kind": "issue", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + }, + "project":{ + "name":"Gitlab Test", + "description":"Aut reprehenderit ut est.", + "web_url":"http://example.com/gitlabhq/gitlab-test", + "avatar_url":null, + "git_ssh_url":"git@example.com:gitlabhq/gitlab-test.git", + "git_http_url":"http://example.com/gitlabhq/gitlab-test.git", + "namespace":"GitlabHQ", + "visibility_level":20, + "path_with_namespace":"gitlabhq/gitlab-test", + "default_branch":"master", + "homepage":"http://example.com/gitlabhq/gitlab-test", + "url":"http://example.com/gitlabhq/gitlab-test.git", + "ssh_url":"git@example.com:gitlabhq/gitlab-test.git", + "http_url":"http://example.com/gitlabhq/gitlab-test.git" + }, + "repository":{ + "name": "Gitlab Test", + "url": "http://example.com/gitlabhq/gitlab-test.git", + "description": "Aut reprehenderit ut est.", + "homepage": "http://example.com/gitlabhq/gitlab-test" + }, + "object_attributes": { + "id": 301, + "title": "New API: create/update/delete file", + "assignee_id": 51, + "author_id": 51, + "project_id": 14, + "created_at": "2013-12-03T17:15:43Z", + "updated_at": "2013-12-03T17:15:43Z", + "position": 0, + "branch_name": null, + "description": "Create new API for manipulations with repository", + "milestone_id": null, + "state": "opened", + "iid": 23, + "url": "http://example.com/diaspora/issues/23", + "action": "open" + }, + "assignee": { + "name": "User1", + "username": "user1", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + } } ` - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/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, IssuesEvents) + }) + 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-Gitlab-Event", "Issue Hook") req.Header.Set("X-Gitlab-Token", "sampleToken!") @@ -335,69 +374,77 @@ func TestIssueEvent(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.(IssueEventPayload) + Equal(t, ok, true) } func TestConfidentialIssueEvent(t *testing.T) { payload := `{ - "object_kind": "issue", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - }, - "project":{ - "name":"Gitlab Test", - "description":"Aut reprehenderit ut est.", - "web_url":"http://example.com/gitlabhq/gitlab-test", - "avatar_url":null, - "git_ssh_url":"git@example.com:gitlabhq/gitlab-test.git", - "git_http_url":"http://example.com/gitlabhq/gitlab-test.git", - "namespace":"GitlabHQ", - "visibility_level":20, - "path_with_namespace":"gitlabhq/gitlab-test", - "default_branch":"master", - "homepage":"http://example.com/gitlabhq/gitlab-test", - "url":"http://example.com/gitlabhq/gitlab-test.git", - "ssh_url":"git@example.com:gitlabhq/gitlab-test.git", - "http_url":"http://example.com/gitlabhq/gitlab-test.git" - }, - "repository":{ - "name": "Gitlab Test", - "url": "http://example.com/gitlabhq/gitlab-test.git", - "description": "Aut reprehenderit ut est.", - "homepage": "http://example.com/gitlabhq/gitlab-test" - }, - "object_attributes": { - "id": 301, - "title": "New API: create/update/delete file", - "assignee_id": 51, - "author_id": 51, - "project_id": 14, - "created_at": "2013-12-03T17:15:43Z", - "updated_at": "2013-12-03T17:15:43Z", - "position": 0, - "branch_name": null, - "description": "Create new API for manipulations with repository", - "milestone_id": null, - "state": "opened", - "iid": 23, - "url": "http://example.com/diaspora/issues/23", - "action": "open" - }, - "assignee": { - "name": "User1", - "username": "user1", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - } - } - ` + "object_kind": "issue", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + }, + "project":{ + "name":"Gitlab Test", + "description":"Aut reprehenderit ut est.", + "web_url":"http://example.com/gitlabhq/gitlab-test", + "avatar_url":null, + "git_ssh_url":"git@example.com:gitlabhq/gitlab-test.git", + "git_http_url":"http://example.com/gitlabhq/gitlab-test.git", + "namespace":"GitlabHQ", + "visibility_level":20, + "path_with_namespace":"gitlabhq/gitlab-test", + "default_branch":"master", + "homepage":"http://example.com/gitlabhq/gitlab-test", + "url":"http://example.com/gitlabhq/gitlab-test.git", + "ssh_url":"git@example.com:gitlabhq/gitlab-test.git", + "http_url":"http://example.com/gitlabhq/gitlab-test.git" + }, + "repository":{ + "name": "Gitlab Test", + "url": "http://example.com/gitlabhq/gitlab-test.git", + "description": "Aut reprehenderit ut est.", + "homepage": "http://example.com/gitlabhq/gitlab-test" + }, + "object_attributes": { + "id": 301, + "title": "New API: create/update/delete file", + "assignee_id": 51, + "author_id": 51, + "project_id": 14, + "created_at": "2013-12-03T17:15:43Z", + "updated_at": "2013-12-03T17:15:43Z", + "position": 0, + "branch_name": null, + "description": "Create new API for manipulations with repository", + "milestone_id": null, + "state": "opened", + "iid": 23, + "url": "http://example.com/diaspora/issues/23", + "action": "open" + }, + "assignee": { + "name": "User1", + "username": "user1", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + } + } + ` - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/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, ConfidentialIssuesEvents) + }) + 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-Gitlab-Event", "Confidential Issue Hook") req.Header.Set("X-Gitlab-Token", "sampleToken!") @@ -407,83 +454,91 @@ func TestConfidentialIssueEvent(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.(ConfidentialIssueEventPayload) + Equal(t, ok, true) } func TestCommentCommitEvent(t *testing.T) { payload := `{ - "object_kind": "note", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - }, - "project_id": 5, - "project":{ - "name":"Gitlab Test", - "description":"Aut reprehenderit ut est.", - "web_url":"http://example.com/gitlabhq/gitlab-test", - "avatar_url":null, - "git_ssh_url":"git@example.com:gitlabhq/gitlab-test.git", - "git_http_url":"http://example.com/gitlabhq/gitlab-test.git", - "namespace":"GitlabHQ", - "visibility_level":20, - "path_with_namespace":"gitlabhq/gitlab-test", - "default_branch":"master", - "homepage":"http://example.com/gitlabhq/gitlab-test", - "url":"http://example.com/gitlabhq/gitlab-test.git", - "ssh_url":"git@example.com:gitlabhq/gitlab-test.git", - "http_url":"http://example.com/gitlabhq/gitlab-test.git" - }, - "repository":{ - "name": "Gitlab Test", - "url": "http://example.com/gitlab-org/gitlab-test.git", - "description": "Aut reprehenderit ut est.", - "homepage": "http://example.com/gitlab-org/gitlab-test" - }, - "object_attributes": { - "id": 1243, - "note": "This is a commit comment. How does this work?", - "noteable_type": "Commit", - "author_id": 1, - "created_at": "2015-05-17 18:08:09 UTC", - "updated_at": "2015-05-17 18:08:09 UTC", - "project_id": 5, - "attachment":null, - "line_code": "bec9703f7a456cd2b4ab5fb3220ae016e3e394e3_0_1", - "commit_id": "cfe32cf61b73a0d5e9f13e774abde7ff789b1660", - "noteable_id": null, - "system": false, - "st_diff": { - "diff": "--- /dev/null\n+++ b/six\n@@ -0,0 +1 @@\n+Subproject commit 409f37c4f05865e4fb208c771485f211a22c4c2d\n", - "new_path": "six", - "old_path": "six", - "a_mode": "0", - "b_mode": "160000", - "new_file": true, - "renamed_file": false, - "deleted_file": false - }, - "url": "http://example.com/gitlab-org/gitlab-test/commit/cfe32cf61b73a0d5e9f13e774abde7ff789b1660#note_1243" - }, - "commit": { - "id": "cfe32cf61b73a0d5e9f13e774abde7ff789b1660", - "message": "Add submodule\n\nSigned-off-by: Dmitriy Zaporozhets \u003cdmitriy.zaporozhets@gmail.com\u003e\n", - "timestamp": "2014-02-27T10:06:20+02:00", - "url": "http://example.com/gitlab-org/gitlab-test/commit/cfe32cf61b73a0d5e9f13e774abde7ff789b1660", - "author": { - "name": "Dmitriy Zaporozhets", - "email": "dmitriy.zaporozhets@gmail.com" - } - } + "object_kind": "note", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + }, + "project_id": 5, + "project":{ + "name":"Gitlab Test", + "description":"Aut reprehenderit ut est.", + "web_url":"http://example.com/gitlabhq/gitlab-test", + "avatar_url":null, + "git_ssh_url":"git@example.com:gitlabhq/gitlab-test.git", + "git_http_url":"http://example.com/gitlabhq/gitlab-test.git", + "namespace":"GitlabHQ", + "visibility_level":20, + "path_with_namespace":"gitlabhq/gitlab-test", + "default_branch":"master", + "homepage":"http://example.com/gitlabhq/gitlab-test", + "url":"http://example.com/gitlabhq/gitlab-test.git", + "ssh_url":"git@example.com:gitlabhq/gitlab-test.git", + "http_url":"http://example.com/gitlabhq/gitlab-test.git" + }, + "repository":{ + "name": "Gitlab Test", + "url": "http://example.com/gitlab-org/gitlab-test.git", + "description": "Aut reprehenderit ut est.", + "homepage": "http://example.com/gitlab-org/gitlab-test" + }, + "object_attributes": { + "id": 1243, + "note": "This is a commit comment. How does this work?", + "noteable_type": "Commit", + "author_id": 1, + "created_at": "2015-05-17 18:08:09 UTC", + "updated_at": "2015-05-17 18:08:09 UTC", + "project_id": 5, + "attachment":null, + "line_code": "bec9703f7a456cd2b4ab5fb3220ae016e3e394e3_0_1", + "commit_id": "cfe32cf61b73a0d5e9f13e774abde7ff789b1660", + "noteable_id": null, + "system": false, + "st_diff": { + "diff": "--- /dev/null\n+++ b/six\n@@ -0,0 +1 @@\n+Subproject commit 409f37c4f05865e4fb208c771485f211a22c4c2d\n", + "new_path": "six", + "old_path": "six", + "a_mode": "0", + "b_mode": "160000", + "new_file": true, + "renamed_file": false, + "deleted_file": false + }, + "url": "http://example.com/gitlab-org/gitlab-test/commit/cfe32cf61b73a0d5e9f13e774abde7ff789b1660#note_1243" + }, + "commit": { + "id": "cfe32cf61b73a0d5e9f13e774abde7ff789b1660", + "message": "Add submodule\n\nSigned-off-by: Dmitriy Zaporozhets \u003cdmitriy.zaporozhets@gmail.com\u003e\n", + "timestamp": "2014-02-27T10:06:20+02:00", + "url": "http://example.com/gitlab-org/gitlab-test/commit/cfe32cf61b73a0d5e9f13e774abde7ff789b1660", + "author": { + "name": "Dmitriy Zaporozhets", + "email": "dmitriy.zaporozhets@gmail.com" + } + } } ` - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/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, CommentEvents) + }) + 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-Gitlab-Event", "Note Hook") req.Header.Set("X-Gitlab-Token", "sampleToken!") @@ -493,131 +548,139 @@ func TestCommentCommitEvent(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.(CommentEventPayload) + Equal(t, ok, true) } func TestCommentMergeRequestEvent(t *testing.T) { payload := `{ - "object_kind": "note", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - }, - "project_id": 5, - "project":{ - "name":"Gitlab Test", - "description":"Aut reprehenderit ut est.", - "web_url":"http://example.com/gitlab-org/gitlab-test", - "avatar_url":null, - "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git", - "git_http_url":"http://example.com/gitlab-org/gitlab-test.git", - "namespace":"Gitlab Org", - "visibility_level":10, - "path_with_namespace":"gitlab-org/gitlab-test", - "default_branch":"master", - "homepage":"http://example.com/gitlab-org/gitlab-test", - "url":"http://example.com/gitlab-org/gitlab-test.git", - "ssh_url":"git@example.com:gitlab-org/gitlab-test.git", - "http_url":"http://example.com/gitlab-org/gitlab-test.git" - }, - "repository":{ - "name": "Gitlab Test", - "url": "http://localhost/gitlab-org/gitlab-test.git", - "description": "Aut reprehenderit ut est.", - "homepage": "http://example.com/gitlab-org/gitlab-test" - }, - "object_attributes": { - "id": 1244, - "note": "This MR needs work.", - "noteable_type": "MergeRequest", - "author_id": 1, - "created_at": "2015-05-17 18:21:36 UTC", - "updated_at": "2015-05-17 18:21:36 UTC", - "project_id": 5, - "attachment": null, - "line_code": null, - "commit_id": "", - "noteable_id": 7, - "system": false, - "st_diff": null, - "url": "http://example.com/gitlab-org/gitlab-test/merge_requests/1#note_1244" - }, - "merge_request": { - "id": 7, - "target_branch": "markdown", - "source_branch": "master", - "source_project_id": 5, - "author_id": 8, - "assignee_id": 28, - "title": "Tempora et eos debitis quae laborum et.", - "created_at": "2015-03-01 20:12:53 UTC", - "updated_at": "2015-03-21 18:27:27 UTC", - "milestone_id": 11, - "state": "opened", - "merge_status": "cannot_be_merged", - "target_project_id": 5, - "iid": 1, - "description": "Et voluptas corrupti assumenda temporibus. Architecto cum animi eveniet amet asperiores. Vitae numquam voluptate est natus sit et ad id.", - "position": 0, - "locked_at": null, - "source":{ - "name":"Gitlab Test", - "description":"Aut reprehenderit ut est.", - "web_url":"http://example.com/gitlab-org/gitlab-test", - "avatar_url":null, - "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git", - "git_http_url":"http://example.com/gitlab-org/gitlab-test.git", - "namespace":"Gitlab Org", - "visibility_level":10, - "path_with_namespace":"gitlab-org/gitlab-test", - "default_branch":"master", - "homepage":"http://example.com/gitlab-org/gitlab-test", - "url":"http://example.com/gitlab-org/gitlab-test.git", - "ssh_url":"git@example.com:gitlab-org/gitlab-test.git", - "http_url":"http://example.com/gitlab-org/gitlab-test.git" - }, - "target": { - "name":"Gitlab Test", - "description":"Aut reprehenderit ut est.", - "web_url":"http://example.com/gitlab-org/gitlab-test", - "avatar_url":null, - "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git", - "git_http_url":"http://example.com/gitlab-org/gitlab-test.git", - "namespace":"Gitlab Org", - "visibility_level":10, - "path_with_namespace":"gitlab-org/gitlab-test", - "default_branch":"master", - "homepage":"http://example.com/gitlab-org/gitlab-test", - "url":"http://example.com/gitlab-org/gitlab-test.git", - "ssh_url":"git@example.com:gitlab-org/gitlab-test.git", - "http_url":"http://example.com/gitlab-org/gitlab-test.git" - }, - "last_commit": { - "id": "562e173be03b8ff2efb05345d12df18815438a4b", - "message": "Merge branch 'another-branch' into 'master'\n\nCheck in this test\n", - "timestamp": "2015-04-08T21: 00:25-07:00", - "url": "http://example.com/gitlab-org/gitlab-test/commit/562e173be03b8ff2efb05345d12df18815438a4b", - "author": { - "name": "John Smith", - "email": "john@example.com" - } - }, - "work_in_progress": false, - "assignee": { - "name": "User1", - "username": "user1", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - } - } + "object_kind": "note", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + }, + "project_id": 5, + "project":{ + "name":"Gitlab Test", + "description":"Aut reprehenderit ut est.", + "web_url":"http://example.com/gitlab-org/gitlab-test", + "avatar_url":null, + "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git", + "git_http_url":"http://example.com/gitlab-org/gitlab-test.git", + "namespace":"Gitlab Org", + "visibility_level":10, + "path_with_namespace":"gitlab-org/gitlab-test", + "default_branch":"master", + "homepage":"http://example.com/gitlab-org/gitlab-test", + "url":"http://example.com/gitlab-org/gitlab-test.git", + "ssh_url":"git@example.com:gitlab-org/gitlab-test.git", + "http_url":"http://example.com/gitlab-org/gitlab-test.git" + }, + "repository":{ + "name": "Gitlab Test", + "url": "http://localhost/gitlab-org/gitlab-test.git", + "description": "Aut reprehenderit ut est.", + "homepage": "http://example.com/gitlab-org/gitlab-test" + }, + "object_attributes": { + "id": 1244, + "note": "This MR needs work.", + "noteable_type": "MergeRequest", + "author_id": 1, + "created_at": "2015-05-17 18:21:36 UTC", + "updated_at": "2015-05-17 18:21:36 UTC", + "project_id": 5, + "attachment": null, + "line_code": null, + "commit_id": "", + "noteable_id": 7, + "system": false, + "st_diff": null, + "url": "http://example.com/gitlab-org/gitlab-test/merge_requests/1#note_1244" + }, + "merge_request": { + "id": 7, + "target_branch": "markdown", + "source_branch": "master", + "source_project_id": 5, + "author_id": 8, + "assignee_id": 28, + "title": "Tempora et eos debitis quae laborum et.", + "created_at": "2015-03-01 20:12:53 UTC", + "updated_at": "2015-03-21 18:27:27 UTC", + "milestone_id": 11, + "state": "opened", + "merge_status": "cannot_be_merged", + "target_project_id": 5, + "iid": 1, + "description": "Et voluptas corrupti assumenda temporibus. Architecto cum animi eveniet amet asperiores. Vitae numquam voluptate est natus sit et ad id.", + "position": 0, + "locked_at": null, + "source":{ + "name":"Gitlab Test", + "description":"Aut reprehenderit ut est.", + "web_url":"http://example.com/gitlab-org/gitlab-test", + "avatar_url":null, + "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git", + "git_http_url":"http://example.com/gitlab-org/gitlab-test.git", + "namespace":"Gitlab Org", + "visibility_level":10, + "path_with_namespace":"gitlab-org/gitlab-test", + "default_branch":"master", + "homepage":"http://example.com/gitlab-org/gitlab-test", + "url":"http://example.com/gitlab-org/gitlab-test.git", + "ssh_url":"git@example.com:gitlab-org/gitlab-test.git", + "http_url":"http://example.com/gitlab-org/gitlab-test.git" + }, + "target": { + "name":"Gitlab Test", + "description":"Aut reprehenderit ut est.", + "web_url":"http://example.com/gitlab-org/gitlab-test", + "avatar_url":null, + "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git", + "git_http_url":"http://example.com/gitlab-org/gitlab-test.git", + "namespace":"Gitlab Org", + "visibility_level":10, + "path_with_namespace":"gitlab-org/gitlab-test", + "default_branch":"master", + "homepage":"http://example.com/gitlab-org/gitlab-test", + "url":"http://example.com/gitlab-org/gitlab-test.git", + "ssh_url":"git@example.com:gitlab-org/gitlab-test.git", + "http_url":"http://example.com/gitlab-org/gitlab-test.git" + }, + "last_commit": { + "id": "562e173be03b8ff2efb05345d12df18815438a4b", + "message": "Merge branch 'another-branch' into 'master'\n\nCheck in this test\n", + "timestamp": "2015-04-08T21:00:25-07:00", + "url": "http://example.com/gitlab-org/gitlab-test/commit/562e173be03b8ff2efb05345d12df18815438a4b", + "author": { + "name": "John Smith", + "email": "john@example.com" + } + }, + "work_in_progress": false, + "assignee": { + "name": "User1", + "username": "user1", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + } + } } ` - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/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, CommentEvents) + }) + 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-Gitlab-Event", "Note Hook") req.Header.Set("X-Gitlab-Token", "sampleToken!") @@ -627,79 +690,87 @@ func TestCommentMergeRequestEvent(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.(CommentEventPayload) + Equal(t, ok, true) } func TestCommentIssueEvent(t *testing.T) { payload := `{ - "object_kind": "note", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - }, - "project_id": 5, - "project":{ - "name":"Gitlab Test", - "description":"Aut reprehenderit ut est.", - "web_url":"http://example.com/gitlab-org/gitlab-test", - "avatar_url":null, - "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git", - "git_http_url":"http://example.com/gitlab-org/gitlab-test.git", - "namespace":"Gitlab Org", - "visibility_level":10, - "path_with_namespace":"gitlab-org/gitlab-test", - "default_branch":"master", - "homepage":"http://example.com/gitlab-org/gitlab-test", - "url":"http://example.com/gitlab-org/gitlab-test.git", - "ssh_url":"git@example.com:gitlab-org/gitlab-test.git", - "http_url":"http://example.com/gitlab-org/gitlab-test.git" - }, - "repository":{ - "name":"diaspora", - "url":"git@example.com:mike/diaspora.git", - "description":"", - "homepage":"http://example.com/mike/diaspora" - }, - "object_attributes": { - "id": 1241, - "note": "Hello world", - "noteable_type": "Issue", - "author_id": 1, - "created_at": "2015-05-17 17:06:40 UTC", - "updated_at": "2015-05-17 17:06:40 UTC", - "project_id": 5, - "attachment": null, - "line_code": null, - "commit_id": "", - "noteable_id": 92, - "system": false, - "st_diff": null, - "url": "http://example.com/gitlab-org/gitlab-test/issues/17#note_1241" - }, - "issue": { - "id": 92, - "title": "test", - "assignee_id": null, - "author_id": 1, - "project_id": 5, - "created_at": "2015-04-12 14:53:17 UTC", - "updated_at": "2015-04-26 08:28:42 UTC", - "position": 0, - "branch_name": null, - "description": "test", - "milestone_id": null, - "state": "closed", - "iid": 17 - } + "object_kind": "note", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + }, + "project_id": 5, + "project":{ + "name":"Gitlab Test", + "description":"Aut reprehenderit ut est.", + "web_url":"http://example.com/gitlab-org/gitlab-test", + "avatar_url":null, + "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git", + "git_http_url":"http://example.com/gitlab-org/gitlab-test.git", + "namespace":"Gitlab Org", + "visibility_level":10, + "path_with_namespace":"gitlab-org/gitlab-test", + "default_branch":"master", + "homepage":"http://example.com/gitlab-org/gitlab-test", + "url":"http://example.com/gitlab-org/gitlab-test.git", + "ssh_url":"git@example.com:gitlab-org/gitlab-test.git", + "http_url":"http://example.com/gitlab-org/gitlab-test.git" + }, + "repository":{ + "name":"diaspora", + "url":"git@example.com:mike/diaspora.git", + "description":"", + "homepage":"http://example.com/mike/diaspora" + }, + "object_attributes": { + "id": 1241, + "note": "Hello world", + "noteable_type": "Issue", + "author_id": 1, + "created_at": "2015-05-17 17:06:40 UTC", + "updated_at": "2015-05-17 17:06:40 UTC", + "project_id": 5, + "attachment": null, + "line_code": null, + "commit_id": "", + "noteable_id": 92, + "system": false, + "st_diff": null, + "url": "http://example.com/gitlab-org/gitlab-test/issues/17#note_1241" + }, + "issue": { + "id": 92, + "title": "test", + "assignee_id": null, + "author_id": 1, + "project_id": 5, + "created_at": "2015-04-12 14:53:17 UTC", + "updated_at": "2015-04-26 08:28:42 UTC", + "position": 0, + "branch_name": null, + "description": "test", + "milestone_id": null, + "state": "closed", + "iid": 17 + } } ` - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/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, CommentEvents) + }) + 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-Gitlab-Event", "Note Hook") req.Header.Set("X-Gitlab-Token", "sampleToken!") @@ -709,77 +780,85 @@ func TestCommentIssueEvent(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.(CommentEventPayload) + Equal(t, ok, true) } -func TestCommentSunippetEvent(t *testing.T) { +func TestCommentSnippetEvent(t *testing.T) { payload := `{ - "object_kind": "note", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - }, - "project_id": 5, - "project":{ - "name":"Gitlab Test", - "description":"Aut reprehenderit ut est.", - "web_url":"http://example.com/gitlab-org/gitlab-test", - "avatar_url":null, - "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git", - "git_http_url":"http://example.com/gitlab-org/gitlab-test.git", - "namespace":"Gitlab Org", - "visibility_level":10, - "path_with_namespace":"gitlab-org/gitlab-test", - "default_branch":"master", - "homepage":"http://example.com/gitlab-org/gitlab-test", - "url":"http://example.com/gitlab-org/gitlab-test.git", - "ssh_url":"git@example.com:gitlab-org/gitlab-test.git", - "http_url":"http://example.com/gitlab-org/gitlab-test.git" - }, - "repository":{ - "name":"Gitlab Test", - "url":"http://example.com/gitlab-org/gitlab-test.git", - "description":"Aut reprehenderit ut est.", - "homepage":"http://example.com/gitlab-org/gitlab-test" - }, - "object_attributes": { - "id": 1245, - "note": "Is this snippet doing what it's supposed to be doing?", - "noteable_type": "Snippet", - "author_id": 1, - "created_at": "2015-05-17 18:35:50 UTC", - "updated_at": "2015-05-17 18:35:50 UTC", - "project_id": 5, - "attachment": null, - "line_code": null, - "commit_id": "", - "noteable_id": 53, - "system": false, - "st_diff": null, - "url": "http://example.com/gitlab-org/gitlab-test/snippets/53#note_1245" - }, - "snippet": { - "id": 53, - "title": "test", - "content": "puts 'Hello world'", - "author_id": 1, - "project_id": 5, - "created_at": "2015-04-09 02:40:38 UTC", - "updated_at": "2015-04-09 02:40:38 UTC", - "file_name": "test.rb", - "expires_at": null, - "type": "ProjectSnippet", - "visibility_level": 0 - } + "object_kind": "note", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + }, + "project_id": 5, + "project":{ + "name":"Gitlab Test", + "description":"Aut reprehenderit ut est.", + "web_url":"http://example.com/gitlab-org/gitlab-test", + "avatar_url":null, + "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git", + "git_http_url":"http://example.com/gitlab-org/gitlab-test.git", + "namespace":"Gitlab Org", + "visibility_level":10, + "path_with_namespace":"gitlab-org/gitlab-test", + "default_branch":"master", + "homepage":"http://example.com/gitlab-org/gitlab-test", + "url":"http://example.com/gitlab-org/gitlab-test.git", + "ssh_url":"git@example.com:gitlab-org/gitlab-test.git", + "http_url":"http://example.com/gitlab-org/gitlab-test.git" + }, + "repository":{ + "name":"Gitlab Test", + "url":"http://example.com/gitlab-org/gitlab-test.git", + "description":"Aut reprehenderit ut est.", + "homepage":"http://example.com/gitlab-org/gitlab-test" + }, + "object_attributes": { + "id": 1245, + "note": "Is this snippet doing what it's supposed to be doing?", + "noteable_type": "Snippet", + "author_id": 1, + "created_at": "2015-05-17 18:35:50 UTC", + "updated_at": "2015-05-17 18:35:50 UTC", + "project_id": 5, + "attachment": null, + "line_code": null, + "commit_id": "", + "noteable_id": 53, + "system": false, + "st_diff": null, + "url": "http://example.com/gitlab-org/gitlab-test/snippets/53#note_1245" + }, + "snippet": { + "id": 53, + "title": "test", + "content": "puts 'Hello world'", + "author_id": 1, + "project_id": 5, + "created_at": "2015-04-09 02:40:38 UTC", + "updated_at": "2015-04-09 02:40:38 UTC", + "file_name": "test.rb", + "expires_at": null, + "type": "ProjectSnippet", + "visibility_level": 0 + } } ` - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/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, CommentEvents) + }) + 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-Gitlab-Event", "Note Hook") req.Header.Set("X-Gitlab-Token", "sampleToken!") @@ -789,157 +868,165 @@ func TestCommentSunippetEvent(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.(CommentEventPayload) + Equal(t, ok, true) } func TestMergeRequestEvent(t *testing.T) { payload := `{ - "object_kind": "merge_request", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - }, - "project": { - "id": 1, - "name":"Gitlab Test", - "description":"Aut reprehenderit ut est.", - "web_url":"http://example.com/gitlabhq/gitlab-test", - "avatar_url":null, - "git_ssh_url":"git@example.com:gitlabhq/gitlab-test.git", - "git_http_url":"http://example.com/gitlabhq/gitlab-test.git", - "namespace":"GitlabHQ", - "visibility_level":20, - "path_with_namespace":"gitlabhq/gitlab-test", - "default_branch":"master", - "homepage":"http://example.com/gitlabhq/gitlab-test", - "url":"http://example.com/gitlabhq/gitlab-test.git", - "ssh_url":"git@example.com:gitlabhq/gitlab-test.git", - "http_url":"http://example.com/gitlabhq/gitlab-test.git" - }, - "repository": { - "name": "Gitlab Test", - "url": "http://example.com/gitlabhq/gitlab-test.git", - "description": "Aut reprehenderit ut est.", - "homepage": "http://example.com/gitlabhq/gitlab-test" - }, - "object_attributes": { - "id": 99, - "target_branch": "master", - "source_branch": "ms-viewport", - "source_project_id": 14, - "author_id": 51, - "assignee_id": 6, - "title": "MS-Viewport", - "created_at": "2013-12-03T17:23:34Z", - "updated_at": "2013-12-03T17:23:34Z", - "milestone_id": null, - "state": "opened", - "merge_status": "unchecked", - "target_project_id": 14, - "iid": 1, - "description": "", - "source": { - "name":"Awesome Project", - "description":"Aut reprehenderit ut est.", - "web_url":"http://example.com/awesome_space/awesome_project", - "avatar_url":null, - "git_ssh_url":"git@example.com:awesome_space/awesome_project.git", - "git_http_url":"http://example.com/awesome_space/awesome_project.git", - "namespace":"Awesome Space", - "visibility_level":20, - "path_with_namespace":"awesome_space/awesome_project", - "default_branch":"master", - "homepage":"http://example.com/awesome_space/awesome_project", - "url":"http://example.com/awesome_space/awesome_project.git", - "ssh_url":"git@example.com:awesome_space/awesome_project.git", - "http_url":"http://example.com/awesome_space/awesome_project.git" - }, - "target": { - "name":"Awesome Project", - "description":"Aut reprehenderit ut est.", - "web_url":"http://example.com/awesome_space/awesome_project", - "avatar_url":null, - "git_ssh_url":"git@example.com:awesome_space/awesome_project.git", - "git_http_url":"http://example.com/awesome_space/awesome_project.git", - "namespace":"Awesome Space", - "visibility_level":20, - "path_with_namespace":"awesome_space/awesome_project", - "default_branch":"master", - "homepage":"http://example.com/awesome_space/awesome_project", - "url":"http://example.com/awesome_space/awesome_project.git", - "ssh_url":"git@example.com:awesome_space/awesome_project.git", - "http_url":"http://example.com/awesome_space/awesome_project.git" - }, - "last_commit": { - "id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", - "message": "fixed readme", - "timestamp": "2012-01-03T23:36:29+02:00", - "url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7", - "author": { - "name": "GitLab dev user", - "email": "gitlabdev@dv6700.(none)" - } - }, - "work_in_progress": false, - "url": "http://example.com/diaspora/merge_requests/1", - "action": "open", - "assignee": { - "name": "User1", - "username": "user1", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - } - }, - "labels": [{ - "id": 206, - "title": "API", - "color": "#ffffff", - "project_id": 14, - "created_at": "2013-12-03T17:15:43Z", - "updated_at": "2013-12-03T17:15:43Z", - "template": false, - "description": "API related issues", - "type": "ProjectLabel", - "group_id": 41 - }], - "changes": { - "updated_by_id": [null, 1], - "updated_at": ["2017-09-15 16:50:55 UTC", "2017-09-15 16:52:00 UTC"], - "labels": { - "previous": [{ - "id": 206, - "title": "API", - "color": "#ffffff", - "project_id": 14, - "created_at": "2013-12-03T17:15:43Z", - "updated_at": "2013-12-03T17:15:43Z", - "template": false, - "description": "API related issues", - "type": "ProjectLabel", - "group_id": 41 - }], - "current": [{ - "id": 205, - "title": "Platform", - "color": "#123123", - "project_id": 14, - "created_at": "2013-12-03T17:15:43Z", - "updated_at": "2013-12-03T17:15:43Z", - "template": false, - "description": "Platform related issues", - "type": "ProjectLabel", - "group_id": 41 - }] - } - } - } + "object_kind": "merge_request", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + }, + "project": { + "id": 1, + "name":"Gitlab Test", + "description":"Aut reprehenderit ut est.", + "web_url":"http://example.com/gitlabhq/gitlab-test", + "avatar_url":null, + "git_ssh_url":"git@example.com:gitlabhq/gitlab-test.git", + "git_http_url":"http://example.com/gitlabhq/gitlab-test.git", + "namespace":"GitlabHQ", + "visibility_level":20, + "path_with_namespace":"gitlabhq/gitlab-test", + "default_branch":"master", + "homepage":"http://example.com/gitlabhq/gitlab-test", + "url":"http://example.com/gitlabhq/gitlab-test.git", + "ssh_url":"git@example.com:gitlabhq/gitlab-test.git", + "http_url":"http://example.com/gitlabhq/gitlab-test.git" + }, + "repository": { + "name": "Gitlab Test", + "url": "http://example.com/gitlabhq/gitlab-test.git", + "description": "Aut reprehenderit ut est.", + "homepage": "http://example.com/gitlabhq/gitlab-test" + }, + "object_attributes": { + "id": 99, + "target_branch": "master", + "source_branch": "ms-viewport", + "source_project_id": 14, + "author_id": 51, + "assignee_id": 6, + "title": "MS-Viewport", + "created_at": "2013-12-03T17:23:34Z", + "updated_at": "2013-12-03T17:23:34Z", + "milestone_id": null, + "state": "opened", + "merge_status": "unchecked", + "target_project_id": 14, + "iid": 1, + "description": "", + "source": { + "name":"Awesome Project", + "description":"Aut reprehenderit ut est.", + "web_url":"http://example.com/awesome_space/awesome_project", + "avatar_url":null, + "git_ssh_url":"git@example.com:awesome_space/awesome_project.git", + "git_http_url":"http://example.com/awesome_space/awesome_project.git", + "namespace":"Awesome Space", + "visibility_level":20, + "path_with_namespace":"awesome_space/awesome_project", + "default_branch":"master", + "homepage":"http://example.com/awesome_space/awesome_project", + "url":"http://example.com/awesome_space/awesome_project.git", + "ssh_url":"git@example.com:awesome_space/awesome_project.git", + "http_url":"http://example.com/awesome_space/awesome_project.git" + }, + "target": { + "name":"Awesome Project", + "description":"Aut reprehenderit ut est.", + "web_url":"http://example.com/awesome_space/awesome_project", + "avatar_url":null, + "git_ssh_url":"git@example.com:awesome_space/awesome_project.git", + "git_http_url":"http://example.com/awesome_space/awesome_project.git", + "namespace":"Awesome Space", + "visibility_level":20, + "path_with_namespace":"awesome_space/awesome_project", + "default_branch":"master", + "homepage":"http://example.com/awesome_space/awesome_project", + "url":"http://example.com/awesome_space/awesome_project.git", + "ssh_url":"git@example.com:awesome_space/awesome_project.git", + "http_url":"http://example.com/awesome_space/awesome_project.git" + }, + "last_commit": { + "id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "message": "fixed readme", + "timestamp": "2012-01-03T23:36:29+02:00", + "url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "author": { + "name": "GitLab dev user", + "email": "gitlabdev@dv6700.(none)" + } + }, + "work_in_progress": false, + "url": "http://example.com/diaspora/merge_requests/1", + "action": "open", + "assignee": { + "name": "User1", + "username": "user1", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + } + }, + "labels": [{ + "id": 206, + "title": "API", + "color": "#ffffff", + "project_id": 14, + "created_at": "2013-12-03T17:15:43Z", + "updated_at": "2013-12-03T17:15:43Z", + "template": false, + "description": "API related issues", + "type": "ProjectLabel", + "group_id": 41 + }], + "changes": { + "updated_by_id": [null, 1], + "updated_at": ["2017-09-15 16:50:55 UTC", "2017-09-15 16:52:00 UTC"], + "labels": { + "previous": [{ + "id": 206, + "title": "API", + "color": "#ffffff", + "project_id": 14, + "created_at": "2013-12-03T17:15:43Z", + "updated_at": "2013-12-03T17:15:43Z", + "template": false, + "description": "API related issues", + "type": "ProjectLabel", + "group_id": 41 + }], + "current": [{ + "id": 205, + "title": "Platform", + "color": "#123123", + "project_id": 14, + "created_at": "2013-12-03T17:15:43Z", + "updated_at": "2013-12-03T17:15:43Z", + "template": false, + "description": "Platform related issues", + "type": "ProjectLabel", + "group_id": 41 + }] + } + } + } ` - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/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, MergeRequestEvents) + }) + 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-Gitlab-Event", "Merge Request Hook") req.Header.Set("X-Gitlab-Token", "sampleToken!") @@ -949,57 +1036,65 @@ func TestMergeRequestEvent(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.(MergeRequestEventPayload) + Equal(t, ok, true) } func TestWikipageEvent(t *testing.T) { payload := `{ - "object_kind": "wiki_page", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon" - }, - "project": { - "name": "awesome-project", - "description": "This is awesome", - "web_url": "http://example.com/root/awesome-project", - "avatar_url": null, - "git_ssh_url": "git@example.com:root/awesome-project.git", - "git_http_url": "http://example.com/root/awesome-project.git", - "namespace": "root", - "visibility_level": 0, - "path_with_namespace": "root/awesome-project", - "default_branch": "master", - "homepage": "http://example.com/root/awesome-project", - "url": "git@example.com:root/awesome-project.git", - "ssh_url": "git@example.com:root/awesome-project.git", - "http_url": "http://example.com/root/awesome-project.git" - }, - "wiki": { - "web_url": "http://example.com/root/awesome-project/wikis/home", - "git_ssh_url": "git@example.com:root/awesome-project.wiki.git", - "git_http_url": "http://example.com/root/awesome-project.wiki.git", - "path_with_namespace": "root/awesome-project.wiki", - "default_branch": "master" - }, - "object_attributes": { - "title": "Awesome", - "content": "awesome content goes here", - "format": "markdown", - "message": "adding an awesome page to the wiki", - "slug": "awesome", - "url": "http://example.com/root/awesome-project/wikis/awesome", - "action": "create" - } + "object_kind": "wiki_page", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon" + }, + "project": { + "name": "awesome-project", + "description": "This is awesome", + "web_url": "http://example.com/root/awesome-project", + "avatar_url": null, + "git_ssh_url": "git@example.com:root/awesome-project.git", + "git_http_url": "http://example.com/root/awesome-project.git", + "namespace": "root", + "visibility_level": 0, + "path_with_namespace": "root/awesome-project", + "default_branch": "master", + "homepage": "http://example.com/root/awesome-project", + "url": "git@example.com:root/awesome-project.git", + "ssh_url": "git@example.com:root/awesome-project.git", + "http_url": "http://example.com/root/awesome-project.git" + }, + "wiki": { + "web_url": "http://example.com/root/awesome-project/wikis/home", + "git_ssh_url": "git@example.com:root/awesome-project.wiki.git", + "git_http_url": "http://example.com/root/awesome-project.wiki.git", + "path_with_namespace": "root/awesome-project.wiki", + "default_branch": "master" + }, + "object_attributes": { + "title": "Awesome", + "content": "awesome content goes here", + "format": "markdown", + "message": "adding an awesome page to the wiki", + "slug": "awesome", + "url": "http://example.com/root/awesome-project/wikis/awesome", + "action": "create" + } } ` - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/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, WikiPageEvents) + }) + 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-Gitlab-Event", "Wiki Page Hook") req.Header.Set("X-Gitlab-Token", "sampleToken!") @@ -1009,170 +1104,178 @@ func TestWikipageEvent(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.(WikiPageEventPayload) + Equal(t, ok, true) } func TestPipelineEvent(t *testing.T) { payload := `{ - "object_kind": "pipeline", - "object_attributes":{ - "id": 31, - "ref": "master", - "tag": false, - "sha": "bcbb5ec396a2c0f828686f14fac9b80b780504f2", - "before_sha": "bcbb5ec396a2c0f828686f14fac9b80b780504f2", - "status": "success", - "stages":[ - "build", - "test", - "deploy" - ], - "created_at": "2016-08-12 15:23:28 UTC", - "finished_at": "2016-08-12 15:26:29 UTC", - "duration": 63 - }, - "user":{ - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" - }, - "project":{ - "name": "Gitlab Test", - "description": "Atque in sunt eos similique dolores voluptatem.", - "web_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test", - "avatar_url": null, - "git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git", - "git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git", - "namespace": "Gitlab Org", - "visibility_level": 20, - "path_with_namespace": "gitlab-org/gitlab-test", - "default_branch": "master" - }, - "commit":{ - "id": "bcbb5ec396a2c0f828686f14fac9b80b780504f2", - "message": "test\n", - "timestamp": "2016-08-12T17:23:21+02:00", - "url": "http://example.com/gitlab-org/gitlab-test/commit/bcbb5ec396a2c0f828686f14fac9b80b780504f2", - "author":{ - "name": "User", - "email": "user@gitlab.com" - } - }, - "builds":[ - { - "id": 380, - "stage": "deploy", - "name": "production", - "status": "skipped", - "created_at": "2016-08-12 15:23:28 UTC", - "started_at": null, - "finished_at": null, - "when": "manual", - "manual": true, - "user":{ - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" - }, - "runner": null, - "artifacts_file":{ - "filename": null, - "size": null - } - }, - { - "id": 377, - "stage": "test", - "name": "test-image", - "status": "success", - "created_at": "2016-08-12 15:23:28 UTC", - "started_at": "2016-08-12 15:26:12 UTC", - "finished_at": null, - "when": "on_success", - "manual": false, - "user":{ - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" - }, - "runner": null, - "artifacts_file":{ - "filename": null, - "size": null - } - }, - { - "id": 378, - "stage": "test", - "name": "test-build", - "status": "success", - "created_at": "2016-08-12 15:23:28 UTC", - "started_at": "2016-08-12 15:26:12 UTC", - "finished_at": "2016-08-12 15:26:29 UTC", - "when": "on_success", - "manual": false, - "user":{ - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" - }, - "runner": null, - "artifacts_file":{ - "filename": null, - "size": null - } - }, - { - "id": 376, - "stage": "build", - "name": "build-image", - "status": "success", - "created_at": "2016-08-12 15:23:28 UTC", - "started_at": "2016-08-12 15:24:56 UTC", - "finished_at": "2016-08-12 15:25:26 UTC", - "when": "on_success", - "manual": false, - "user":{ - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" - }, - "runner": null, - "artifacts_file":{ - "filename": null, - "size": null - } - }, - { - "id": 379, - "stage": "deploy", - "name": "staging", - "status": "created", - "created_at": "2016-08-12 15:23:28 UTC", - "started_at": null, - "finished_at": null, - "when": "on_success", - "manual": false, - "user":{ - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" - }, - "runner": null, - "artifacts_file":{ - "filename": null, - "size": null - } - } - ] + "object_kind": "pipeline", + "object_attributes":{ + "id": 31, + "ref": "master", + "tag": false, + "sha": "bcbb5ec396a2c0f828686f14fac9b80b780504f2", + "before_sha": "bcbb5ec396a2c0f828686f14fac9b80b780504f2", + "status": "success", + "stages":[ + "build", + "test", + "deploy" + ], + "created_at": "2016-08-12 15:23:28 UTC", + "finished_at": "2016-08-12 15:26:29 UTC", + "duration": 63 + }, + "user":{ + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" + }, + "project":{ + "name": "Gitlab Test", + "description": "Atque in sunt eos similique dolores voluptatem.", + "web_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test", + "avatar_url": null, + "git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git", + "git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git", + "namespace": "Gitlab Org", + "visibility_level": 20, + "path_with_namespace": "gitlab-org/gitlab-test", + "default_branch": "master" + }, + "commit":{ + "id": "bcbb5ec396a2c0f828686f14fac9b80b780504f2", + "message": "test\n", + "timestamp": "2016-08-12T17:23:21+02:00", + "url": "http://example.com/gitlab-org/gitlab-test/commit/bcbb5ec396a2c0f828686f14fac9b80b780504f2", + "author":{ + "name": "User", + "email": "user@gitlab.com" + } + }, + "builds":[ + { + "id": 380, + "stage": "deploy", + "name": "production", + "status": "skipped", + "created_at": "2016-08-12 15:23:28 UTC", + "started_at": null, + "finished_at": null, + "when": "manual", + "manual": true, + "user":{ + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" + }, + "runner": null, + "artifacts_file":{ + "filename": null, + "size": null + } + }, + { + "id": 377, + "stage": "test", + "name": "test-image", + "status": "success", + "created_at": "2016-08-12 15:23:28 UTC", + "started_at": "2016-08-12 15:26:12 UTC", + "finished_at": null, + "when": "on_success", + "manual": false, + "user":{ + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" + }, + "runner": null, + "artifacts_file":{ + "filename": null, + "size": null + } + }, + { + "id": 378, + "stage": "test", + "name": "test-build", + "status": "success", + "created_at": "2016-08-12 15:23:28 UTC", + "started_at": "2016-08-12 15:26:12 UTC", + "finished_at": "2016-08-12 15:26:29 UTC", + "when": "on_success", + "manual": false, + "user":{ + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" + }, + "runner": null, + "artifacts_file":{ + "filename": null, + "size": null + } + }, + { + "id": 376, + "stage": "build", + "name": "build-image", + "status": "success", + "created_at": "2016-08-12 15:23:28 UTC", + "started_at": "2016-08-12 15:24:56 UTC", + "finished_at": "2016-08-12 15:25:26 UTC", + "when": "on_success", + "manual": false, + "user":{ + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" + }, + "runner": null, + "artifacts_file":{ + "filename": null, + "size": null + } + }, + { + "id": 379, + "stage": "deploy", + "name": "staging", + "status": "created", + "created_at": "2016-08-12 15:23:28 UTC", + "started_at": null, + "finished_at": null, + "when": "on_success", + "manual": false, + "user":{ + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" + }, + "runner": null, + "artifacts_file":{ + "filename": null, + "size": null + } + } + ] } ` - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/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, PipelineEvents) + }) + 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-Gitlab-Event", "Pipeline Hook") req.Header.Set("X-Gitlab-Token", "sampleToken!") @@ -1182,59 +1285,67 @@ func TestPipelineEvent(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.(PipelineEventPayload) + Equal(t, ok, true) } func TestBuildEvent(t *testing.T) { payload := `{ - "object_kind": "build", - "ref": "gitlab-script-trigger", - "tag": false, - "before_sha": "2293ada6b400935a1378653304eaf6221e0fdb8f", - "sha": "2293ada6b400935a1378653304eaf6221e0fdb8f", - "build_id": 1977, - "build_name": "test", - "build_stage": "test", - "build_status": "created", - "build_started_at": null, - "build_finished_at": null, - "build_duration": null, - "build_allow_failure": false, - "project_id": 380, - "project_name": "gitlab-org/gitlab-test", - "user": { - "id": 3, - "name": "User", - "email": "user@gitlab.com" - }, - "commit": { - "id": 2366, - "sha": "2293ada6b400935a1378653304eaf6221e0fdb8f", - "message": "test\n", - "author_name": "User", - "author_email": "user@gitlab.com", - "status": "created", - "duration": null, - "started_at": null, - "finished_at": null - }, - "repository": { - "name": "gitlab_test", - "git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git", - "description": "Atque in sunt eos similique dolores voluptatem.", - "homepage": "http://192.168.64.1:3005/gitlab-org/gitlab-test", - "git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git", - "git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git", - "visibility_level": 20 - } + "object_kind": "build", + "ref": "gitlab-script-trigger", + "tag": false, + "before_sha": "2293ada6b400935a1378653304eaf6221e0fdb8f", + "sha": "2293ada6b400935a1378653304eaf6221e0fdb8f", + "build_id": 1977, + "build_name": "test", + "build_stage": "test", + "build_status": "created", + "build_started_at": null, + "build_finished_at": null, + "build_duration": null, + "build_allow_failure": false, + "project_id": 380, + "project_name": "gitlab-org/gitlab-test", + "user": { + "id": 3, + "name": "User", + "email": "user@gitlab.com" + }, + "commit": { + "id": 2366, + "sha": "2293ada6b400935a1378653304eaf6221e0fdb8f", + "message": "test\n", + "author_name": "User", + "author_email": "user@gitlab.com", + "status": "created", + "duration": null, + "started_at": null, + "finished_at": null + }, + "repository": { + "name": "gitlab_test", + "git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git", + "description": "Atque in sunt eos similique dolores voluptatem.", + "homepage": "http://192.168.64.1:3005/gitlab-org/gitlab-test", + "git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git", + "git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git", + "visibility_level": 20 + } } ` - req, err := http.NewRequest("POST", "http://127.0.0.1:3011/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, BuildEvents) + }) + 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-Gitlab-Event", "Build Hook") req.Header.Set("X-Gitlab-Token", "sampleToken!") @@ -1244,8 +1355,8 @@ func TestBuildEvent(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.(BuildEventPayload) + Equal(t, ok, true) } diff --git a/gitlab/payload.go b/gitlab/payload.go index bec1afc..86eaebc 100644 --- a/gitlab/payload.go +++ b/gitlab/payload.go @@ -427,14 +427,14 @@ type LabelChanges struct { // Label contains all of the GitLab label information type Label struct { - Id int64 `json:"id"` + ID int64 `json:"id"` Title string `json:"title"` Color string `json:"color"` - ProjectId int64 `json:"project_id"` + ProjectID int64 `json:"project_id"` CreatedAt customTime `json:"created_at"` UpdatedAt customTime `json:"updated_at"` Template bool `json:"template"` Description string `json:"description"` Type string `json:"type"` - GroupId int64 `json:"group_id"` + GroupID int64 `json:"group_id"` } diff --git a/webhooks_test.go b/webhooks_test.go index fed998b..e42b38f 100644 --- a/webhooks_test.go +++ b/webhooks_test.go @@ -1,280 +1,281 @@ package webhooks -import ( - "bytes" - "crypto/tls" - "net/http" - "os" - "testing" - "time" - - "net/http/httptest" - - . "gopkg.in/go-playground/assert.v1" -) - -// NOTES: -// - Run "go test" to run tests -// - Run "gocov test | gocov report" to report on test converage by file -// - Run "gocov test | gocov annotate -" to report on all code and functions, those ,marked with "MISS" were never called // -// or +//import ( +// "bytes" +// "crypto/tls" +// "net/http" +// "os" +// "testing" +// "time" // -// -- may be a good idea to change to output path to somewherelike /tmp -// go test -coverprofile cover.out && go tool cover -html=cover.out -o cover.html +// "net/http/httptest" // - -type FakeWebhook struct { - provider Provider -} - -func (fhook FakeWebhook) Provider() Provider { - return fhook.provider -} - -func (fhook FakeWebhook) ParsePayload(w http.ResponseWriter, r *http.Request) { -} - -var fakeHook Webhook - -func TestMain(m *testing.M) { - - // setup - fakeHook = &FakeWebhook{ - provider: GitHub, - } - - os.Exit(m.Run()) - - // teardown -} - -func TestHandler(t *testing.T) { - - mux := http.NewServeMux() - mux.Handle("/webhooks", Handler(fakeHook)) - - s := httptest.NewServer(Handler(fakeHook)) - defer s.Close() - - payload := "{}" - - req, err := http.NewRequest("POST", s.URL+"/webhooks", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - - 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) - - // Test BAD METHOD - req, err = http.NewRequest("GET", s.URL+"/webhooks", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - - Equal(t, err, nil) - - resp, err = client.Do(req) - Equal(t, err, nil) - - defer resp.Body.Close() - - Equal(t, resp.StatusCode, http.StatusMethodNotAllowed) -} - -func TestRun(t *testing.T) { - - go Run(fakeHook, "127.0.0.1:3006", "/webhooks") - time.Sleep(5000) - - payload := "{}" - - req, err := http.NewRequest("POST", "http://127.0.0.1:3006/webhooks", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - - 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) - - // While HTTP Server is running test some bad input - - // Test BAD URL - req, err = http.NewRequest("POST", "http://127.0.0.1:3006", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - - Equal(t, err, nil) - - resp, err = client.Do(req) - Equal(t, err, nil) - - defer resp.Body.Close() - - Equal(t, resp.StatusCode, http.StatusNotFound) - - // Test BAD METHOD - req, err = http.NewRequest("GET", "http://127.0.0.1:3006/webhooks", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - - Equal(t, err, nil) - - resp, err = client.Do(req) - Equal(t, err, nil) - - defer resp.Body.Close() - - Equal(t, resp.StatusCode, http.StatusMethodNotAllowed) -} - -func TestRunServer(t *testing.T) { - DefaultLog = NewLogger(true) - server := &http.Server{Addr: "127.0.0.1:3007", Handler: nil} - go RunServer(server, fakeHook, "/webhooks") - time.Sleep(5000) - - payload := "{}" - - req, err := http.NewRequest("POST", "http://127.0.0.1:3007/webhooks", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - - 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) - - // While HTTP Server is running test some bad input - - // Test BAD URL - req, err = http.NewRequest("POST", "http://127.0.0.1:3007", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - - Equal(t, err, nil) - - resp, err = client.Do(req) - Equal(t, err, nil) - - defer resp.Body.Close() - - Equal(t, resp.StatusCode, http.StatusNotFound) - - // Test BAD METHOD - req, err = http.NewRequest("GET", "http://127.0.0.1:3007/webhooks", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - - Equal(t, err, nil) - - resp, err = client.Do(req) - Equal(t, err, nil) - - defer resp.Body.Close() - - Equal(t, resp.StatusCode, http.StatusMethodNotAllowed) -} - -func TestRunTLSServer(t *testing.T) { - - var err error - - // can have certificates in static variables or load from disk - cert := `-----BEGIN CERTIFICATE----- -MIIB0zCCAX2gAwIBAgIJAI/M7BYjwB+uMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV -BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX -aWRnaXRzIFB0eSBMdGQwHhcNMTIwOTEyMjE1MjAyWhcNMTUwOTEyMjE1MjAyWjBF -MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50 -ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANLJ -hPHhITqQbPklG3ibCVxwGMRfp/v4XqhfdQHdcVfHap6NQ5Wok/4xIA+ui35/MmNa -rtNuC+BdZ1tMuVCPFZcCAwEAAaNQME4wHQYDVR0OBBYEFJvKs8RfJaXTH08W+SGv -zQyKn0H8MB8GA1UdIwQYMBaAFJvKs8RfJaXTH08W+SGvzQyKn0H8MAwGA1UdEwQF -MAMBAf8wDQYJKoZIhvcNAQEFBQADQQBJlffJHybjDGxRMqaRmDhX0+6v02TUKZsW -r5QuVbpQhH6u+0UgcW0jp9QwpxoPTLTWGXEWBBBurxFwiCBhkQ+V ------END CERTIFICATE----- - ` - key := `-----BEGIN RSA PRIVATE KEY----- -MIIBOwIBAAJBANLJhPHhITqQbPklG3ibCVxwGMRfp/v4XqhfdQHdcVfHap6NQ5Wo -k/4xIA+ui35/MmNartNuC+BdZ1tMuVCPFZcCAwEAAQJAEJ2N+zsR0Xn8/Q6twa4G -6OB1M1WO+k+ztnX/1SvNeWu8D6GImtupLTYgjZcHufykj09jiHmjHx8u8ZZB/o1N -MQIhAPW+eyZo7ay3lMz1V01WVjNKK9QSn1MJlb06h/LuYv9FAiEA25WPedKgVyCW -SmUwbPw8fnTcpqDWE3yTO3vKcebqMSsCIBF3UmVue8YU3jybC3NxuXq3wNm34R8T -xVLHwDXh/6NJAiEAl2oHGGLz64BuAfjKrqwz7qMYr9HCLIe/YsoWq/olzScCIQDi -D2lWusoe2/nEqfDVVWGWlyJ7yOmqaVm/iNUN9B2N2g== ------END RSA PRIVATE KEY----- -` - - server := &http.Server{Addr: "127.0.0.1:3008", Handler: nil, TLSConfig: &tls.Config{}} - server.TLSConfig.Certificates = make([]tls.Certificate, 1) - - server.TLSConfig.Certificates[0], err = tls.X509KeyPair([]byte(cert), []byte(key)) - Equal(t, err, nil) - - go RunTLSServer(server, fakeHook, "/webhooks") - time.Sleep(5000) - - payload := "{}" - - req, err := http.NewRequest("POST", "https://127.0.0.1:3008/webhooks", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - - Equal(t, err, nil) - - tr := &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - } - - client := &http.Client{Transport: tr} - resp, err := client.Do(req) - Equal(t, err, nil) - - defer resp.Body.Close() - - Equal(t, resp.StatusCode, http.StatusOK) - - // While HTTP Server is running test some bad input - - // Test BAD URL - req, err = http.NewRequest("POST", "https://127.0.0.1:3008", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - - Equal(t, err, nil) - - resp, err = client.Do(req) - Equal(t, err, nil) - - defer resp.Body.Close() - - Equal(t, resp.StatusCode, http.StatusNotFound) - - // Test BAD METHOD - req, err = http.NewRequest("GET", "https://127.0.0.1:3008/webhooks", bytes.NewBuffer([]byte(payload))) - req.Header.Set("Content-Type", "application/json") - - Equal(t, err, nil) - - resp, err = client.Do(req) - Equal(t, err, nil) - - defer resp.Body.Close() - - Equal(t, resp.StatusCode, http.StatusMethodNotAllowed) -} - -func TestProviderString(t *testing.T) { - - Equal(t, GitHub.String(), "GitHub") - Equal(t, Bitbucket.String(), "Bitbucket") - Equal(t, GitLab.String(), "GitLab") - Equal(t, Provider(999999).String(), "Unknown") -} +// . "gopkg.in/go-playground/assert.v1" +//) +// +//// NOTES: +//// - Run "go test" to run tests +//// - Run "gocov test | gocov report" to report on test converage by file +//// - Run "gocov test | gocov annotate -" to report on all code and functions, those ,marked with "MISS" were never called +//// +//// or +//// +//// -- may be a good idea to change to output path to somewherelike /tmp +//// go test -coverprofile cover.out && go tool cover -html=cover.out -o cover.html +//// +// +//type FakeWebhook struct { +// provider Provider +//} +// +//func (fhook FakeWebhook) Provider() Provider { +// return fhook.provider +//} +// +//func (fhook FakeWebhook) ParsePayload(w http.ResponseWriter, r *http.Request) { +//} +// +//var fakeHook Webhook +// +//func TestMain(m *testing.M) { +// +// // setup +// fakeHook = &FakeWebhook{ +// provider: GitHub, +// } +// +// os.Exit(m.Run()) +// +// // teardown +//} +// +//func TestHandler(t *testing.T) { +// +// mux := http.NewServeMux() +// mux.Handle("/webhooks", Handler(fakeHook)) +// +// s := httptest.NewServer(Handler(fakeHook)) +// defer s.Close() +// +// payload := "{}" +// +// req, err := http.NewRequest("POST", s.URL+"/webhooks", bytes.NewBuffer([]byte(payload))) +// req.Header.Set("Content-Type", "application/json") +// +// 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) +// +// // Test BAD METHOD +// req, err = http.NewRequest("GET", s.URL+"/webhooks", bytes.NewBuffer([]byte(payload))) +// req.Header.Set("Content-Type", "application/json") +// +// Equal(t, err, nil) +// +// resp, err = client.Do(req) +// Equal(t, err, nil) +// +// defer resp.Body.Close() +// +// Equal(t, resp.StatusCode, http.StatusMethodNotAllowed) +//} +// +//func TestRun(t *testing.T) { +// +// go Run(fakeHook, "127.0.0.1:3006", "/webhooks") +// time.Sleep(5000) +// +// payload := "{}" +// +// req, err := http.NewRequest("POST", "http://127.0.0.1:3006/webhooks", bytes.NewBuffer([]byte(payload))) +// req.Header.Set("Content-Type", "application/json") +// +// 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) +// +// // While HTTP Server is running test some bad input +// +// // Test BAD URL +// req, err = http.NewRequest("POST", "http://127.0.0.1:3006", bytes.NewBuffer([]byte(payload))) +// req.Header.Set("Content-Type", "application/json") +// +// Equal(t, err, nil) +// +// resp, err = client.Do(req) +// Equal(t, err, nil) +// +// defer resp.Body.Close() +// +// Equal(t, resp.StatusCode, http.StatusNotFound) +// +// // Test BAD METHOD +// req, err = http.NewRequest("GET", "http://127.0.0.1:3006/webhooks", bytes.NewBuffer([]byte(payload))) +// req.Header.Set("Content-Type", "application/json") +// +// Equal(t, err, nil) +// +// resp, err = client.Do(req) +// Equal(t, err, nil) +// +// defer resp.Body.Close() +// +// Equal(t, resp.StatusCode, http.StatusMethodNotAllowed) +//} +// +//func TestRunServer(t *testing.T) { +// DefaultLog = NewLogger(true) +// server := &http.Server{Addr: "127.0.0.1:3007", Handler: nil} +// go RunServer(server, fakeHook, "/webhooks") +// time.Sleep(5000) +// +// payload := "{}" +// +// req, err := http.NewRequest("POST", "http://127.0.0.1:3007/webhooks", bytes.NewBuffer([]byte(payload))) +// req.Header.Set("Content-Type", "application/json") +// +// 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) +// +// // While HTTP Server is running test some bad input +// +// // Test BAD URL +// req, err = http.NewRequest("POST", "http://127.0.0.1:3007", bytes.NewBuffer([]byte(payload))) +// req.Header.Set("Content-Type", "application/json") +// +// Equal(t, err, nil) +// +// resp, err = client.Do(req) +// Equal(t, err, nil) +// +// defer resp.Body.Close() +// +// Equal(t, resp.StatusCode, http.StatusNotFound) +// +// // Test BAD METHOD +// req, err = http.NewRequest("GET", "http://127.0.0.1:3007/webhooks", bytes.NewBuffer([]byte(payload))) +// req.Header.Set("Content-Type", "application/json") +// +// Equal(t, err, nil) +// +// resp, err = client.Do(req) +// Equal(t, err, nil) +// +// defer resp.Body.Close() +// +// Equal(t, resp.StatusCode, http.StatusMethodNotAllowed) +//} +// +//func TestRunTLSServer(t *testing.T) { +// +// var err error +// +// // can have certificates in static variables or load from disk +// cert := `-----BEGIN CERTIFICATE----- +//MIIB0zCCAX2gAwIBAgIJAI/M7BYjwB+uMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV +//BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX +//aWRnaXRzIFB0eSBMdGQwHhcNMTIwOTEyMjE1MjAyWhcNMTUwOTEyMjE1MjAyWjBF +//MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50 +//ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANLJ +//hPHhITqQbPklG3ibCVxwGMRfp/v4XqhfdQHdcVfHap6NQ5Wok/4xIA+ui35/MmNa +//rtNuC+BdZ1tMuVCPFZcCAwEAAaNQME4wHQYDVR0OBBYEFJvKs8RfJaXTH08W+SGv +//zQyKn0H8MB8GA1UdIwQYMBaAFJvKs8RfJaXTH08W+SGvzQyKn0H8MAwGA1UdEwQF +//MAMBAf8wDQYJKoZIhvcNAQEFBQADQQBJlffJHybjDGxRMqaRmDhX0+6v02TUKZsW +//r5QuVbpQhH6u+0UgcW0jp9QwpxoPTLTWGXEWBBBurxFwiCBhkQ+V +//-----END CERTIFICATE----- +// ` +// key := `-----BEGIN RSA PRIVATE KEY----- +//MIIBOwIBAAJBANLJhPHhITqQbPklG3ibCVxwGMRfp/v4XqhfdQHdcVfHap6NQ5Wo +//k/4xIA+ui35/MmNartNuC+BdZ1tMuVCPFZcCAwEAAQJAEJ2N+zsR0Xn8/Q6twa4G +//6OB1M1WO+k+ztnX/1SvNeWu8D6GImtupLTYgjZcHufykj09jiHmjHx8u8ZZB/o1N +//MQIhAPW+eyZo7ay3lMz1V01WVjNKK9QSn1MJlb06h/LuYv9FAiEA25WPedKgVyCW +//SmUwbPw8fnTcpqDWE3yTO3vKcebqMSsCIBF3UmVue8YU3jybC3NxuXq3wNm34R8T +//xVLHwDXh/6NJAiEAl2oHGGLz64BuAfjKrqwz7qMYr9HCLIe/YsoWq/olzScCIQDi +//D2lWusoe2/nEqfDVVWGWlyJ7yOmqaVm/iNUN9B2N2g== +//-----END RSA PRIVATE KEY----- +//` +// +// server := &http.Server{Addr: "127.0.0.1:3008", Handler: nil, TLSConfig: &tls.Config{}} +// server.TLSConfig.Certificates = make([]tls.Certificate, 1) +// +// server.TLSConfig.Certificates[0], err = tls.X509KeyPair([]byte(cert), []byte(key)) +// Equal(t, err, nil) +// +// go RunTLSServer(server, fakeHook, "/webhooks") +// time.Sleep(5000) +// +// payload := "{}" +// +// req, err := http.NewRequest("POST", "https://127.0.0.1:3008/webhooks", bytes.NewBuffer([]byte(payload))) +// req.Header.Set("Content-Type", "application/json") +// +// Equal(t, err, nil) +// +// tr := &http.Transport{ +// TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, +// } +// +// client := &http.Client{Transport: tr} +// resp, err := client.Do(req) +// Equal(t, err, nil) +// +// defer resp.Body.Close() +// +// Equal(t, resp.StatusCode, http.StatusOK) +// +// // While HTTP Server is running test some bad input +// +// // Test BAD URL +// req, err = http.NewRequest("POST", "https://127.0.0.1:3008", bytes.NewBuffer([]byte(payload))) +// req.Header.Set("Content-Type", "application/json") +// +// Equal(t, err, nil) +// +// resp, err = client.Do(req) +// Equal(t, err, nil) +// +// defer resp.Body.Close() +// +// Equal(t, resp.StatusCode, http.StatusNotFound) +// +// // Test BAD METHOD +// req, err = http.NewRequest("GET", "https://127.0.0.1:3008/webhooks", bytes.NewBuffer([]byte(payload))) +// req.Header.Set("Content-Type", "application/json") +// +// Equal(t, err, nil) +// +// resp, err = client.Do(req) +// Equal(t, err, nil) +// +// defer resp.Body.Close() +// +// Equal(t, resp.StatusCode, http.StatusMethodNotAllowed) +//} +// +//func TestProviderString(t *testing.T) { +// +// Equal(t, GitHub.String(), "GitHub") +// Equal(t, Bitbucket.String(), "Bitbucket") +// Equal(t, GitLab.String(), "GitLab") +// Equal(t, Provider(999999).String(), "Unknown") +//}