From b3c683514afe8b6620e5659e6d7053590ec8afe4 Mon Sep 17 00:00:00 2001 From: Minh-Quan TRAN Date: Sun, 13 Oct 2019 00:42:51 +0200 Subject: [PATCH 1/2] add system hook events Signed-off-by: Minh-Quan TRAN --- event_parsing.go | 87 ++ event_parsing_systemhook_test.go | 201 +++ event_parsing_test.go | 1278 ----------------- event_parsing_webhook_test.go | 377 +++++ event_systemhook_types.go | 132 ++ event_types_test.go | 757 ---------- event_types.go => event_webhook_types.go | 0 event_webhook_types_test.go | 191 +++ gitlab_test.go | 10 + testdata/systemhooks/group_create.json | 10 + testdata/systemhooks/group_destroy.json | 10 + testdata/systemhooks/group_rename.json | 13 + testdata/systemhooks/key_create.json | 8 + testdata/systemhooks/key_destroy.json | 8 + testdata/systemhooks/merge_request.json | 114 ++ testdata/systemhooks/project_create.json | 12 + testdata/systemhooks/project_destroy.json | 12 + testdata/systemhooks/project_rename.json | 13 + testdata/systemhooks/project_transfer.json | 13 + testdata/systemhooks/project_update.json | 12 + testdata/systemhooks/push.json | 50 + testdata/systemhooks/repository_update.json | 32 + testdata/systemhooks/tag_push.json | 38 + testdata/systemhooks/user_add_to_group.json | 13 + testdata/systemhooks/user_add_to_team.json | 15 + testdata/systemhooks/user_create.json | 9 + testdata/systemhooks/user_destroy.json | 9 + testdata/systemhooks/user_failed_login.json | 10 + .../systemhooks/user_remove_from_group.json | 13 + .../systemhooks/user_remove_from_team.json | 15 + testdata/systemhooks/user_rename.json | 10 + .../systemhooks/user_update_for_group.json | 13 + .../systemhooks/user_update_for_team.json | 15 + testdata/webhooks/build.json | 42 + testdata/webhooks/group_merge_request.json | 113 ++ testdata/webhooks/issue.json | 107 ++ testdata/webhooks/merge_request.json | 146 ++ testdata/webhooks/note_commit.json | 67 + testdata/webhooks/note_issue.json | 64 + testdata/webhooks/note_merge_request.json | 114 ++ testdata/webhooks/note_snippet.json | 61 + testdata/webhooks/pipeline.json | 175 +++ testdata/webhooks/push.json | 68 + testdata/webhooks/tag_push.json | 39 + testdata/webhooks/wiki_page.json | 41 + 45 files changed, 2502 insertions(+), 2035 deletions(-) create mode 100644 event_parsing_systemhook_test.go delete mode 100644 event_parsing_test.go create mode 100644 event_parsing_webhook_test.go create mode 100644 event_systemhook_types.go delete mode 100644 event_types_test.go rename event_types.go => event_webhook_types.go (100%) create mode 100644 event_webhook_types_test.go create mode 100644 testdata/systemhooks/group_create.json create mode 100644 testdata/systemhooks/group_destroy.json create mode 100644 testdata/systemhooks/group_rename.json create mode 100644 testdata/systemhooks/key_create.json create mode 100644 testdata/systemhooks/key_destroy.json create mode 100644 testdata/systemhooks/merge_request.json create mode 100644 testdata/systemhooks/project_create.json create mode 100644 testdata/systemhooks/project_destroy.json create mode 100644 testdata/systemhooks/project_rename.json create mode 100644 testdata/systemhooks/project_transfer.json create mode 100644 testdata/systemhooks/project_update.json create mode 100644 testdata/systemhooks/push.json create mode 100644 testdata/systemhooks/repository_update.json create mode 100644 testdata/systemhooks/tag_push.json create mode 100644 testdata/systemhooks/user_add_to_group.json create mode 100644 testdata/systemhooks/user_add_to_team.json create mode 100644 testdata/systemhooks/user_create.json create mode 100644 testdata/systemhooks/user_destroy.json create mode 100644 testdata/systemhooks/user_failed_login.json create mode 100644 testdata/systemhooks/user_remove_from_group.json create mode 100644 testdata/systemhooks/user_remove_from_team.json create mode 100644 testdata/systemhooks/user_rename.json create mode 100644 testdata/systemhooks/user_update_for_group.json create mode 100644 testdata/systemhooks/user_update_for_team.json create mode 100644 testdata/webhooks/build.json create mode 100644 testdata/webhooks/group_merge_request.json create mode 100644 testdata/webhooks/issue.json create mode 100644 testdata/webhooks/merge_request.json create mode 100644 testdata/webhooks/note_commit.json create mode 100644 testdata/webhooks/note_issue.json create mode 100644 testdata/webhooks/note_merge_request.json create mode 100644 testdata/webhooks/note_snippet.json create mode 100644 testdata/webhooks/pipeline.json create mode 100644 testdata/webhooks/push.json create mode 100644 testdata/webhooks/tag_push.json create mode 100644 testdata/webhooks/wiki_page.json diff --git a/event_parsing.go b/event_parsing.go index 7ac042ae8..548998398 100644 --- a/event_parsing.go +++ b/event_parsing.go @@ -20,6 +20,7 @@ const ( EventTypePush EventType = "Push Hook" EventTypeTagPush EventType = "Tag Push Hook" EventTypeWikiPage EventType = "Wiki Page Hook" + EventSystemHook EventType = "System Hook" ) const ( @@ -115,3 +116,89 @@ func ParseWebhook(eventType EventType, payload []byte) (event interface{}, err e return event, nil } + +// ParseSystemhook parses the System Hook event payload. For recognized event types, a +// value of the corresponding struct type will be returned. An error will +// be returned for unrecognized event types. +func ParseSystemhook(eventType EventType, payload []byte) (event interface{}, err error) { + switch eventType { + case EventSystemHook: + e := &systemHookEvent{} + err := json.Unmarshal(payload, e) + if err != nil { + return nil, err + } + + switch e.EventName { + case "push": + event = &PushSystemHookEvent{} + case "tag_push": + event = &TagPushSystemHookEvent{} + case "repository_update": + event = &RepositoryUpdateSystemHookEvent{} + case "project_create": + fallthrough + case "project_update": + fallthrough + case "project_destroy": + fallthrough + case "project_transfer": + fallthrough + case "project_rename": + event = &ProjectSystemHookEvent{} + case "group_create": + fallthrough + case "group_destroy": + fallthrough + case "group_rename": + event = &GroupSystemHookEvent{} + case "key_create": + fallthrough + case "key_destroy": + event = &KeySystemHookEvent{} + case "user_create": + fallthrough + case "user_destroy": + fallthrough + case "user_rename": + event = &UserSystemHookEvent{} + case "user_add_to_group": + fallthrough + case "user_remove_from_group": + fallthrough + case "user_update_for_group": + event = &UserGroupSystemHookEvent{} + case "user_add_to_team": + fallthrough + case "user_remove_from_team": + fallthrough + case "user_update_for_team": + event = &UserTeamSystemHookEvent{} + default: + switch e.ObjectKind { + case "merge_request": + event = &MergeEvent{} + default: + return nil, fmt.Errorf("unexpected system hook type %s", e.EventName) + } + } + + default: + return nil, fmt.Errorf("unexpected event type: %s", eventType) + } + + if err := json.Unmarshal(payload, event); err != nil { + return nil, err + } + + return event, nil +} + +// ParseHook processes both ParseWebhook & ParseSystemhook +func ParseHook(eventType EventType, payload []byte) (event interface{}, err error) { + if event, err = ParseWebhook(eventType, payload); err != nil { + event, err = ParseSystemhook(eventType, payload) + return + } + return +} diff --git a/event_parsing_systemhook_test.go b/event_parsing_systemhook_test.go new file mode 100644 index 000000000..c70eb930e --- /dev/null +++ b/event_parsing_systemhook_test.go @@ -0,0 +1,201 @@ +package gitlab + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestParseSystemhookPush(t *testing.T) { + payload := loadFixture("testdata/systemhooks/push.json") + + parsedEvent, err := ParseSystemhook("System Hook", payload) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + + event, ok := parsedEvent.(*PushSystemHookEvent) + if !ok { + t.Errorf("Expected PushSystemHookEvent, but parsing produced %T", parsedEvent) + } + assert.Equal(t, "push", event.EventName) +} + +func TestParseSystemhookTagPush(t *testing.T) { + payload := loadFixture("testdata/systemhooks/tag_push.json") + + parsedEvent, err := ParseSystemhook("System Hook", payload) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + + event, ok := parsedEvent.(*TagPushSystemHookEvent) + if !ok { + t.Errorf("Expected TagPushSystemHookEvent, but parsing produced %T", parsedEvent) + } + assert.Equal(t, "tag_push", event.EventName) +} + +func TestParseSystemhookMergeRequest(t *testing.T) { + payload := loadFixture("testdata/systemhooks/merge_request.json") + + parsedEvent, err := ParseSystemhook("System Hook", payload) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + + event, ok := parsedEvent.(*MergeEvent) + if !ok { + t.Errorf("Expected MergeRequestSystemHookEvent, but parsing produced %T", parsedEvent) + } + assert.Equal(t, "merge_request", event.ObjectKind) +} + +func TestParseSystemhookRepositoryUpdate(t *testing.T) { + payload := loadFixture("testdata/systemhooks/repository_update.json") + + parsedEvent, err := ParseSystemhook("System Hook", payload) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + + event, ok := parsedEvent.(*RepositoryUpdateSystemHookEvent) + if !ok { + t.Errorf("Expected RepositoryUpdateSystemHookEvent, but parsing produced %T", parsedEvent) + } + assert.Equal(t, "repository_update", event.EventName) +} + +func TestParseSystemhookProject(t *testing.T) { + var tests = []struct { + event string + payload []byte + }{ + {"project_create", loadFixture("testdata/systemhooks/project_create.json")}, + {"project_update", loadFixture("testdata/systemhooks/project_update.json")}, + {"project_destroy", loadFixture("testdata/systemhooks/project_destroy.json")}, + {"project_transfer", loadFixture("testdata/systemhooks/project_transfer.json")}, + {"project_rename", loadFixture("testdata/systemhooks/project_rename.json")}, + } + for _, tt := range tests { + t.Run(tt.event, func(t *testing.T) { + parsedEvent, err := ParseSystemhook("System Hook", tt.payload) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + event, ok := parsedEvent.(*ProjectSystemHookEvent) + if !ok { + t.Errorf("Expected ProjectSystemHookEvent, but parsing produced %T", parsedEvent) + } + assert.Equal(t, tt.event, event.EventName) + }) + } +} + +func TestParseSystemhookGroup(t *testing.T) { + var tests = []struct { + event string + payload []byte + }{ + {"group_create", loadFixture("testdata/systemhooks/group_create.json")}, + {"group_destroy", loadFixture("testdata/systemhooks/group_destroy.json")}, + {"group_rename", loadFixture("testdata/systemhooks/group_rename.json")}, + } + for _, tt := range tests { + t.Run(tt.event, func(t *testing.T) { + parsedEvent, err := ParseSystemhook("System Hook", tt.payload) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + event, ok := parsedEvent.(*GroupSystemHookEvent) + if !ok { + t.Errorf("Expected GroupSystemHookEvent, but parsing produced %T", parsedEvent) + } + assert.Equal(t, tt.event, event.EventName) + }) + } +} + +func TestParseSystemhookUser(t *testing.T) { + var tests = []struct { + event string + payload []byte + }{ + {"user_create", loadFixture("testdata/systemhooks/user_create.json")}, + {"user_destroy", loadFixture("testdata/systemhooks/user_destroy.json")}, + {"user_rename", loadFixture("testdata/systemhooks/user_rename.json")}, + } + for _, tt := range tests { + t.Run(tt.event, func(t *testing.T) { + parsedEvent, err := ParseSystemhook("System Hook", tt.payload) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + event, ok := parsedEvent.(*UserSystemHookEvent) + if !ok { + t.Errorf("Expected UserSystemHookEvent, but parsing produced %T", parsedEvent) + } + assert.Equal(t, tt.event, event.EventName) + }) + } +} + +func TestParseSystemhookUserGroup(t *testing.T) { + var tests = []struct { + event string + payload []byte + }{ + {"user_add_to_group", loadFixture("testdata/systemhooks/user_add_to_group.json")}, + {"user_remove_from_group", loadFixture("testdata/systemhooks/user_remove_from_group.json")}, + {"user_update_for_group", loadFixture("testdata/systemhooks/user_update_for_group.json")}, + } + for _, tt := range tests { + t.Run(tt.event, func(t *testing.T) { + parsedEvent, err := ParseSystemhook("System Hook", tt.payload) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + event, ok := parsedEvent.(*UserGroupSystemHookEvent) + if !ok { + t.Errorf("Expected UserGroupSystemHookEvent, but parsing produced %T", parsedEvent) + } + assert.Equal(t, tt.event, event.EventName) + }) + } +} + +func TestParseSystemhookUserTeam(t *testing.T) { + var tests = []struct { + event string + payload []byte + }{ + {"user_add_to_team", loadFixture("testdata/systemhooks/user_add_to_team.json")}, + {"user_remove_from_team", loadFixture("testdata/systemhooks/user_remove_from_team.json")}, + {"user_update_for_team", loadFixture("testdata/systemhooks/user_update_for_team.json")}, + } + for _, tt := range tests { + t.Run(tt.event, func(t *testing.T) { + parsedEvent, err := ParseSystemhook("System Hook", tt.payload) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + event, ok := parsedEvent.(*UserTeamSystemHookEvent) + if !ok { + t.Errorf("Expected UserTeamSystemHookEvent, but parsing produced %T", parsedEvent) + } + assert.Equal(t, tt.event, event.EventName) + }) + } +} + +func TestParseHookSystemHook(t *testing.T) { + parsedEvent1, err := ParseHook("System Hook", loadFixture("testdata/systemhooks/merge_request.json")) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + parsedEvent2, err := ParseSystemhook("System Hook", loadFixture("testdata/systemhooks/merge_request.json")) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + assert.Equal(t, parsedEvent1, parsedEvent2) +} diff --git a/event_parsing_test.go b/event_parsing_test.go deleted file mode 100644 index aa2f3c114..000000000 --- a/event_parsing_test.go +++ /dev/null @@ -1,1278 +0,0 @@ -package gitlab - -import ( - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestWebhookEventType(t *testing.T) { - req, err := http.NewRequest(http.MethodGet, "https://gitlab.com", nil) - if err != nil { - t.Errorf("Error creating HTTP request: %s", err) - } - req.Header.Set("X-Gitlab-Event", "Push Hook") - - eventType := WebhookEventType(req) - if eventType != "Push Hook" { - t.Errorf("WebhookEventType is %s, want %s", eventType, "Push Hook") - } -} - -func TestParsePushHook(t *testing.T) { - raw := `{ - "object_kind": "push", - "before": "95790bf891e76fee5e1747ab589903a6a1f80f22", - "after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", - "ref": "refs/heads/master", - "checkout_sha": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", - "user_id": 4, - "user_name": "John Smith", - "user_username": "jsmith", - "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":{ - "id": 15, - "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 -}` - - parsedEvent, err := ParseWebhook("Push Hook", []byte(raw)) - if err != nil { - t.Errorf("Error parsing push hook: %s", err) - } - - event, ok := parsedEvent.(*PushEvent) - if !ok { - t.Errorf("Expected PushEvent, but parsing produced %T", parsedEvent) - } - - if event.ObjectKind != "push" { - t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "push") - } - - if event.ProjectID != 15 { - t.Errorf("ProjectID is %v, want %v", event.ProjectID, 15) - } - - if event.UserName != "John Smith" { - t.Errorf("Username is %s, want %s", event.UserName, "John Smith") - } - - if event.Commits[0] == nil || event.Commits[0].Timestamp == nil { - t.Errorf("Commit Timestamp isn't nil") - } - - if event.Commits[0] == nil || event.Commits[0].Author.Name != "Jordi Mallach" { - t.Errorf("Commit Username is %s, want %s", event.UserName, "Jordi Mallach") - } -} - -func TestParseTagHook(t *testing.T) { - raw := `{ - "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":{ - "id": 1, - "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 -}` - - parsedEvent, err := ParseWebhook("Tag Push Hook", []byte(raw)) - if err != nil { - t.Errorf("Error parsing tag hook: %s", err) - } - - event, ok := parsedEvent.(*TagEvent) - if !ok { - t.Errorf("Expected TagEvent, but parsing produced %T", parsedEvent) - } - - if event.ObjectKind != "tag_push" { - t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "tag_push") - } - - if event.ProjectID != 1 { - t.Errorf("ProjectID is %v, want %v", event.ProjectID, 1) - } - - if event.UserName != "John Smith" { - t.Errorf("Username is %s, want %s", event.UserName, "John Smith") - } - - if event.Ref != "refs/tags/v1.0.0" { - t.Errorf("Ref is %s, want %s", event.Ref, "refs/tags/v1.0.0") - } -} - -func TestParseIssueHook(t *testing.T) { - raw := `{ - "object_kind": "issue", - "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": 301, - "title": "New API: create/update/delete file", - "assignee_ids": [51], - "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" - }, - "assignees": [{ - "name": "User1", - "username": "user1", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - }], - "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": { - "previous": null, - "current": 1 - }, - "updated_at": { - "previous": "2017-09-15 16:50:55 UTC", - "current": "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 - }] - } - } -}` - - parsedEvent, err := ParseWebhook("Issue Hook", []byte(raw)) - if err != nil { - t.Errorf("Error parsing issue hook: %s", err) - } - - event, ok := parsedEvent.(*IssueEvent) - if !ok { - t.Errorf("Expected IssueEvent, but parsing produced %T", parsedEvent) - } - - if event.ObjectKind != "issue" { - t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "issue") - } - - if event.Project.Name != "Gitlab Test" { - t.Errorf("Project name is %v, want %v", event.Project.Name, "Gitlab Test") - } - - if event.ObjectAttributes.State != "opened" { - t.Errorf("Issue state is %v, want %v", event.ObjectAttributes.State, "opened") - } - - if event.Assignee.Username != "user1" { - t.Errorf("Assignee username is %v, want %v", event.Assignee.Username, "user1") - } - assert.Equal(t, 1, len(event.Labels)) - assert.Equal(t, 0, event.Changes.UpdatedByID.Previous) - assert.Equal(t, 1, event.Changes.UpdatedByID.Current) - assert.Equal(t, 1, len(event.Changes.Labels.Previous)) - assert.Equal(t, 1, len(event.Changes.Labels.Current)) -} - -func TestParseCommitCommentHook(t *testing.T) { - raw := `{ - "object_kind": "note", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - }, - "project_id": 5, - "project":{ - "id": 5, - "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" - } - } -}` - - parsedEvent, err := ParseWebhook("Note Hook", []byte(raw)) - if err != nil { - t.Errorf("Error parsing note hook: %s", err) - } - - event, ok := parsedEvent.(*CommitCommentEvent) - if !ok { - t.Errorf("Expected CommitCommentEvent, but parsing produced %T", parsedEvent) - } - - if event.ObjectKind != "note" { - t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "note") - } - - if event.ProjectID != 5 { - t.Errorf("ProjectID is %v, want %v", event.ProjectID, 5) - } - - if event.ObjectAttributes.NoteableType != "Commit" { - t.Errorf("NoteableType is %v, want %v", event.ObjectAttributes.NoteableType, "Commit") - } - - if event.Commit.ID != "cfe32cf61b73a0d5e9f13e774abde7ff789b1660" { - t.Errorf("CommitID is %v, want %v", event.Commit.ID, "cfe32cf61b73a0d5e9f13e774abde7ff789b1660") - } -} - -func TestParseMergeRequestCommentHook(t *testing.T) { - raw := `{ - "object_kind": "note", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - }, - "project_id": 5, - "project":{ - "id": 5, - "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, - "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" - } - } -}` - - parsedEvent, err := ParseWebhook("Note Hook", []byte(raw)) - if err != nil { - t.Errorf("Error parsing note hook: %s", err) - } - - event, ok := parsedEvent.(*MergeCommentEvent) - if !ok { - t.Errorf("Expected MergeCommentEvent, but parsing produced %T", parsedEvent) - } - - if event.ObjectKind != "note" { - t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "note") - } - - if event.ProjectID != 5 { - t.Errorf("ProjectID is %v, want %v", event.ProjectID, 5) - } - - if event.ObjectAttributes.NoteableType != "MergeRequest" { - t.Errorf("NoteableType is %v, want %v", event.ObjectAttributes.NoteableType, "MergeRequest") - } - - if event.MergeRequest.ID != 7 { - t.Errorf("MergeRequest ID is %v, want %v", event.MergeRequest.ID, 7) - } -} - -func TestParseIssueCommentHook(t *testing.T) { - raw := `{ - "object_kind": "note", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - }, - "project_id": 5, - "project":{ - "id": 5, - "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_ids": [], - "assignee_id": null, - "author_id": 1, - "project_id": 5, - "created_at": "2016-01-04T15:31:46.176Z", - "updated_at": "2016-01-04T15:31:46.176Z", - "position": 0, - "branch_name": null, - "description": "test", - "milestone_id": null, - "state": "closed", - "iid": 17 - } -}` - - parsedEvent, err := ParseWebhook("Note Hook", []byte(raw)) - if err != nil { - t.Errorf("Error parsing note hook: %s", err) - } - - event, ok := parsedEvent.(*IssueCommentEvent) - if !ok { - t.Errorf("Expected IssueCommentEvent, but parsing produced %T", parsedEvent) - } - - if event.ObjectKind != "note" { - t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "note") - } - - if event.ProjectID != 5 { - t.Errorf("ProjectID is %v, want %v", event.ProjectID, 5) - } - - if event.ObjectAttributes.NoteableType != "Issue" { - t.Errorf("NoteableType is %v, want %v", event.ObjectAttributes.NoteableType, "Issue") - } - - if event.Issue.Title != "test" { - t.Errorf("Issue title is %v, want %v", event.Issue.Title, "test") - } -} - -func TestParseSnippetCommentHook(t *testing.T) { - raw := `{ - "object_kind": "note", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - }, - "project_id": 5, - "project":{ - "id": 5, - "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": "2016-01-04T15:31:46.176Z", - "updated_at": "2016-01-04T15:31:46.176Z", - "file_name": "test.rb", - "expires_at": null, - "type": "ProjectSnippet", - "visibility_level": 0 - } -}` - - parsedEvent, err := ParseWebhook("Note Hook", []byte(raw)) - if err != nil { - t.Errorf("Error parsing note hook: %s", err) - } - - event, ok := parsedEvent.(*SnippetCommentEvent) - if !ok { - t.Errorf("Expected SnippetCommentEvent, but parsing produced %T", parsedEvent) - } - - if event.ObjectKind != "note" { - t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "note") - } - - if event.ProjectID != 5 { - t.Errorf("ProjectID is %v, want %v", event.ProjectID, 5) - } - - if event.ObjectAttributes.NoteableType != "Snippet" { - t.Errorf("NoteableType is %v, want %v", event.ObjectAttributes.NoteableType, "Snippet") - } - - if event.Snippet.Title != "test" { - t.Errorf("Snippet title is %v, want %v", event.Snippet.Title, "test") - } -} - -func TestParseMergeRequestHook(t *testing.T) { - raw := `{ - "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": { - "previous": null, - "current": 1 - }, - "updated_at": { - "previous": "2017-09-15 16:50:55 UTC", - "current": "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 - }] - } - } -}` - - parsedEvent, err := ParseWebhook("Merge Request Hook", []byte(raw)) - if err != nil { - t.Errorf("Error parsing merge request hook: %s", err) - } - - event, ok := parsedEvent.(*MergeEvent) - if !ok { - t.Errorf("Expected MergeEvent, but parsing produced %T", parsedEvent) - } - - if event.ObjectKind != "merge_request" { - t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "merge_request") - } - - if event.ObjectAttributes.MergeStatus != "unchecked" { - t.Errorf("MergeStatus is %v, want %v", event.ObjectAttributes.MergeStatus, "unchecked") - } - - if event.ObjectAttributes.LastCommit.ID != "da1560886d4f094c3e6c9ef40349f7d38b5d27d7" { - t.Errorf("LastCommit ID is %v, want %v", event.ObjectAttributes.LastCommit.ID, "da1560886d4f094c3e6c9ef40349f7d38b5d27d7") - } - - if event.ObjectAttributes.WorkInProgress { - t.Errorf("WorkInProgress is %v, want %v", event.ObjectAttributes.WorkInProgress, false) - } - assert.Equal(t, 1, len(event.Labels)) - assert.Equal(t, 0, event.Changes.UpdatedByID.Previous) - assert.Equal(t, 1, event.Changes.UpdatedByID.Current) - assert.Equal(t, 1, len(event.Changes.Labels.Previous)) - assert.Equal(t, 1, len(event.Changes.Labels.Current)) -} - -func TestParseWikiPageHook(t *testing.T) { - raw := `{ - "object_kind": "wiki_page", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon" - }, - "project": { - "id": 1, - "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" - } -}` - - parsedEvent, err := ParseWebhook("Wiki Page Hook", []byte(raw)) - if err != nil { - t.Errorf("Error parsing wiki page hook: %s", err) - } - - event, ok := parsedEvent.(*WikiPageEvent) - if !ok { - t.Errorf("Expected WikiPageEvent, but parsing produced %T", parsedEvent) - } - - if event.ObjectKind != "wiki_page" { - t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "wiki_page") - } - - if event.Project.Name != "awesome-project" { - t.Errorf("Project name is %v, want %v", event.Project.Name, "awesome-project") - } - - if event.Wiki.WebURL != "http://example.com/root/awesome-project/wikis/home" { - t.Errorf("Wiki web URL is %v, want %v", event.Wiki.WebURL, "http://example.com/root/awesome-project/wikis/home") - } - - if event.ObjectAttributes.Message != "adding an awesome page to the wiki" { - t.Errorf("Message is %v, want %v", event.ObjectAttributes.Message, "adding an awesome page to the wiki") - } -} - -func TestParsePipelineHook(t *testing.T) { - raw := `{ - "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, - "variables": [ - { - "key": "NESTOR_PROD_ENVIRONMENT", - "value": "us-west-1" - } - ] - }, - "user":{ - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" - }, - "project":{ - "id": 1, - "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": { - "id":380987, - "description":"shared-runners-manager-6.gitlab.com", - "active":true, - "is_shared":true - }, - "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": { - "id":380987, - "description":"shared-runners-manager-6.gitlab.com", - "active":true, - "is_shared":true - }, - "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": { - "id":380987, - "description":"shared-runners-manager-6.gitlab.com", - "active":true, - "is_shared":true - }, - "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 - } - } - ] -}` - - parsedEvent, err := ParseWebhook("Pipeline Hook", []byte(raw)) - if err != nil { - t.Errorf("Error parsing pipeline hook: %s", err) - } - - event, ok := parsedEvent.(*PipelineEvent) - if !ok { - t.Errorf("Expected PipelineEvent, but parsing produced %T", parsedEvent) - } - - if event.ObjectKind != "pipeline" { - t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "pipeline") - } - - if event.ObjectAttributes.Duration != 63 { - t.Errorf("Duration is %v, want %v", event.ObjectAttributes.Duration, 63) - } - - if event.Commit.ID != "bcbb5ec396a2c0f828686f14fac9b80b780504f2" { - t.Errorf("Commit ID is %v, want %v", event.Commit.ID, "bcbb5ec396a2c0f828686f14fac9b80b780504f2") - } - - if event.Builds[0].ID != 380 { - t.Errorf("Builds[0] ID is %v, want %v", event.Builds[0].ID, 380) - } -} - -func TestParseBuildHook(t *testing.T) { - raw := `{ - "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, - "build_failure_reason": "script_failure", - "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", - "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 - } -}` - - parsedEvent, err := ParseWebhook("Build Hook", []byte(raw)) - if err != nil { - t.Errorf("Error parsing build hook: %s", err) - } - - event, ok := parsedEvent.(*BuildEvent) - if !ok { - t.Errorf("Expected BuildEvent, but parsing produced %T", parsedEvent) - } - - if event.ObjectKind != "build" { - t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "build") - } - - if event.BuildID != 1977 { - t.Errorf("BuildID is %v, want %v", event.BuildID, 1977) - } - - if event.BuildAllowFailure { - t.Errorf("BuildAllowFailure is %v, want %v", event.BuildAllowFailure, false) - } - - if event.Commit.SHA != "2293ada6b400935a1378653304eaf6221e0fdb8f" { - t.Errorf("Commit SHA is %v, want %v", event.Commit.SHA, "2293ada6b400935a1378653304eaf6221e0fdb8f") - } -} diff --git a/event_parsing_webhook_test.go b/event_parsing_webhook_test.go new file mode 100644 index 000000000..c833d8842 --- /dev/null +++ b/event_parsing_webhook_test.go @@ -0,0 +1,377 @@ +package gitlab + +import ( + "net/http" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestWebhookEventType(t *testing.T) { + req, err := http.NewRequest(http.MethodGet, "https://gitlab.com", nil) + if err != nil { + t.Errorf("Error creating HTTP request: %s", err) + } + req.Header.Set("X-Gitlab-Event", "Push Hook") + + eventType := WebhookEventType(req) + if eventType != "Push Hook" { + t.Errorf("WebhookEventType is %s, want %s", eventType, "Push Hook") + } +} + +func TestParsePushHook(t *testing.T) { + raw := loadFixture("testdata/webhooks/push.json") + + parsedEvent, err := ParseWebhook("Push Hook", raw) + if err != nil { + t.Errorf("Error parsing push hook: %s", err) + } + + event, ok := parsedEvent.(*PushEvent) + if !ok { + t.Errorf("Expected PushEvent, but parsing produced %T", parsedEvent) + } + + if event.ObjectKind != "push" { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "push") + } + + if event.ProjectID != 15 { + t.Errorf("ProjectID is %v, want %v", event.ProjectID, 15) + } + + if event.UserName != "John Smith" { + t.Errorf("Username is %s, want %s", event.UserName, "John Smith") + } + + if event.Commits[0] == nil || event.Commits[0].Timestamp == nil { + t.Errorf("Commit Timestamp isn't nil") + } + + if event.Commits[0] == nil || event.Commits[0].Author.Name != "Jordi Mallach" { + t.Errorf("Commit Username is %s, want %s", event.UserName, "Jordi Mallach") + } +} + +func TestParseTagHook(t *testing.T) { + raw := loadFixture("testdata/webhooks/tag_push.json") + + parsedEvent, err := ParseWebhook("Tag Push Hook", raw) + if err != nil { + t.Errorf("Error parsing tag hook: %s", err) + } + + event, ok := parsedEvent.(*TagEvent) + if !ok { + t.Errorf("Expected TagEvent, but parsing produced %T", parsedEvent) + } + + if event.ObjectKind != "tag_push" { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "tag_push") + } + + if event.ProjectID != 1 { + t.Errorf("ProjectID is %v, want %v", event.ProjectID, 1) + } + + if event.UserName != "John Smith" { + t.Errorf("Username is %s, want %s", event.UserName, "John Smith") + } + + if event.Ref != "refs/tags/v1.0.0" { + t.Errorf("Ref is %s, want %s", event.Ref, "refs/tags/v1.0.0") + } +} + +func TestParseIssueHook(t *testing.T) { + raw := loadFixture("testdata/webhooks/issue.json") + + parsedEvent, err := ParseWebhook("Issue Hook", raw) + if err != nil { + t.Errorf("Error parsing issue hook: %s", err) + } + + event, ok := parsedEvent.(*IssueEvent) + if !ok { + t.Errorf("Expected IssueEvent, but parsing produced %T", parsedEvent) + } + + if event.ObjectKind != "issue" { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "issue") + } + + if event.Project.Name != "Gitlab Test" { + t.Errorf("Project name is %v, want %v", event.Project.Name, "Gitlab Test") + } + + if event.ObjectAttributes.State != "opened" { + t.Errorf("Issue state is %v, want %v", event.ObjectAttributes.State, "opened") + } + + if event.Assignee.Username != "user1" { + t.Errorf("Assignee username is %v, want %v", event.Assignee.Username, "user1") + } + assert.Equal(t, 1, len(event.Labels)) + assert.Equal(t, 0, event.Changes.UpdatedByID.Previous) + assert.Equal(t, 1, event.Changes.UpdatedByID.Current) + assert.Equal(t, 1, len(event.Changes.Labels.Previous)) + assert.Equal(t, 1, len(event.Changes.Labels.Current)) +} + +func TestParseCommitCommentHook(t *testing.T) { + raw := loadFixture("testdata/webhooks/note_commit.json") + + parsedEvent, err := ParseWebhook("Note Hook", raw) + if err != nil { + t.Errorf("Error parsing note hook: %s", err) + } + + event, ok := parsedEvent.(*CommitCommentEvent) + if !ok { + t.Errorf("Expected CommitCommentEvent, but parsing produced %T", parsedEvent) + } + + if event.ObjectKind != "note" { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "note") + } + + if event.ProjectID != 5 { + t.Errorf("ProjectID is %v, want %v", event.ProjectID, 5) + } + + if event.ObjectAttributes.NoteableType != "Commit" { + t.Errorf("NoteableType is %v, want %v", event.ObjectAttributes.NoteableType, "Commit") + } + + if event.Commit.ID != "cfe32cf61b73a0d5e9f13e774abde7ff789b1660" { + t.Errorf("CommitID is %v, want %v", event.Commit.ID, "cfe32cf61b73a0d5e9f13e774abde7ff789b1660") + } +} + +func TestParseMergeRequestCommentHook(t *testing.T) { + raw := loadFixture("testdata/webhooks/note_merge_request.json") + + parsedEvent, err := ParseWebhook("Note Hook", raw) + if err != nil { + t.Errorf("Error parsing note hook: %s", err) + } + + event, ok := parsedEvent.(*MergeCommentEvent) + if !ok { + t.Errorf("Expected MergeCommentEvent, but parsing produced %T", parsedEvent) + } + + if event.ObjectKind != "note" { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "note") + } + + if event.ProjectID != 5 { + t.Errorf("ProjectID is %v, want %v", event.ProjectID, 5) + } + + if event.ObjectAttributes.NoteableType != "MergeRequest" { + t.Errorf("NoteableType is %v, want %v", event.ObjectAttributes.NoteableType, "MergeRequest") + } + + if event.MergeRequest.ID != 7 { + t.Errorf("MergeRequest ID is %v, want %v", event.MergeRequest.ID, 7) + } +} + +func TestParseIssueCommentHook(t *testing.T) { + raw := loadFixture("testdata/webhooks/note_issue.json") + + parsedEvent, err := ParseWebhook("Note Hook", raw) + if err != nil { + t.Errorf("Error parsing note hook: %s", err) + } + + event, ok := parsedEvent.(*IssueCommentEvent) + if !ok { + t.Errorf("Expected IssueCommentEvent, but parsing produced %T", parsedEvent) + } + + if event.ObjectKind != "note" { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "note") + } + + if event.ProjectID != 5 { + t.Errorf("ProjectID is %v, want %v", event.ProjectID, 5) + } + + if event.ObjectAttributes.NoteableType != "Issue" { + t.Errorf("NoteableType is %v, want %v", event.ObjectAttributes.NoteableType, "Issue") + } + + if event.Issue.Title != "test" { + t.Errorf("Issue title is %v, want %v", event.Issue.Title, "test") + } +} + +func TestParseSnippetCommentHook(t *testing.T) { + raw := loadFixture("testdata/webhooks/note_snippet.json") + + parsedEvent, err := ParseWebhook("Note Hook", raw) + if err != nil { + t.Errorf("Error parsing note hook: %s", err) + } + + event, ok := parsedEvent.(*SnippetCommentEvent) + if !ok { + t.Errorf("Expected SnippetCommentEvent, but parsing produced %T", parsedEvent) + } + + if event.ObjectKind != "note" { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "note") + } + + if event.ProjectID != 5 { + t.Errorf("ProjectID is %v, want %v", event.ProjectID, 5) + } + + if event.ObjectAttributes.NoteableType != "Snippet" { + t.Errorf("NoteableType is %v, want %v", event.ObjectAttributes.NoteableType, "Snippet") + } + + if event.Snippet.Title != "test" { + t.Errorf("Snippet title is %v, want %v", event.Snippet.Title, "test") + } +} + +func TestParseMergeRequestHook(t *testing.T) { + raw := loadFixture("testdata/webhooks/merge_request.json") + + parsedEvent, err := ParseWebhook("Merge Request Hook", raw) + if err != nil { + t.Errorf("Error parsing merge request hook: %s", err) + } + + event, ok := parsedEvent.(*MergeEvent) + if !ok { + t.Errorf("Expected MergeEvent, but parsing produced %T", parsedEvent) + } + + if event.ObjectKind != "merge_request" { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "merge_request") + } + + if event.ObjectAttributes.MergeStatus != "unchecked" { + t.Errorf("MergeStatus is %v, want %v", event.ObjectAttributes.MergeStatus, "unchecked") + } + + if event.ObjectAttributes.LastCommit.ID != "da1560886d4f094c3e6c9ef40349f7d38b5d27d7" { + t.Errorf("LastCommit ID is %v, want %v", event.ObjectAttributes.LastCommit.ID, "da1560886d4f094c3e6c9ef40349f7d38b5d27d7") + } + + if event.ObjectAttributes.WorkInProgress { + t.Errorf("WorkInProgress is %v, want %v", event.ObjectAttributes.WorkInProgress, false) + } + assert.Equal(t, 1, len(event.Labels)) + assert.Equal(t, 0, event.Changes.UpdatedByID.Previous) + assert.Equal(t, 1, event.Changes.UpdatedByID.Current) + assert.Equal(t, 1, len(event.Changes.Labels.Previous)) + assert.Equal(t, 1, len(event.Changes.Labels.Current)) +} + +func TestParseWikiPageHook(t *testing.T) { + raw := loadFixture("testdata/webhooks/wiki_page.json") + + parsedEvent, err := ParseWebhook("Wiki Page Hook", raw) + if err != nil { + t.Errorf("Error parsing wiki page hook: %s", err) + } + + event, ok := parsedEvent.(*WikiPageEvent) + if !ok { + t.Errorf("Expected WikiPageEvent, but parsing produced %T", parsedEvent) + } + + if event.ObjectKind != "wiki_page" { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "wiki_page") + } + + if event.Project.Name != "awesome-project" { + t.Errorf("Project name is %v, want %v", event.Project.Name, "awesome-project") + } + + if event.Wiki.WebURL != "http://example.com/root/awesome-project/wikis/home" { + t.Errorf("Wiki web URL is %v, want %v", event.Wiki.WebURL, "http://example.com/root/awesome-project/wikis/home") + } + + if event.ObjectAttributes.Message != "adding an awesome page to the wiki" { + t.Errorf("Message is %v, want %v", event.ObjectAttributes.Message, "adding an awesome page to the wiki") + } +} + +func TestParsePipelineHook(t *testing.T) { + raw := loadFixture("testdata/webhooks/pipeline.json") + + parsedEvent, err := ParseWebhook("Pipeline Hook", raw) + if err != nil { + t.Errorf("Error parsing pipeline hook: %s", err) + } + + event, ok := parsedEvent.(*PipelineEvent) + if !ok { + t.Errorf("Expected PipelineEvent, but parsing produced %T", parsedEvent) + } + + if event.ObjectKind != "pipeline" { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "pipeline") + } + + if event.ObjectAttributes.Duration != 63 { + t.Errorf("Duration is %v, want %v", event.ObjectAttributes.Duration, 63) + } + + if event.Commit.ID != "bcbb5ec396a2c0f828686f14fac9b80b780504f2" { + t.Errorf("Commit ID is %v, want %v", event.Commit.ID, "bcbb5ec396a2c0f828686f14fac9b80b780504f2") + } + + if event.Builds[0].ID != 380 { + t.Errorf("Builds[0] ID is %v, want %v", event.Builds[0].ID, 380) + } +} + +func TestParseBuildHook(t *testing.T) { + raw := loadFixture("testdata/webhooks/build.json") + + parsedEvent, err := ParseWebhook("Build Hook", raw) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + + event, ok := parsedEvent.(*BuildEvent) + if !ok { + t.Errorf("Expected BuildEvent, but parsing produced %T", parsedEvent) + } + + if event.ObjectKind != "build" { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "build") + } + + if event.BuildID != 1977 { + t.Errorf("BuildID is %v, want %v", event.BuildID, 1977) + } + + if event.BuildAllowFailure { + t.Errorf("BuildAllowFailure is %v, want %v", event.BuildAllowFailure, false) + } + + if event.Commit.SHA != "2293ada6b400935a1378653304eaf6221e0fdb8f" { + t.Errorf("Commit SHA is %v, want %v", event.Commit.SHA, "2293ada6b400935a1378653304eaf6221e0fdb8f") + } +} + +func TestParseHookWebHook(t *testing.T) { + parsedEvent1, err := ParseHook("Merge Request Hook", loadFixture("testdata/webhooks/merge_request.json")) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + parsedEvent2, err := ParseWebhook("Merge Request Hook", loadFixture("testdata/webhooks/merge_request.json")) + if err != nil { + t.Errorf("Error parsing build hook: %s", err) + } + assert.Equal(t, parsedEvent1, parsedEvent2) +} diff --git a/event_systemhook_types.go b/event_systemhook_types.go new file mode 100644 index 000000000..3ae66c6ad --- /dev/null +++ b/event_systemhook_types.go @@ -0,0 +1,132 @@ +package gitlab + +// systemHookEvent is used to pre-process events to determine the right event type for System Hook events +type systemHookEvent struct { + BaseSystemHookEvent + ObjectKind string `json:"object_kind"` +} + +// BaseSystemHookEvent contains System Hook's common properties +// +// GitLab API docs: +// https://docs.gitlab.com/ee/system_hooks/system_hooks.html +type BaseSystemHookEvent struct { + EventName string `json:"event_name"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` +} + +// ProjectSystemHookEvent +// +// GitLab API docs: +// https://docs.gitlab.com/ee/system_hooks/system_hooks.html +type ProjectSystemHookEvent struct { + BaseSystemHookEvent + Name string `json:"name"` + Path string `json:"path"` + PathWithNamespace string `json:"path_with_namespace"` + ProjectID int `json:"project_id"` + OwnerName string `json:"owner_name"` + OwnerEmail string `json:"owner_email"` + ProjectVisibility string `json:"project_visibility"` + OldPathWithNamespace string `json:"old_path_with_namespace,omitempty"` +} + +// GroupSystemHookEvent +// +// GitLab API docs: +// https://docs.gitlab.com/ee/system_hooks/system_hooks.html +type GroupSystemHookEvent struct { + BaseSystemHookEvent + Name string `json:"name"` + Path string `json:"path"` + PathWithNamespace string `json:"full_path"` + GroupID int `json:"group_id"` + OwnerName string `json:"owner_name"` + OwnerEmail string `json:"owner_email"` + ProjectVisibility string `json:"project_visibility"` + OldPath string `json:"old_path,omitempty"` + OldPathWithNamespace string `json:"old_full_path,omitempty"` +} + +// KeySystemHookEvent +// +// GitLab API docs: +// https://docs.gitlab.com/ee/system_hooks/system_hooks.html +type KeySystemHookEvent struct { + BaseSystemHookEvent + ID int `json:"id"` + Username string `json:"username"` + Key string `json:"key"` +} + +// UserSystemHookEvent +// +// GitLab API docs: +// https://docs.gitlab.com/ee/system_hooks/system_hooks.html +type UserSystemHookEvent struct { + BaseSystemHookEvent + ID int `json:"user_id"` + Name string `json:"name"` + Username string `json:"username"` + OldUsername string `json:"old_username,omitempty"` + Email string `json:"email"` +} + +// UserGroupSystemHookEvent +// +// GitLab API docs: +// https://docs.gitlab.com/ee/system_hooks/system_hooks.html +type UserGroupSystemHookEvent struct { + BaseSystemHookEvent + ID int `json:"user_id"` + Name string `json:"user_name"` + Username string `json:"user_username"` + Email string `json:"user_email"` + GroupID int `json:"group_id"` + GroupName string `json:"group_name"` + GroupPath string `json:"group_path"` + GroupAccess string `json:"group_access"` +} + +// UserTeamSystemHookEvent +// +// GitLab API docs: +// https://docs.gitlab.com/ee/system_hooks/system_hooks.html +type UserTeamSystemHookEvent struct { + BaseSystemHookEvent + ID int `json:"user_id"` + Name string `json:"user_name"` + Username string `json:"user_username"` + Email string `json:"user_email"` + ProjectID int `json:"project_id"` + ProjectName string `json:"project_name"` + ProjectPath string `json:"project_path"` + ProjectPathWithNamespace string `json:"project_path_with_namespace"` + ProjectVisibility string `json:"project_visibility"` + AccessLevel string `json:"access_level"` +} + +// PushSystemHookEvent +// +// GitLab API docs: +// https://docs.gitlab.com/ee/system_hooks/system_hooks.html +type PushSystemHookEvent struct { + BaseSystemHookEvent +} + +// TagPushSystemHookEvent +// +// GitLab API docs: +// https://docs.gitlab.com/ee/system_hooks/system_hooks.html +type TagPushSystemHookEvent struct { + BaseSystemHookEvent +} + +// RepositoryUpdateSystemHookEvent +// +// GitLab API docs: +// https://docs.gitlab.com/ee/system_hooks/system_hooks.html +type RepositoryUpdateSystemHookEvent struct { + BaseSystemHookEvent +} diff --git a/event_types_test.go b/event_types_test.go deleted file mode 100644 index d26145523..000000000 --- a/event_types_test.go +++ /dev/null @@ -1,757 +0,0 @@ -package gitlab - -import ( - "encoding/json" - "github.com/stretchr/testify/assert" - "testing" -) - -func TestPushEventUnmarshal(t *testing.T) { - jsonObject := `{ - "object_kind": "push", - "before": "95790bf891e76fee5e1747ab589903a6a1f80f22", - "after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", - "ref": "refs/heads/master", - "checkout_sha": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", - "user_id": 4, - "user_name": "John Smith", - "user_username": "jsmith", - "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":{ - "id": 15, - "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 event *PushEvent - err := json.Unmarshal([]byte(jsonObject), &event) - - if err != nil { - t.Errorf("Push Event can not unmarshaled: %v\n ", err.Error()) - } - - if event == nil { - t.Errorf("Push Event is null") - } - - if event.ProjectID != 15 { - t.Errorf("ProjectID is %v, want %v", event.ProjectID, 15) - } - - if event.UserName != "John Smith" { - t.Errorf("Username is %s, want %s", event.UserName, "John Smith") - } - - if event.Commits[0] == nil || event.Commits[0].Timestamp == nil { - t.Errorf("Commit Timestamp isn't nil") - } - - if event.Commits[0] == nil || event.Commits[0].Author.Name != "Jordi Mallach" { - t.Errorf("Commit Username is %s, want %s", event.UserName, "Jordi Mallach") - } -} - -func TestMergeEventUnmarshal(t *testing.T) { - - jsonObject := `{ - "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": { - "previous": null, - "current": 1 - }, - "updated_at": { - "previous": "2017-09-15 16:50:55 UTC", - "current": "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 - }] - }, - "source_branch": { - "previous": null, - "current": "feature/test" - }, - "source_project_id": { - "previous": null, - "current": 1 - }, - "target_branch": { - "previous": null, - "current": "develop" - }, - "target_project_id": { - "previous": null, - "current": 1 - }, - "assignees": { - "previous": [], - "current": [ - { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" - } - ] - }, - "total_time_spent": { - "previous": null, - "current": 0 - } - } -}` - - var event *MergeEvent - err := json.Unmarshal([]byte(jsonObject), &event) - - if !assert.NoError(t, err, "Merge Event can not unmarshaled") { - return - } - - assert.Equal(t, 99, event.ObjectAttributes.ID) - assert.Equal(t, "http://example.com/awesome_space/awesome_project", event.ObjectAttributes.Source.Homepage) - assert.Equal(t, "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", event.ObjectAttributes.LastCommit.ID) - assert.Equal(t, "User1", event.ObjectAttributes.Assignee.Name) - assert.Equal(t, "user1", event.ObjectAttributes.Assignee.Username) - assert.Equal(t, "Administrator", event.User.Name) - assert.NotNil(t, "Administrator", event.ObjectAttributes.LastCommit.Timestamp) - assert.Equal(t, "GitLab dev user", event.ObjectAttributes.LastCommit.Author.Name) - assert.Equal(t, "feature/test", event.Changes.SourceBranch.Current) - assert.Empty(t, event.Changes.Assignees.Previous) - if assert.NotEmpty(t, event.Changes.Assignees.Current) { - assert.Equal(t, "Administrator", event.Changes.Assignees.Current[0].Name) - } -} - -func TestPipelineEventUnmarshal(t *testing.T) { - jsonObject := `{ - "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, - "variables": [ - { - "key": "NESTOR_PROD_ENVIRONMENT", - "value": "us-west-1" - } - ] - }, - "merge_request": { - "id": 1, - "iid": 1, - "title": "Test", - "source_branch": "test", - "source_project_id": 1, - "target_branch": "master", - "target_project_id": 1, - "state": "opened", - "merge_status": "can_be_merged", - "url": "http://192.168.64.1:3005/gitlab-org/gitlab-test/merge_requests/1" - }, - "user":{ - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" - }, - "project":{ - "id": 1, - "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": { - "id":380987, - "description":"shared-runners-manager-6.gitlab.com", - "active":true, - "is_shared":true - }, - "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": { - "id":380987, - "description":"shared-runners-manager-6.gitlab.com", - "active":true, - "is_shared":true - }, - "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": { - "id":380987, - "description":"shared-runners-manager-6.gitlab.com", - "active":true, - "is_shared":true - }, - "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 - } - } - ] -}` - - var event *PipelineEvent - err := json.Unmarshal([]byte(jsonObject), &event) - - if err != nil { - t.Errorf("Pipeline Event can not unmarshaled: %v\n ", err.Error()) - } - - if event == nil { - t.Errorf("Pipeline Event is null") - } - - if event.ObjectAttributes.ID != 31 { - t.Errorf("ObjectAttributes is %v, want %v", event.ObjectAttributes.ID, 1977) - } - - if event.User.Name == "" { - t.Errorf("Username is %s, want %s", event.User.Name, "Administrator") - } - - if event.Commit.Timestamp == nil { - t.Errorf("Timestamp isn't nil") - } - - if name := event.Commit.Author.Name; name != "User" { - t.Errorf("Commit Username is %s, want %s", name, "User") - } - - if mergeRequestID := event.MergeRequest.ID; mergeRequestID != 1 { - t.Errorf("Merge Request ID is %d, want %d", mergeRequestID, 1) - } -} - -func TestBuildEventUnmarshal(t *testing.T) { - jsonObject := `{ - "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, - "build_failure_reason": "script_failure", - "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", - "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 - } -}` - var event *BuildEvent - err := json.Unmarshal([]byte(jsonObject), &event) - - if err != nil { - t.Errorf("Build Event can not unmarshaled: %v\n ", err.Error()) - } - - if event == nil { - t.Errorf("Build Event is null") - } - - if event.BuildID != 1977 { - t.Errorf("BuildID is %v, want %v", event.BuildID, 1977) - } -} - -func TestMergeEventUnmarshalFromGroup(t *testing.T) { - - jsonObject := `{ - "object_kind": "merge_request", - "user": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/d22738dc40839e3d95fca77ca3eac067?s=80\u0026d=identicon" - }, - "project": { - "name": "example-project", - "description": "", - "web_url": "http://example.com/exm-namespace/example-project", - "avatar_url": null, - "git_ssh_url": "git@example.com:exm-namespace/example-project.git", - "git_http_url": "http://example.com/exm-namespace/example-project.git", - "namespace": "exm-namespace", - "visibility": "public", - "path_with_namespace": "exm-namespace/example-project", - "default_branch": "master", - "homepage": "http://example.com/exm-namespace/example-project", - "url": "git@example.com:exm-namespace/example-project.git", - "ssh_url": "git@example.com:exm-namespace/example-project.git", - "http_url": "http://example.com/exm-namespace/example-project.git" - }, - "object_attributes": { - "id": 15917, - "target_branch ": "master ", - "source_branch ": "source-branch-test ", - "source_project_id ": 87, - "author_id ": 15, - "assignee_id ": 29, - "title ": "source-branch-test ", - "created_at ": "2016 - 12 - 01 13: 11: 10 UTC ", - "updated_at ": "2016 - 12 - 01 13: 21: 20 UTC ", - "milestone_id ": null, - "state ": "merged ", - "merge_status ": "can_be_merged ", - "target_project_id ": 87, - "iid ": 1402, - "description ": "word doc support for e - ticket ", - "position ": 0, - "locked_at ": null, - "updated_by_id ": null, - "merge_error ": null, - "merge_params": { - "force_remove_source_branch": "0" - }, - "merge_when_build_succeeds": false, - "merge_user_id": null, - "merge_commit_sha": "ac3ca1559bc39abf963586372eff7f8fdded646e", - "deleted_at": null, - "approvals_before_merge": null, - "rebase_commit_sha": null, - "in_progress_merge_commit_sha": null, - "lock_version": 0, - "time_estimate": 0, - "source": { - "name": "example-project", - "description": "", - "web_url": "http://example.com/exm-namespace/example-project", - "avatar_url": null, - "git_ssh_url": "git@example.com:exm-namespace/example-project.git", - "git_http_url": "http://example.com/exm-namespace/example-project.git", - "namespace": "exm-namespace", - "visibility": "public", - "path_with_namespace": "exm-namespace/example-project", - "default_branch": "master", - "homepage": "http://example.com/exm-namespace/example-project", - "url": "git@example.com:exm-namespace/example-project.git", - "ssh_url": "git@example.com:exm-namespace/example-project.git", - "http_url": "http://example.com/exm-namespace/example-project.git" - }, - "target": { - "name": "example-project", - "description": "", - "web_url": "http://example.com/exm-namespace/example-project", - "avatar_url": null, - "git_ssh_url": "git@example.com:exm-namespace/example-project.git", - "git_http_url": "http://example.com/exm-namespace/example-project.git", - "namespace": "exm-namespace", - "visibility": "public", - "path_with_namespace": "exm-namespace/example-project", - "default_branch": "master", - "homepage": "http://example.com/exm-namespace/example-project", - "url": "git@example.com:exm-namespace/example-project.git", - "ssh_url": "git@example.com:exm-namespace/example-project.git", - "http_url": "http://example.com/exm-namespace/example-project.git" - }, - "last_commit": { - "id": "61b6a0d35dbaf915760233b637622e383d3cc9ec", - "message": "commit message", - "timestamp": "2016-12-01T15:07:53+02:00", - "url": "http://example.com/exm-namespace/example-project/commit/61b6a0d35dbaf915760233b637622e383d3cc9ec", - "author": { - "name": "Test User", - "email": "test.user@mail.com" - } - }, - "work_in_progress": false, - "url": "http://example.com/exm-namespace/example-project/merge_requests/1402", - "action": "merge" - }, - "repository": { - "name": "example-project", - "url": "git@example.com:exm-namespace/example-project.git", - "description": "", - "homepage": "http://example.com/exm-namespace/example-project" - }, - "assignee": { - "name": "Administrator", - "username": "root", - "avatar_url": "http://www.gravatar.com/avatar/d22738dc40839e3d95fca77ca3eac067?s=80\u0026d=identicon" - } -}` - - var event *MergeEvent - err := json.Unmarshal([]byte(jsonObject), &event) - - if err != nil { - t.Errorf("Group Merge Event can not unmarshaled: %v\n ", err.Error()) - } - - if event == nil { - t.Errorf("Group Merge Event is null") - } - - if event.ObjectKind != "merge_request" { - t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "merge_request") - } - - if event.User.Username != "root" { - t.Errorf("User.Username is %v, want %v", event.User.Username, "root") - } - - if event.Project.Name != "example-project" { - t.Errorf("Project.Name is %v, want %v", event.Project.Name, "example-project") - } - - if event.ObjectAttributes.ID != 15917 { - t.Errorf("ObjectAttributes.ID is %v, want %v", event.ObjectAttributes.ID, 15917) - } - - if event.ObjectAttributes.Source.Name != "example-project" { - t.Errorf("ObjectAttributes.Source.Name is %v, want %v", event.ObjectAttributes.Source.Name, "example-project") - } - - if event.ObjectAttributes.LastCommit.Author.Email != "test.user@mail.com" { - t.Errorf("ObjectAttributes.LastCommit.Author.Email is %v, want %v", event.ObjectAttributes.LastCommit.Author.Email, "test.user@mail.com") - } - - if event.Repository.Name != "example-project" { - t.Errorf("Repository.Name is %v, want %v", event.Repository.Name, "example-project") - } - - if event.Assignee.Username != "root" { - t.Errorf("Assignee.Username is %v, want %v", event.Assignee, "root") - } - - if event.User.Name == "" { - t.Errorf("Username is %s, want %s", event.User.Name, "Administrator") - } - - if event.ObjectAttributes.LastCommit.Timestamp == nil { - t.Errorf("Timestamp isn't nil") - } - - if name := event.ObjectAttributes.LastCommit.Author.Name; name != "Test User" { - t.Errorf("Commit Username is %s, want %s", name, "Test User") - } -} diff --git a/event_types.go b/event_webhook_types.go similarity index 100% rename from event_types.go rename to event_webhook_types.go diff --git a/event_webhook_types_test.go b/event_webhook_types_test.go new file mode 100644 index 000000000..3973dd5cb --- /dev/null +++ b/event_webhook_types_test.go @@ -0,0 +1,191 @@ +package gitlab + +import ( + "encoding/json" + "testing" +) + +func TestPushEventUnmarshal(t *testing.T) { + jsonObject := loadFixture("testdata/webhooks/push.json") + var event *PushEvent + err := json.Unmarshal(jsonObject, &event) + + if err != nil { + t.Errorf("Push Event can not unmarshaled: %v\n ", err.Error()) + } + + if event == nil { + t.Errorf("Push Event is null") + } + + if event.ProjectID != 15 { + t.Errorf("ProjectID is %v, want %v", event.ProjectID, 15) + } + + if event.UserName != "John Smith" { + t.Errorf("Username is %s, want %s", event.UserName, "John Smith") + } + + if event.Commits[0] == nil || event.Commits[0].Timestamp == nil { + t.Errorf("Commit Timestamp isn't nil") + } + + if event.Commits[0] == nil || event.Commits[0].Author.Name != "Jordi Mallach" { + t.Errorf("Commit Username is %s, want %s", event.UserName, "Jordi Mallach") + } +} + +func TestMergeEventUnmarshal(t *testing.T) { + jsonObject := loadFixture("testdata/webhooks/merge_request.json") + + var event *MergeEvent + err := json.Unmarshal(jsonObject, &event) + + if err != nil { + t.Errorf("Merge Event can not unmarshaled: %v\n ", err.Error()) + } + + if event == nil { + t.Errorf("Merge Event is null") + } + + if event.ObjectAttributes.ID != 99 { + t.Errorf("ObjectAttributes.ID is %v, want %v", event.ObjectAttributes.ID, 99) + } + + if event.ObjectAttributes.Source.Homepage != "http://example.com/awesome_space/awesome_project" { + t.Errorf("ObjectAttributes.Source.Homepage is %v, want %v", event.ObjectAttributes.Source.Homepage, "http://example.com/awesome_space/awesome_project") + } + + if event.ObjectAttributes.LastCommit.ID != "da1560886d4f094c3e6c9ef40349f7d38b5d27d7" { + t.Errorf("ObjectAttributes.LastCommit.ID is %v, want %s", event.ObjectAttributes.LastCommit.ID, "da1560886d4f094c3e6c9ef40349f7d38b5d27d7") + } + if event.ObjectAttributes.Assignee.Name != "User1" { + t.Errorf("Assignee.Name is %v, want %v", event.ObjectAttributes.ID, "User1") + } + + if event.ObjectAttributes.Assignee.Username != "user1" { + t.Errorf("ObjectAttributes is %v, want %v", event.ObjectAttributes.Assignee.Username, "user1") + } + + if event.User.Name == "" { + t.Errorf("Username is %s, want %s", event.User.Name, "Administrator") + } + + if event.ObjectAttributes.LastCommit.Timestamp == nil { + t.Errorf("Timestamp isn't nil") + } + + if name := event.ObjectAttributes.LastCommit.Author.Name; name != "GitLab dev user" { + t.Errorf("Commit Username is %s, want %s", name, "GitLab dev user") + } +} + +func TestPipelineEventUnmarshal(t *testing.T) { + jsonObject := loadFixture("testdata/webhooks/pipeline.json") + + var event *PipelineEvent + err := json.Unmarshal(jsonObject, &event) + + if err != nil { + t.Errorf("Pipeline Event can not unmarshaled: %v\n ", err.Error()) + } + + if event == nil { + t.Errorf("Pipeline Event is null") + } + + if event.ObjectAttributes.ID != 31 { + t.Errorf("ObjectAttributes is %v, want %v", event.ObjectAttributes.ID, 1977) + } + + if event.User.Name == "" { + t.Errorf("Username is %s, want %s", event.User.Name, "Administrator") + } + + if event.Commit.Timestamp == nil { + t.Errorf("Timestamp isn't nil") + } + + if name := event.Commit.Author.Name; name != "User" { + t.Errorf("Commit Username is %s, want %s", name, "User") + } +} + +func TestBuildEventUnmarshal(t *testing.T) { + jsonObject := loadFixture("testdata/webhooks/build.json") + + var event *BuildEvent + err := json.Unmarshal(jsonObject, &event) + + if err != nil { + t.Errorf("Build Event can not unmarshaled: %v\n ", err.Error()) + } + + if event == nil { + t.Errorf("Build Event is null") + } + + if event.BuildID != 1977 { + t.Errorf("BuildID is %v, want %v", event.BuildID, 1977) + } +} + +func TestMergeEventUnmarshalFromGroup(t *testing.T) { + jsonObject := loadFixture("testdata/webhooks/group_merge_request.json") + + var event *MergeEvent + err := json.Unmarshal(jsonObject, &event) + + if err != nil { + t.Errorf("Group Merge Event can not unmarshaled: %v\n ", err.Error()) + } + + if event == nil { + t.Errorf("Group Merge Event is null") + } + + if event.ObjectKind != "merge_request" { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "merge_request") + } + + if event.User.Username != "root" { + t.Errorf("User.Username is %v, want %v", event.User.Username, "root") + } + + if event.Project.Name != "example-project" { + t.Errorf("Project.Name is %v, want %v", event.Project.Name, "example-project") + } + + if event.ObjectAttributes.ID != 15917 { + t.Errorf("ObjectAttributes.ID is %v, want %v", event.ObjectAttributes.ID, 15917) + } + + if event.ObjectAttributes.Source.Name != "example-project" { + t.Errorf("ObjectAttributes.Source.Name is %v, want %v", event.ObjectAttributes.Source.Name, "example-project") + } + + if event.ObjectAttributes.LastCommit.Author.Email != "test.user@mail.com" { + t.Errorf("ObjectAttributes.LastCommit.Author.Email is %v, want %v", event.ObjectAttributes.LastCommit.Author.Email, "test.user@mail.com") + } + + if event.Repository.Name != "example-project" { + t.Errorf("Repository.Name is %v, want %v", event.Repository.Name, "example-project") + } + + if event.Assignee.Username != "root" { + t.Errorf("Assignee.Username is %v, want %v", event.Assignee, "root") + } + + if event.User.Name == "" { + t.Errorf("Username is %s, want %s", event.User.Name, "Administrator") + } + + if event.ObjectAttributes.LastCommit.Timestamp == nil { + t.Errorf("Timestamp isn't nil") + } + + if name := event.ObjectAttributes.LastCommit.Author.Name; name != "Test User" { + t.Errorf("Commit Username is %s, want %s", name, "Test User") + } +} diff --git a/gitlab_test.go b/gitlab_test.go index 17115d111..371eb3372 100644 --- a/gitlab_test.go +++ b/gitlab_test.go @@ -7,6 +7,7 @@ import ( "errors" "io" "io/ioutil" + "log" "net/http" "net/http/httptest" "os" @@ -195,3 +196,12 @@ func TestBoolValue(t *testing.T) { }) } } + +func loadFixture(filePath string) []byte { + content, err := ioutil.ReadFile(filePath) + if err != nil { + log.Fatal(err) + } + + return content +} diff --git a/testdata/systemhooks/group_create.json b/testdata/systemhooks/group_create.json new file mode 100644 index 000000000..ecc220599 --- /dev/null +++ b/testdata/systemhooks/group_create.json @@ -0,0 +1,10 @@ +{ + "created_at": "2012-07-21T07:30:54Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "group_create", + "name": "StoreCloud", + "owner_email": null, + "owner_name": null, + "path": "storecloud", + "group_id": 78 +} \ No newline at end of file diff --git a/testdata/systemhooks/group_destroy.json b/testdata/systemhooks/group_destroy.json new file mode 100644 index 000000000..62ec7bb26 --- /dev/null +++ b/testdata/systemhooks/group_destroy.json @@ -0,0 +1,10 @@ +{ + "created_at": "2012-07-21T07:30:54Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "group_destroy", + "name": "StoreCloud", + "owner_email": null, + "owner_name": null, + "path": "storecloud", + "group_id": 78 +} \ No newline at end of file diff --git a/testdata/systemhooks/group_rename.json b/testdata/systemhooks/group_rename.json new file mode 100644 index 000000000..93852f7a7 --- /dev/null +++ b/testdata/systemhooks/group_rename.json @@ -0,0 +1,13 @@ +{ + "event_name": "group_rename", + "created_at": "2017-10-30T15:09:00Z", + "updated_at": "2017-11-01T10:23:52Z", + "name": "Better Name", + "path": "better-name", + "full_path": "parent-group/better-name", + "group_id": 64, + "owner_name": null, + "owner_email": null, + "old_path": "old-name", + "old_full_path": "parent-group/old-name" +} \ No newline at end of file diff --git a/testdata/systemhooks/key_create.json b/testdata/systemhooks/key_create.json new file mode 100644 index 000000000..bd0481f89 --- /dev/null +++ b/testdata/systemhooks/key_create.json @@ -0,0 +1,8 @@ +{ + "event_name": "key_create", + "created_at": "2014-08-18 18:45:16 UTC", + "updated_at": "2012-07-21T07:38:22Z", + "username": "root", + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC58FwqHUbebw2SdT7SP4FxZ0w+lAO/erhy2ylhlcW/tZ3GY3mBu9VeeiSGoGz8hCx80Zrz+aQv28xfFfKlC8XQFpCWwsnWnQqO2Lv9bS8V1fIHgMxOHIt5Vs+9CAWGCCvUOAurjsUDoE2ALIXLDMKnJxcxD13XjWdK54j6ZXDB4syLF0C2PnAQSVY9X7MfCYwtuFmhQhKaBussAXpaVMRHltie3UYSBUUuZaB3J4cg/7TxlmxcNd+ppPRIpSZAB0NI6aOnqoBCpimscO/VpQRJMVLr3XiSYeT6HBiDXWHnIVPfQc03OGcaFqOit6p8lYKMaP/iUQLm+pgpZqrXZ9vB john@localhost", + "id": 4 +} \ No newline at end of file diff --git a/testdata/systemhooks/key_destroy.json b/testdata/systemhooks/key_destroy.json new file mode 100644 index 000000000..6b6a16119 --- /dev/null +++ b/testdata/systemhooks/key_destroy.json @@ -0,0 +1,8 @@ +{ + "event_name": "key_destroy", + "created_at": "2014-08-18 18:45:16 UTC", + "updated_at": "2012-07-21T07:38:22Z", + "username": "root", + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC58FwqHUbebw2SdT7SP4FxZ0w+lAO/erhy2ylhlcW/tZ3GY3mBu9VeeiSGoGz8hCx80Zrz+aQv28xfFfKlC8XQFpCWwsnWnQqO2Lv9bS8V1fIHgMxOHIt5Vs+9CAWGCCvUOAurjsUDoE2ALIXLDMKnJxcxD13XjWdK54j6ZXDB4syLF0C2PnAQSVY9X7MfCYwtuFmhQhKaBussAXpaVMRHltie3UYSBUUuZaB3J4cg/7TxlmxcNd+ppPRIpSZAB0NI6aOnqoBCpimscO/VpQRJMVLr3XiSYeT6HBiDXWHnIVPfQc03OGcaFqOit6p8lYKMaP/iUQLm+pgpZqrXZ9vB john@localhost", + "id": 4 +} \ No newline at end of file diff --git a/testdata/systemhooks/merge_request.json b/testdata/systemhooks/merge_request.json new file mode 100644 index 000000000..ea05ad89e --- /dev/null +++ b/testdata/systemhooks/merge_request.json @@ -0,0 +1,114 @@ +{ + "object_kind": "merge_request", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon" + }, + "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", + "ci_config_path": "", + "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" + }, + "object_attributes": { + "id": 90, + "target_branch": "master", + "source_branch": "ms-viewport", + "source_project_id": 14, + "author_id": 51, + "assignee_id": 6, + "title": "MS-Viewport", + "created_at": "2017-09-20T08:31:45.944Z", + "updated_at": "2017-09-28T12:23:42.365Z", + "milestone_id": null, + "state": "opened", + "merge_status": "unchecked", + "target_project_id": 14, + "iid": 1, + "description": "", + "updated_by_id": 1, + "merge_error": null, + "merge_params": { + "force_remove_source_branch": "0" + }, + "merge_when_pipeline_succeeds": false, + "merge_user_id": null, + "merge_commit_sha": null, + "deleted_at": null, + "in_progress_merge_commit_sha": null, + "lock_version": 5, + "time_estimate": 0, + "last_edited_at": "2017-09-27T12:43:37.558Z", + "last_edited_by_id": 1, + "head_pipeline_id": 61, + "ref_fetched": true, + "merge_jid": null, + "source": { + "name": "Awesome Project", + "description": "", + "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": "root", + "visibility_level": 0, + "path_with_namespace": "awesome_space/awesome_project", + "default_branch": "master", + "ci_config_path": "", + "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": 0, + "path_with_namespace": "awesome_space/awesome_project", + "default_branch": "master", + "ci_config_path": "", + "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": "ba3e0d8ff79c80d5b0bbb4f3e2e343e0aaa662b7", + "message": "fixed readme", + "timestamp": "2017-09-26T16:12:57Z", + "url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "author": { + "name": "GitLab dev user", + "email": "gitlabdev@dv6700.(none)" + } + }, + "work_in_progress": false, + "total_time_spent": 0, + "human_total_time_spent": null, + "human_time_estimate": null + }, + "labels": null, + "repository": { + "name": "git-gpg-test", + "url": "git@example.com:awesome_space/awesome_project.git", + "description": "", + "homepage": "http://example.com/awesome_space/awesome_project" + } +} \ No newline at end of file diff --git a/testdata/systemhooks/project_create.json b/testdata/systemhooks/project_create.json new file mode 100644 index 000000000..a5280a058 --- /dev/null +++ b/testdata/systemhooks/project_create.json @@ -0,0 +1,12 @@ +{ + "created_at": "2012-07-21T07:30:54Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "project_create", + "name": "StoreCloud", + "owner_email": "johnsmith@gmail.com", + "owner_name": "John Smith", + "path": "storecloud", + "path_with_namespace": "jsmith/storecloud", + "project_id": 74, + "project_visibility": "private" +} \ No newline at end of file diff --git a/testdata/systemhooks/project_destroy.json b/testdata/systemhooks/project_destroy.json new file mode 100644 index 000000000..e39a84671 --- /dev/null +++ b/testdata/systemhooks/project_destroy.json @@ -0,0 +1,12 @@ +{ + "created_at": "2012-07-21T07:30:58Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "project_destroy", + "name": "Underscore", + "owner_email": "johnsmith@gmail.com", + "owner_name": "John Smith", + "path": "underscore", + "path_with_namespace": "jsmith/underscore", + "project_id": 73, + "project_visibility": "internal" +} \ No newline at end of file diff --git a/testdata/systemhooks/project_rename.json b/testdata/systemhooks/project_rename.json new file mode 100644 index 000000000..aac40bbc5 --- /dev/null +++ b/testdata/systemhooks/project_rename.json @@ -0,0 +1,13 @@ +{ + "created_at": "2012-07-21T07:30:58Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "project_rename", + "name": "Underscore", + "path": "underscore", + "path_with_namespace": "jsmith/underscore", + "project_id": 73, + "owner_name": "John Smith", + "owner_email": "johnsmith@gmail.com", + "project_visibility": "internal", + "old_path_with_namespace": "jsmith/overscore" +} \ No newline at end of file diff --git a/testdata/systemhooks/project_transfer.json b/testdata/systemhooks/project_transfer.json new file mode 100644 index 000000000..488cfae50 --- /dev/null +++ b/testdata/systemhooks/project_transfer.json @@ -0,0 +1,13 @@ +{ + "created_at": "2012-07-21T07:30:58Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "project_transfer", + "name": "Underscore", + "path": "underscore", + "path_with_namespace": "scores/underscore", + "project_id": 73, + "owner_name": "John Smith", + "owner_email": "johnsmith@gmail.com", + "project_visibility": "internal", + "old_path_with_namespace": "jsmith/overscore" +} \ No newline at end of file diff --git a/testdata/systemhooks/project_update.json b/testdata/systemhooks/project_update.json new file mode 100644 index 000000000..7dd95f218 --- /dev/null +++ b/testdata/systemhooks/project_update.json @@ -0,0 +1,12 @@ +{ + "created_at": "2012-07-21T07:30:54Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "project_update", + "name": "StoreCloud", + "owner_email": "johnsmith@gmail.com", + "owner_name": "John Smith", + "path": "storecloud", + "path_with_namespace": "jsmith/storecloud", + "project_id": 74, + "project_visibility": "private" +} \ No newline at end of file diff --git a/testdata/systemhooks/push.json b/testdata/systemhooks/push.json new file mode 100644 index 000000000..8eb7be171 --- /dev/null +++ b/testdata/systemhooks/push.json @@ -0,0 +1,50 @@ +{ + "event_name": "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": "c5feabde2d8cd023215af4d2ceeb7a64839fc428", + "message": "Add simple search to projects in public area", + "timestamp": "2013-05-13T18:18:08+00:00", + "url": "https://dev.gitlab.org/gitlab/gitlabhq/commit/c5feabde2d8cd023215af4d2ceeb7a64839fc428", + "author": { + "name": "Dmitriy Zaporozhets", + "email": "dmitriy.zaporozhets@gmail.com" + } + } + ], + "total_commits_count": 1 +} \ No newline at end of file diff --git a/testdata/systemhooks/repository_update.json b/testdata/systemhooks/repository_update.json new file mode 100644 index 000000000..ecc69fbe7 --- /dev/null +++ b/testdata/systemhooks/repository_update.json @@ -0,0 +1,32 @@ +{ + "event_name": "repository_update", + "user_id": 1, + "user_name": "John Smith", + "user_email": "admin@example.com", + "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" + }, + "changes": [ + { + "before":"8205ea8d81ce0c6b90fbe8280d118cc9fdad6130", + "after":"4045ea7a3df38697b3730a20fb73c8bed8a3e69e", + "ref":"refs/heads/master" + } + ], + "refs":["refs/heads/master"] +} \ No newline at end of file diff --git a/testdata/systemhooks/tag_push.json b/testdata/systemhooks/tag_push.json new file mode 100644 index 000000000..0b4224faa --- /dev/null +++ b/testdata/systemhooks/tag_push.json @@ -0,0 +1,38 @@ +{ + "event_name": "tag_push", + "before": "0000000000000000000000000000000000000000", + "after": "82b3d5ae55f7080f1e6022629cdb57bfae7cccc7", + "ref": "refs/tags/v1.0.0", + "checkout_sha": "5937ac0a7beb003549fc5fd26fc247adbce4a52e", + "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 +} \ No newline at end of file diff --git a/testdata/systemhooks/user_add_to_group.json b/testdata/systemhooks/user_add_to_group.json new file mode 100644 index 000000000..8f07c9f6d --- /dev/null +++ b/testdata/systemhooks/user_add_to_group.json @@ -0,0 +1,13 @@ +{ + "created_at": "2012-07-21T07:30:56Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "user_add_to_group", + "group_access": "Maintainer", + "group_id": 78, + "group_name": "StoreCloud", + "group_path": "storecloud", + "user_email": "johnsmith@gmail.com", + "user_name": "John Smith", + "user_username": "johnsmith", + "user_id": 41 +} \ No newline at end of file diff --git a/testdata/systemhooks/user_add_to_team.json b/testdata/systemhooks/user_add_to_team.json new file mode 100644 index 000000000..74ee8353d --- /dev/null +++ b/testdata/systemhooks/user_add_to_team.json @@ -0,0 +1,15 @@ +{ + "created_at": "2012-07-21T07:30:56Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "user_add_to_team", + "access_level": "Maintainer", + "project_id": 74, + "project_name": "StoreCloud", + "project_path": "storecloud", + "project_path_with_namespace": "jsmith/storecloud", + "user_email": "johnsmith@gmail.com", + "user_name": "John Smith", + "user_username": "johnsmith", + "user_id": 41, + "project_visibility": "visibilitylevel|private" +} \ No newline at end of file diff --git a/testdata/systemhooks/user_create.json b/testdata/systemhooks/user_create.json new file mode 100644 index 000000000..289ea9f2b --- /dev/null +++ b/testdata/systemhooks/user_create.json @@ -0,0 +1,9 @@ +{ + "created_at": "2012-07-21T07:44:07Z", + "updated_at": "2012-07-21T07:38:22Z", + "email": "js@gitlabhq.com", + "event_name": "user_create", + "name": "John Smith", + "username": "js", + "user_id": 41 +} \ No newline at end of file diff --git a/testdata/systemhooks/user_destroy.json b/testdata/systemhooks/user_destroy.json new file mode 100644 index 000000000..cf07b2e0a --- /dev/null +++ b/testdata/systemhooks/user_destroy.json @@ -0,0 +1,9 @@ +{ + "created_at": "2012-07-21T07:44:07Z", + "updated_at": "2012-07-21T07:38:22Z", + "email": "js@gitlabhq.com", + "event_name": "user_destroy", + "name": "John Smith", + "username": "js", + "user_id": 41 +} \ No newline at end of file diff --git a/testdata/systemhooks/user_failed_login.json b/testdata/systemhooks/user_failed_login.json new file mode 100644 index 000000000..5ab3cd503 --- /dev/null +++ b/testdata/systemhooks/user_failed_login.json @@ -0,0 +1,10 @@ +{ + "event_name": "user_failed_login", + "created_at": "2017-10-03T06:08:48Z", + "updated_at": "2018-01-15T04:52:06Z", + "name": "John Smith", + "email": "user4@example.com", + "user_id": 26, + "username": "user4", + "state": "blocked" +} \ No newline at end of file diff --git a/testdata/systemhooks/user_remove_from_group.json b/testdata/systemhooks/user_remove_from_group.json new file mode 100644 index 000000000..951e5ac32 --- /dev/null +++ b/testdata/systemhooks/user_remove_from_group.json @@ -0,0 +1,13 @@ +{ + "created_at": "2012-07-21T07:30:56Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "user_remove_from_group", + "group_access": "Maintainer", + "group_id": 78, + "group_name": "StoreCloud", + "group_path": "storecloud", + "user_email": "johnsmith@gmail.com", + "user_name": "John Smith", + "user_username": "johnsmith", + "user_id": 41 +} \ No newline at end of file diff --git a/testdata/systemhooks/user_remove_from_team.json b/testdata/systemhooks/user_remove_from_team.json new file mode 100644 index 000000000..386835b57 --- /dev/null +++ b/testdata/systemhooks/user_remove_from_team.json @@ -0,0 +1,15 @@ +{ + "created_at": "2012-07-21T07:30:56Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "user_remove_from_team", + "access_level": "Maintainer", + "project_id": 74, + "project_name": "StoreCloud", + "project_path": "storecloud", + "project_path_with_namespace": "jsmith/storecloud", + "user_email": "johnsmith@gmail.com", + "user_name": "John Smith", + "user_username": "johnsmith", + "user_id": 41, + "project_visibility": "visibilitylevel|private" +} \ No newline at end of file diff --git a/testdata/systemhooks/user_rename.json b/testdata/systemhooks/user_rename.json new file mode 100644 index 000000000..e64e06711 --- /dev/null +++ b/testdata/systemhooks/user_rename.json @@ -0,0 +1,10 @@ +{ + "event_name": "user_rename", + "created_at": "2017-11-01T11:21:04Z", + "updated_at": "2017-11-01T14:04:47Z", + "name": "new-name", + "email": "best-email@example.tld", + "user_id": 58, + "username": "new-exciting-name", + "old_username": "old-boring-name" +} \ No newline at end of file diff --git a/testdata/systemhooks/user_update_for_group.json b/testdata/systemhooks/user_update_for_group.json new file mode 100644 index 000000000..44dfd0f27 --- /dev/null +++ b/testdata/systemhooks/user_update_for_group.json @@ -0,0 +1,13 @@ +{ + "created_at": "2012-07-21T07:30:56Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "user_update_for_group", + "group_access": "Maintainer", + "group_id": 78, + "group_name": "StoreCloud", + "group_path": "storecloud", + "user_email": "johnsmith@gmail.com", + "user_name": "John Smith", + "user_username": "johnsmith", + "user_id": 41 +} \ No newline at end of file diff --git a/testdata/systemhooks/user_update_for_team.json b/testdata/systemhooks/user_update_for_team.json new file mode 100644 index 000000000..28dd18772 --- /dev/null +++ b/testdata/systemhooks/user_update_for_team.json @@ -0,0 +1,15 @@ +{ + "created_at": "2012-07-21T07:30:56Z", + "updated_at": "2012-07-21T07:38:22Z", + "event_name": "user_update_for_team", + "access_level": "Maintainer", + "project_id": 74, + "project_name": "StoreCloud", + "project_path": "storecloud", + "project_path_with_namespace": "jsmith/storecloud", + "user_email": "johnsmith@gmail.com", + "user_name": "John Smith", + "user_username": "johnsmith", + "user_id": 41, + "project_visibility": "visibilitylevel|private" +} \ No newline at end of file diff --git a/testdata/webhooks/build.json b/testdata/webhooks/build.json new file mode 100644 index 000000000..546dfd4ee --- /dev/null +++ b/testdata/webhooks/build.json @@ -0,0 +1,42 @@ +{ + "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, + "build_failure_reason": "script_failure", + "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", + "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 + } +} \ No newline at end of file diff --git a/testdata/webhooks/group_merge_request.json b/testdata/webhooks/group_merge_request.json new file mode 100644 index 000000000..7220709ff --- /dev/null +++ b/testdata/webhooks/group_merge_request.json @@ -0,0 +1,113 @@ +{ + "object_kind": "merge_request", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/d22738dc40839e3d95fca77ca3eac067?s=80\u0026d=identicon" + }, + "project": { + "name": "example-project", + "description": "", + "web_url": "http://example.com/exm-namespace/example-project", + "avatar_url": null, + "git_ssh_url": "git@example.com:exm-namespace/example-project.git", + "git_http_url": "http://example.com/exm-namespace/example-project.git", + "namespace": "exm-namespace", + "visibility": "public", + "path_with_namespace": "exm-namespace/example-project", + "default_branch": "master", + "homepage": "http://example.com/exm-namespace/example-project", + "url": "git@example.com:exm-namespace/example-project.git", + "ssh_url": "git@example.com:exm-namespace/example-project.git", + "http_url": "http://example.com/exm-namespace/example-project.git" + }, + "object_attributes": { + "id": 15917, + "target_branch ": "master", + "source_branch ": "source-branch-test", + "source_project_id ": 87, + "author_id ": 15, + "assignee_id ": 29, + "title ": "source-branch-test ", + "created_at ": "2016-12-01 13:11:10 UTC", + "updated_at ": "2016-12-01 13:21:20 UTC", + "milestone_id ": null, + "state ": "merged ", + "merge_status ": "can_be_merged ", + "target_project_id ": 87, + "iid ": 1402, + "description ": "word doc support for e-ticket", + "position ": 0, + "locked_at ": null, + "updated_by_id ": null, + "merge_error ": null, + "merge_params": { + "force_remove_source_branch": "0" + }, + "merge_when_build_succeeds": false, + "merge_user_id": null, + "merge_commit_sha": "ac3ca1559bc39abf963586372eff7f8fdded646e", + "deleted_at": null, + "approvals_before_merge": null, + "rebase_commit_sha": null, + "in_progress_merge_commit_sha": null, + "lock_version": 0, + "time_estimate": 0, + "source": { + "name": "example-project", + "description": "", + "web_url": "http://example.com/exm-namespace/example-project", + "avatar_url": null, + "git_ssh_url": "git@example.com:exm-namespace/example-project.git", + "git_http_url": "http://example.com/exm-namespace/example-project.git", + "namespace": "exm-namespace", + "visibility": "public", + "path_with_namespace": "exm-namespace/example-project", + "default_branch": "master", + "homepage": "http://example.com/exm-namespace/example-project", + "url": "git@example.com:exm-namespace/example-project.git", + "ssh_url": "git@example.com:exm-namespace/example-project.git", + "http_url": "http://example.com/exm-namespace/example-project.git" + }, + "target": { + "name": "example-project", + "description": "", + "web_url": "http://example.com/exm-namespace/example-project", + "avatar_url": null, + "git_ssh_url": "git@example.com:exm-namespace/example-project.git", + "git_http_url": "http://example.com/exm-namespace/example-project.git", + "namespace": "exm-namespace", + "visibility": "public", + "path_with_namespace": "exm-namespace/example-project", + "default_branch": "master", + "homepage": "http://example.com/exm-namespace/example-project", + "url": "git@example.com:exm-namespace/example-project.git", + "ssh_url": "git@example.com:exm-namespace/example-project.git", + "http_url": "http://example.com/exm-namespace/example-project.git" + }, + "last_commit": { + "id": "61b6a0d35dbaf915760233b637622e383d3cc9ec", + "message": "commit message", + "timestamp": "2016-12-01T15:07:53+02:00", + "url": "http://example.com/exm-namespace/example-project/commit/61b6a0d35dbaf915760233b637622e383d3cc9ec", + "author": { + "name": "Test User", + "email": "test.user@mail.com" + } + }, + "work_in_progress": false, + "url": "http://example.com/exm-namespace/example-project/merge_requests/1402", + "action": "merge" + }, + "repository": { + "name": "example-project", + "url": "git@example.com:exm-namespace/example-project.git", + "description": "", + "homepage": "http://example.com/exm-namespace/example-project" + }, + "assignee": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/d22738dc40839e3d95fca77ca3eac067?s=80\u0026d=identicon" + } +} \ No newline at end of file diff --git a/testdata/webhooks/issue.json b/testdata/webhooks/issue.json new file mode 100644 index 000000000..98eeafda6 --- /dev/null +++ b/testdata/webhooks/issue.json @@ -0,0 +1,107 @@ +{ + "object_kind": "issue", + "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": 301, + "title": "New API: create/update/delete file", + "assignee_ids": [51], + "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" + }, + "assignees": [{ + "name": "User1", + "username": "user1", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + }], + "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": { + "previous": null, + "current": 1 + }, + "updated_at": { + "previous": "2017-09-15 16:50:55 UTC", + "current": "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 + }] + } + } +} \ No newline at end of file diff --git a/testdata/webhooks/merge_request.json b/testdata/webhooks/merge_request.json new file mode 100644 index 000000000..144c0a098 --- /dev/null +++ b/testdata/webhooks/merge_request.json @@ -0,0 +1,146 @@ +{ + "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": { + "previous": null, + "current": 1 + }, + "updated_at": { + "previous": "2017-09-15 16:50:55 UTC", + "current": "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 + }] + } + } +} \ No newline at end of file diff --git a/testdata/webhooks/note_commit.json b/testdata/webhooks/note_commit.json new file mode 100644 index 000000000..c454bfced --- /dev/null +++ b/testdata/webhooks/note_commit.json @@ -0,0 +1,67 @@ +{ + "object_kind": "note", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + }, + "project_id": 5, + "project":{ + "id": 5, + "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" + } + } +} \ No newline at end of file diff --git a/testdata/webhooks/note_issue.json b/testdata/webhooks/note_issue.json new file mode 100644 index 000000000..dcb66fac3 --- /dev/null +++ b/testdata/webhooks/note_issue.json @@ -0,0 +1,64 @@ +{ + "object_kind": "note", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + }, + "project_id": 5, + "project":{ + "id": 5, + "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_ids": [], + "assignee_id": null, + "author_id": 1, + "project_id": 5, + "created_at": "2016-01-04T15:31:46.176Z", + "updated_at": "2016-01-04T15:31:46.176Z", + "position": 0, + "branch_name": null, + "description": "test", + "milestone_id": null, + "state": "closed", + "iid": 17 + } +} \ No newline at end of file diff --git a/testdata/webhooks/note_merge_request.json b/testdata/webhooks/note_merge_request.json new file mode 100644 index 000000000..d015ca5c8 --- /dev/null +++ b/testdata/webhooks/note_merge_request.json @@ -0,0 +1,114 @@ +{ + "object_kind": "note", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + }, + "project_id": 5, + "project":{ + "id": 5, + "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, + "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" + } + } +} \ No newline at end of file diff --git a/testdata/webhooks/note_snippet.json b/testdata/webhooks/note_snippet.json new file mode 100644 index 000000000..baf72bea4 --- /dev/null +++ b/testdata/webhooks/note_snippet.json @@ -0,0 +1,61 @@ +{ + "object_kind": "note", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + }, + "project_id": 5, + "project": { + "id": 5, + "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": "2016-01-04T15:31:46.176Z", + "updated_at": "2016-01-04T15:31:46.176Z", + "file_name": "test.rb", + "expires_at": null, + "type": "ProjectSnippet", + "visibility_level": 0 + } +} \ No newline at end of file diff --git a/testdata/webhooks/pipeline.json b/testdata/webhooks/pipeline.json new file mode 100644 index 000000000..efe5fd50b --- /dev/null +++ b/testdata/webhooks/pipeline.json @@ -0,0 +1,175 @@ +{ + "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, + "variables": [ + { + "key": "NESTOR_PROD_ENVIRONMENT", + "value": "us-west-1" + } + ] + }, + "user":{ + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" + }, + "project":{ + "id": 1, + "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": { + "id":380987, + "description":"shared-runners-manager-6.gitlab.com", + "active":true, + "is_shared":true + }, + "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": { + "id":380987, + "description":"shared-runners-manager-6.gitlab.com", + "active":true, + "is_shared":true + }, + "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": { + "id":380987, + "description":"shared-runners-manager-6.gitlab.com", + "active":true, + "is_shared":true + }, + "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 + } + } + ] +} \ No newline at end of file diff --git a/testdata/webhooks/push.json b/testdata/webhooks/push.json new file mode 100644 index 000000000..9abe73e8c --- /dev/null +++ b/testdata/webhooks/push.json @@ -0,0 +1,68 @@ +{ + "object_kind": "push", + "before": "95790bf891e76fee5e1747ab589903a6a1f80f22", + "after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "ref": "refs/heads/master", + "checkout_sha": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "user_id": 4, + "user_name": "John Smith", + "user_username": "jsmith", + "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":{ + "id": 15, + "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 +} \ No newline at end of file diff --git a/testdata/webhooks/tag_push.json b/testdata/webhooks/tag_push.json new file mode 100644 index 000000000..06040b952 --- /dev/null +++ b/testdata/webhooks/tag_push.json @@ -0,0 +1,39 @@ +{ + "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":{ + "id": 1, + "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 +} \ No newline at end of file diff --git a/testdata/webhooks/wiki_page.json b/testdata/webhooks/wiki_page.json new file mode 100644 index 000000000..e944c9768 --- /dev/null +++ b/testdata/webhooks/wiki_page.json @@ -0,0 +1,41 @@ +{ + "object_kind": "wiki_page", + "user": { + "name": "Administrator", + "username": "root", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon" + }, + "project": { + "id": 1, + "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" + } +} \ No newline at end of file From 8ad78d16c0363f76f630e14e4b5226c8544f5515 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Sun, 26 Jan 2020 16:42:48 +0100 Subject: [PATCH 2/2] Refactor the system hook code a little --- event_parsing.go | 203 ++++++++++-------- event_parsing_systemhook_test.go | 66 +++--- event_parsing_webhook_test.go | 2 +- event_systemhook_types.go | 63 +++--- testdata/get_merge_request.json | 1 - testdata/systemhooks/group_create.json | 2 +- testdata/systemhooks/group_destroy.json | 2 +- testdata/systemhooks/group_rename.json | 2 +- testdata/systemhooks/key_create.json | 2 +- testdata/systemhooks/key_destroy.json | 2 +- testdata/systemhooks/merge_request.json | 2 +- testdata/systemhooks/project_create.json | 2 +- testdata/systemhooks/project_destroy.json | 2 +- testdata/systemhooks/project_rename.json | 2 +- testdata/systemhooks/project_transfer.json | 2 +- testdata/systemhooks/project_update.json | 2 +- testdata/systemhooks/push.json | 2 +- testdata/systemhooks/repository_update.json | 2 +- testdata/systemhooks/tag_push.json | 2 +- testdata/systemhooks/user_add_to_group.json | 2 +- testdata/systemhooks/user_add_to_team.json | 2 +- testdata/systemhooks/user_create.json | 2 +- testdata/systemhooks/user_destroy.json | 2 +- testdata/systemhooks/user_failed_login.json | 2 +- .../systemhooks/user_remove_from_group.json | 2 +- .../systemhooks/user_remove_from_team.json | 2 +- testdata/systemhooks/user_rename.json | 2 +- .../systemhooks/user_update_for_group.json | 2 +- .../systemhooks/user_update_for_team.json | 2 +- testdata/webhooks/build.json | 2 +- testdata/webhooks/group_merge_request.json | 2 +- testdata/webhooks/issue.json | 2 +- testdata/webhooks/merge_request.json | 2 +- testdata/webhooks/note_commit.json | 2 +- testdata/webhooks/note_issue.json | 2 +- testdata/webhooks/note_merge_request.json | 2 +- testdata/webhooks/note_snippet.json | 2 +- testdata/webhooks/pipeline.json | 2 +- testdata/webhooks/push.json | 2 +- testdata/webhooks/tag_push.json | 2 +- testdata/webhooks/wiki_page.json | 2 +- 41 files changed, 217 insertions(+), 190 deletions(-) diff --git a/event_parsing.go b/event_parsing.go index 548998398..ce8c733fa 100644 --- a/event_parsing.go +++ b/event_parsing.go @@ -18,9 +18,9 @@ const ( EventTypeNote EventType = "Note Hook" EventTypePipeline EventType = "Pipeline Hook" EventTypePush EventType = "Push Hook" + EventTypeSystemHook EventType = "System Hook" EventTypeTagPush EventType = "Tag Push Hook" EventTypeWikiPage EventType = "Wiki Page Hook" - EventSystemHook EventType = "System Hook" ) const ( @@ -39,6 +39,119 @@ type noteEvent struct { const eventTypeHeader = "X-Gitlab-Event" +// HookEventType returns the event type for the given request. +func HookEventType(r *http.Request) EventType { + return EventType(r.Header.Get(eventTypeHeader)) +} + +// ParseHook tries to parse both web- and system hooks. +// +// Example usage: +// +// func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { +// payload, err := ioutil.ReadAll(r.Body) +// if err != nil { ... } +// event, err := gitlab.ParseHook(gitlab.HookEventType(r), payload) +// if err != nil { ... } +// switch event := event.(type) { +// case *gitlab.PushEvent: +// processPushEvent(event) +// case *gitlab.MergeEvent: +// processMergeEvent(event) +// ... +// } +// } +// +func ParseHook(eventType EventType, payload []byte) (event interface{}, err error) { + switch eventType { + case EventTypeSystemHook: + return ParseSystemhook(payload) + default: + return ParseWebhook(eventType, payload) + } +} + +// ParseSystemhook parses the event payload. For recognized event types, a +// value of the corresponding struct type will be returned. An error will be +// returned for unrecognized event types. +// +// Example usage: +// +// func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { +// payload, err := ioutil.ReadAll(r.Body) +// if err != nil { ... } +// event, err := gitlab.ParseSystemhook(payload) +// if err != nil { ... } +// switch event := event.(type) { +// case *gitlab.PushSystemEvent: +// processPushSystemEvent(event) +// case *gitlab.MergeSystemEvent: +// processMergeSystemEvent(event) +// ... +// } +// } +// +func ParseSystemhook(payload []byte) (event interface{}, err error) { + e := &systemHookEvent{} + err = json.Unmarshal(payload, e) + if err != nil { + return nil, err + } + + switch e.EventName { + case "push": + event = &PushSystemEvent{} + case "tag_push": + event = &TagPushSystemEvent{} + case "repository_update": + event = &RepositoryUpdateSystemEvent{} + case + "project_create", + "project_update", + "project_destroy", + "project_transfer", + "project_rename": + event = &ProjectSystemEvent{} + case + "group_create", + "group_destroy", + "group_rename": + event = &GroupSystemEvent{} + case + "key_create", + "key_destroy": + event = &KeySystemEvent{} + case + "user_create", + "user_destroy", + "user_rename": + event = &UserSystemEvent{} + case + "user_add_to_group", + "user_remove_from_group", + "user_update_for_group": + event = &UserGroupSystemEvent{} + case + "user_add_to_team", + "user_remove_from_team", + "user_update_for_team": + event = &UserTeamSystemEvent{} + default: + switch e.ObjectKind { + case "merge_request": + event = &MergeEvent{} + default: + return nil, fmt.Errorf("unexpected system hook type %s", e.EventName) + } + } + + if err := json.Unmarshal(payload, event); err != nil { + return nil, err + } + + return event, nil +} + // WebhookEventType returns the event type for the given request. func WebhookEventType(r *http.Request) EventType { return EventType(r.Header.Get(eventTypeHeader)) @@ -53,7 +166,7 @@ func WebhookEventType(r *http.Request) EventType { // func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // payload, err := ioutil.ReadAll(r.Body) // if err != nil { ... } -// event, err := gitlab.ParseWebhook(gitlab.WebhookEventType(r), payload) +// event, err := gitlab.ParseWebhook(gitlab.HookEventType(r), payload) // if err != nil { ... } // switch event := event.(type) { // case *gitlab.PushEvent: @@ -116,89 +229,3 @@ func ParseWebhook(eventType EventType, payload []byte) (event interface{}, err e return event, nil } - -// ParseSystemhook parses the System Hook event payload. For recognized event types, a -// value of the corresponding struct type will be returned. An error will -// be returned for unrecognized event types. -func ParseSystemhook(eventType EventType, payload []byte) (event interface{}, err error) { - switch eventType { - case EventSystemHook: - e := &systemHookEvent{} - err := json.Unmarshal(payload, e) - if err != nil { - return nil, err - } - - switch e.EventName { - case "push": - event = &PushSystemHookEvent{} - case "tag_push": - event = &TagPushSystemHookEvent{} - case "repository_update": - event = &RepositoryUpdateSystemHookEvent{} - case "project_create": - fallthrough - case "project_update": - fallthrough - case "project_destroy": - fallthrough - case "project_transfer": - fallthrough - case "project_rename": - event = &ProjectSystemHookEvent{} - case "group_create": - fallthrough - case "group_destroy": - fallthrough - case "group_rename": - event = &GroupSystemHookEvent{} - case "key_create": - fallthrough - case "key_destroy": - event = &KeySystemHookEvent{} - case "user_create": - fallthrough - case "user_destroy": - fallthrough - case "user_rename": - event = &UserSystemHookEvent{} - case "user_add_to_group": - fallthrough - case "user_remove_from_group": - fallthrough - case "user_update_for_group": - event = &UserGroupSystemHookEvent{} - case "user_add_to_team": - fallthrough - case "user_remove_from_team": - fallthrough - case "user_update_for_team": - event = &UserTeamSystemHookEvent{} - default: - switch e.ObjectKind { - case "merge_request": - event = &MergeEvent{} - default: - return nil, fmt.Errorf("unexpected system hook type %s", e.EventName) - } - } - - default: - return nil, fmt.Errorf("unexpected event type: %s", eventType) - } - - if err := json.Unmarshal(payload, event); err != nil { - return nil, err - } - - return event, nil -} - -// ParseHook processes both ParseWebhook & ParseSystemhook -func ParseHook(eventType EventType, payload []byte) (event interface{}, err error) { - if event, err = ParseWebhook(eventType, payload); err != nil { - event, err = ParseSystemhook(eventType, payload) - return - } - return -} diff --git a/event_parsing_systemhook_test.go b/event_parsing_systemhook_test.go index c70eb930e..8ec874ebb 100644 --- a/event_parsing_systemhook_test.go +++ b/event_parsing_systemhook_test.go @@ -9,12 +9,12 @@ import ( func TestParseSystemhookPush(t *testing.T) { payload := loadFixture("testdata/systemhooks/push.json") - parsedEvent, err := ParseSystemhook("System Hook", payload) + parsedEvent, err := ParseSystemhook(payload) if err != nil { t.Errorf("Error parsing build hook: %s", err) } - event, ok := parsedEvent.(*PushSystemHookEvent) + event, ok := parsedEvent.(*PushSystemEvent) if !ok { t.Errorf("Expected PushSystemHookEvent, but parsing produced %T", parsedEvent) } @@ -24,12 +24,12 @@ func TestParseSystemhookPush(t *testing.T) { func TestParseSystemhookTagPush(t *testing.T) { payload := loadFixture("testdata/systemhooks/tag_push.json") - parsedEvent, err := ParseSystemhook("System Hook", payload) + parsedEvent, err := ParseSystemhook(payload) if err != nil { t.Errorf("Error parsing build hook: %s", err) } - event, ok := parsedEvent.(*TagPushSystemHookEvent) + event, ok := parsedEvent.(*TagPushSystemEvent) if !ok { t.Errorf("Expected TagPushSystemHookEvent, but parsing produced %T", parsedEvent) } @@ -39,7 +39,7 @@ func TestParseSystemhookTagPush(t *testing.T) { func TestParseSystemhookMergeRequest(t *testing.T) { payload := loadFixture("testdata/systemhooks/merge_request.json") - parsedEvent, err := ParseSystemhook("System Hook", payload) + parsedEvent, err := ParseSystemhook(payload) if err != nil { t.Errorf("Error parsing build hook: %s", err) } @@ -54,12 +54,12 @@ func TestParseSystemhookMergeRequest(t *testing.T) { func TestParseSystemhookRepositoryUpdate(t *testing.T) { payload := loadFixture("testdata/systemhooks/repository_update.json") - parsedEvent, err := ParseSystemhook("System Hook", payload) + parsedEvent, err := ParseSystemhook(payload) if err != nil { t.Errorf("Error parsing build hook: %s", err) } - event, ok := parsedEvent.(*RepositoryUpdateSystemHookEvent) + event, ok := parsedEvent.(*RepositoryUpdateSystemEvent) if !ok { t.Errorf("Expected RepositoryUpdateSystemHookEvent, but parsing produced %T", parsedEvent) } @@ -77,17 +77,17 @@ func TestParseSystemhookProject(t *testing.T) { {"project_transfer", loadFixture("testdata/systemhooks/project_transfer.json")}, {"project_rename", loadFixture("testdata/systemhooks/project_rename.json")}, } - for _, tt := range tests { - t.Run(tt.event, func(t *testing.T) { - parsedEvent, err := ParseSystemhook("System Hook", tt.payload) + for _, tc := range tests { + t.Run(tc.event, func(t *testing.T) { + parsedEvent, err := ParseSystemhook(tc.payload) if err != nil { t.Errorf("Error parsing build hook: %s", err) } - event, ok := parsedEvent.(*ProjectSystemHookEvent) + event, ok := parsedEvent.(*ProjectSystemEvent) if !ok { t.Errorf("Expected ProjectSystemHookEvent, but parsing produced %T", parsedEvent) } - assert.Equal(t, tt.event, event.EventName) + assert.Equal(t, tc.event, event.EventName) }) } } @@ -101,17 +101,17 @@ func TestParseSystemhookGroup(t *testing.T) { {"group_destroy", loadFixture("testdata/systemhooks/group_destroy.json")}, {"group_rename", loadFixture("testdata/systemhooks/group_rename.json")}, } - for _, tt := range tests { - t.Run(tt.event, func(t *testing.T) { - parsedEvent, err := ParseSystemhook("System Hook", tt.payload) + for _, tc := range tests { + t.Run(tc.event, func(t *testing.T) { + parsedEvent, err := ParseSystemhook(tc.payload) if err != nil { t.Errorf("Error parsing build hook: %s", err) } - event, ok := parsedEvent.(*GroupSystemHookEvent) + event, ok := parsedEvent.(*GroupSystemEvent) if !ok { t.Errorf("Expected GroupSystemHookEvent, but parsing produced %T", parsedEvent) } - assert.Equal(t, tt.event, event.EventName) + assert.Equal(t, tc.event, event.EventName) }) } } @@ -125,17 +125,17 @@ func TestParseSystemhookUser(t *testing.T) { {"user_destroy", loadFixture("testdata/systemhooks/user_destroy.json")}, {"user_rename", loadFixture("testdata/systemhooks/user_rename.json")}, } - for _, tt := range tests { - t.Run(tt.event, func(t *testing.T) { - parsedEvent, err := ParseSystemhook("System Hook", tt.payload) + for _, tc := range tests { + t.Run(tc.event, func(t *testing.T) { + parsedEvent, err := ParseSystemhook(tc.payload) if err != nil { t.Errorf("Error parsing build hook: %s", err) } - event, ok := parsedEvent.(*UserSystemHookEvent) + event, ok := parsedEvent.(*UserSystemEvent) if !ok { t.Errorf("Expected UserSystemHookEvent, but parsing produced %T", parsedEvent) } - assert.Equal(t, tt.event, event.EventName) + assert.Equal(t, tc.event, event.EventName) }) } } @@ -149,17 +149,17 @@ func TestParseSystemhookUserGroup(t *testing.T) { {"user_remove_from_group", loadFixture("testdata/systemhooks/user_remove_from_group.json")}, {"user_update_for_group", loadFixture("testdata/systemhooks/user_update_for_group.json")}, } - for _, tt := range tests { - t.Run(tt.event, func(t *testing.T) { - parsedEvent, err := ParseSystemhook("System Hook", tt.payload) + for _, tc := range tests { + t.Run(tc.event, func(t *testing.T) { + parsedEvent, err := ParseSystemhook(tc.payload) if err != nil { t.Errorf("Error parsing build hook: %s", err) } - event, ok := parsedEvent.(*UserGroupSystemHookEvent) + event, ok := parsedEvent.(*UserGroupSystemEvent) if !ok { t.Errorf("Expected UserGroupSystemHookEvent, but parsing produced %T", parsedEvent) } - assert.Equal(t, tt.event, event.EventName) + assert.Equal(t, tc.event, event.EventName) }) } } @@ -173,17 +173,17 @@ func TestParseSystemhookUserTeam(t *testing.T) { {"user_remove_from_team", loadFixture("testdata/systemhooks/user_remove_from_team.json")}, {"user_update_for_team", loadFixture("testdata/systemhooks/user_update_for_team.json")}, } - for _, tt := range tests { - t.Run(tt.event, func(t *testing.T) { - parsedEvent, err := ParseSystemhook("System Hook", tt.payload) + for _, tc := range tests { + t.Run(tc.event, func(t *testing.T) { + parsedEvent, err := ParseSystemhook(tc.payload) if err != nil { t.Errorf("Error parsing build hook: %s", err) } - event, ok := parsedEvent.(*UserTeamSystemHookEvent) + event, ok := parsedEvent.(*UserTeamSystemEvent) if !ok { t.Errorf("Expected UserTeamSystemHookEvent, but parsing produced %T", parsedEvent) } - assert.Equal(t, tt.event, event.EventName) + assert.Equal(t, tc.event, event.EventName) }) } } @@ -193,7 +193,7 @@ func TestParseHookSystemHook(t *testing.T) { if err != nil { t.Errorf("Error parsing build hook: %s", err) } - parsedEvent2, err := ParseSystemhook("System Hook", loadFixture("testdata/systemhooks/merge_request.json")) + parsedEvent2, err := ParseSystemhook(loadFixture("testdata/systemhooks/merge_request.json")) if err != nil { t.Errorf("Error parsing build hook: %s", err) } diff --git a/event_parsing_webhook_test.go b/event_parsing_webhook_test.go index c833d8842..e73856499 100644 --- a/event_parsing_webhook_test.go +++ b/event_parsing_webhook_test.go @@ -14,7 +14,7 @@ func TestWebhookEventType(t *testing.T) { } req.Header.Set("X-Gitlab-Event", "Push Hook") - eventType := WebhookEventType(req) + eventType := HookEventType(req) if eventType != "Push Hook" { t.Errorf("WebhookEventType is %s, want %s", eventType, "Push Hook") } diff --git a/event_systemhook_types.go b/event_systemhook_types.go index 3ae66c6ad..4f3d527b5 100644 --- a/event_systemhook_types.go +++ b/event_systemhook_types.go @@ -1,27 +1,28 @@ package gitlab -// systemHookEvent is used to pre-process events to determine the right event type for System Hook events +// systemHookEvent is used to pre-process events to determine the +// system hook event type. type systemHookEvent struct { - BaseSystemHookEvent + BaseSystemEvent ObjectKind string `json:"object_kind"` } -// BaseSystemHookEvent contains System Hook's common properties +// BaseSystemEvent contains system hook's common properties. // // GitLab API docs: // https://docs.gitlab.com/ee/system_hooks/system_hooks.html -type BaseSystemHookEvent struct { +type BaseSystemEvent struct { EventName string `json:"event_name"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` } -// ProjectSystemHookEvent +// ProjectSystemEvent represents a project system event. // // GitLab API docs: // https://docs.gitlab.com/ee/system_hooks/system_hooks.html -type ProjectSystemHookEvent struct { - BaseSystemHookEvent +type ProjectSystemEvent struct { + BaseSystemEvent Name string `json:"name"` Path string `json:"path"` PathWithNamespace string `json:"path_with_namespace"` @@ -32,12 +33,12 @@ type ProjectSystemHookEvent struct { OldPathWithNamespace string `json:"old_path_with_namespace,omitempty"` } -// GroupSystemHookEvent +// GroupSystemEvent represents a group system event. // // GitLab API docs: // https://docs.gitlab.com/ee/system_hooks/system_hooks.html -type GroupSystemHookEvent struct { - BaseSystemHookEvent +type GroupSystemEvent struct { + BaseSystemEvent Name string `json:"name"` Path string `json:"path"` PathWithNamespace string `json:"full_path"` @@ -49,23 +50,23 @@ type GroupSystemHookEvent struct { OldPathWithNamespace string `json:"old_full_path,omitempty"` } -// KeySystemHookEvent +// KeySystemEvent represents a key system event. // // GitLab API docs: // https://docs.gitlab.com/ee/system_hooks/system_hooks.html -type KeySystemHookEvent struct { - BaseSystemHookEvent +type KeySystemEvent struct { + BaseSystemEvent ID int `json:"id"` Username string `json:"username"` Key string `json:"key"` } -// UserSystemHookEvent +// UserSystemEvent represents a user system event. // // GitLab API docs: // https://docs.gitlab.com/ee/system_hooks/system_hooks.html -type UserSystemHookEvent struct { - BaseSystemHookEvent +type UserSystemEvent struct { + BaseSystemEvent ID int `json:"user_id"` Name string `json:"name"` Username string `json:"username"` @@ -73,12 +74,12 @@ type UserSystemHookEvent struct { Email string `json:"email"` } -// UserGroupSystemHookEvent +// UserGroupSystemEvent represents a user group system event. // // GitLab API docs: // https://docs.gitlab.com/ee/system_hooks/system_hooks.html -type UserGroupSystemHookEvent struct { - BaseSystemHookEvent +type UserGroupSystemEvent struct { + BaseSystemEvent ID int `json:"user_id"` Name string `json:"user_name"` Username string `json:"user_username"` @@ -89,12 +90,12 @@ type UserGroupSystemHookEvent struct { GroupAccess string `json:"group_access"` } -// UserTeamSystemHookEvent +// UserTeamSystemEvent represents a user team system event. // // GitLab API docs: // https://docs.gitlab.com/ee/system_hooks/system_hooks.html -type UserTeamSystemHookEvent struct { - BaseSystemHookEvent +type UserTeamSystemEvent struct { + BaseSystemEvent ID int `json:"user_id"` Name string `json:"user_name"` Username string `json:"user_username"` @@ -107,26 +108,26 @@ type UserTeamSystemHookEvent struct { AccessLevel string `json:"access_level"` } -// PushSystemHookEvent +// PushSystemEvent represents a push system event. // // GitLab API docs: // https://docs.gitlab.com/ee/system_hooks/system_hooks.html -type PushSystemHookEvent struct { - BaseSystemHookEvent +type PushSystemEvent struct { + BaseSystemEvent } -// TagPushSystemHookEvent +// TagPushSystemEvent represents a tag push system event. // // GitLab API docs: // https://docs.gitlab.com/ee/system_hooks/system_hooks.html -type TagPushSystemHookEvent struct { - BaseSystemHookEvent +type TagPushSystemEvent struct { + BaseSystemEvent } -// RepositoryUpdateSystemHookEvent +// RepositoryUpdateSystemEvent represents a repository updated system event. // // GitLab API docs: // https://docs.gitlab.com/ee/system_hooks/system_hooks.html -type RepositoryUpdateSystemHookEvent struct { - BaseSystemHookEvent +type RepositoryUpdateSystemEvent struct { + BaseSystemEvent } diff --git a/testdata/get_merge_request.json b/testdata/get_merge_request.json index 2434efa98..3c1a503d4 100644 --- a/testdata/get_merge_request.json +++ b/testdata/get_merge_request.json @@ -1,4 +1,3 @@ - { "id": 33092005, "iid": 14656, diff --git a/testdata/systemhooks/group_create.json b/testdata/systemhooks/group_create.json index ecc220599..a54c0ed5c 100644 --- a/testdata/systemhooks/group_create.json +++ b/testdata/systemhooks/group_create.json @@ -7,4 +7,4 @@ "owner_name": null, "path": "storecloud", "group_id": 78 -} \ No newline at end of file +} diff --git a/testdata/systemhooks/group_destroy.json b/testdata/systemhooks/group_destroy.json index 62ec7bb26..396f3e0bc 100644 --- a/testdata/systemhooks/group_destroy.json +++ b/testdata/systemhooks/group_destroy.json @@ -7,4 +7,4 @@ "owner_name": null, "path": "storecloud", "group_id": 78 -} \ No newline at end of file +} diff --git a/testdata/systemhooks/group_rename.json b/testdata/systemhooks/group_rename.json index 93852f7a7..f1c010de3 100644 --- a/testdata/systemhooks/group_rename.json +++ b/testdata/systemhooks/group_rename.json @@ -10,4 +10,4 @@ "owner_email": null, "old_path": "old-name", "old_full_path": "parent-group/old-name" -} \ No newline at end of file +} diff --git a/testdata/systemhooks/key_create.json b/testdata/systemhooks/key_create.json index bd0481f89..4bcb5c930 100644 --- a/testdata/systemhooks/key_create.json +++ b/testdata/systemhooks/key_create.json @@ -5,4 +5,4 @@ "username": "root", "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC58FwqHUbebw2SdT7SP4FxZ0w+lAO/erhy2ylhlcW/tZ3GY3mBu9VeeiSGoGz8hCx80Zrz+aQv28xfFfKlC8XQFpCWwsnWnQqO2Lv9bS8V1fIHgMxOHIt5Vs+9CAWGCCvUOAurjsUDoE2ALIXLDMKnJxcxD13XjWdK54j6ZXDB4syLF0C2PnAQSVY9X7MfCYwtuFmhQhKaBussAXpaVMRHltie3UYSBUUuZaB3J4cg/7TxlmxcNd+ppPRIpSZAB0NI6aOnqoBCpimscO/VpQRJMVLr3XiSYeT6HBiDXWHnIVPfQc03OGcaFqOit6p8lYKMaP/iUQLm+pgpZqrXZ9vB john@localhost", "id": 4 -} \ No newline at end of file +} diff --git a/testdata/systemhooks/key_destroy.json b/testdata/systemhooks/key_destroy.json index 6b6a16119..f85f9f952 100644 --- a/testdata/systemhooks/key_destroy.json +++ b/testdata/systemhooks/key_destroy.json @@ -5,4 +5,4 @@ "username": "root", "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC58FwqHUbebw2SdT7SP4FxZ0w+lAO/erhy2ylhlcW/tZ3GY3mBu9VeeiSGoGz8hCx80Zrz+aQv28xfFfKlC8XQFpCWwsnWnQqO2Lv9bS8V1fIHgMxOHIt5Vs+9CAWGCCvUOAurjsUDoE2ALIXLDMKnJxcxD13XjWdK54j6ZXDB4syLF0C2PnAQSVY9X7MfCYwtuFmhQhKaBussAXpaVMRHltie3UYSBUUuZaB3J4cg/7TxlmxcNd+ppPRIpSZAB0NI6aOnqoBCpimscO/VpQRJMVLr3XiSYeT6HBiDXWHnIVPfQc03OGcaFqOit6p8lYKMaP/iUQLm+pgpZqrXZ9vB john@localhost", "id": 4 -} \ No newline at end of file +} diff --git a/testdata/systemhooks/merge_request.json b/testdata/systemhooks/merge_request.json index ea05ad89e..94307a692 100644 --- a/testdata/systemhooks/merge_request.json +++ b/testdata/systemhooks/merge_request.json @@ -111,4 +111,4 @@ "description": "", "homepage": "http://example.com/awesome_space/awesome_project" } -} \ No newline at end of file +} diff --git a/testdata/systemhooks/project_create.json b/testdata/systemhooks/project_create.json index a5280a058..ec0c050e2 100644 --- a/testdata/systemhooks/project_create.json +++ b/testdata/systemhooks/project_create.json @@ -9,4 +9,4 @@ "path_with_namespace": "jsmith/storecloud", "project_id": 74, "project_visibility": "private" -} \ No newline at end of file +} diff --git a/testdata/systemhooks/project_destroy.json b/testdata/systemhooks/project_destroy.json index e39a84671..e6189a9c6 100644 --- a/testdata/systemhooks/project_destroy.json +++ b/testdata/systemhooks/project_destroy.json @@ -9,4 +9,4 @@ "path_with_namespace": "jsmith/underscore", "project_id": 73, "project_visibility": "internal" -} \ No newline at end of file +} diff --git a/testdata/systemhooks/project_rename.json b/testdata/systemhooks/project_rename.json index aac40bbc5..e73b717ff 100644 --- a/testdata/systemhooks/project_rename.json +++ b/testdata/systemhooks/project_rename.json @@ -10,4 +10,4 @@ "owner_email": "johnsmith@gmail.com", "project_visibility": "internal", "old_path_with_namespace": "jsmith/overscore" -} \ No newline at end of file +} diff --git a/testdata/systemhooks/project_transfer.json b/testdata/systemhooks/project_transfer.json index 488cfae50..0963a01bd 100644 --- a/testdata/systemhooks/project_transfer.json +++ b/testdata/systemhooks/project_transfer.json @@ -10,4 +10,4 @@ "owner_email": "johnsmith@gmail.com", "project_visibility": "internal", "old_path_with_namespace": "jsmith/overscore" -} \ No newline at end of file +} diff --git a/testdata/systemhooks/project_update.json b/testdata/systemhooks/project_update.json index 7dd95f218..2ce7e7065 100644 --- a/testdata/systemhooks/project_update.json +++ b/testdata/systemhooks/project_update.json @@ -9,4 +9,4 @@ "path_with_namespace": "jsmith/storecloud", "project_id": 74, "project_visibility": "private" -} \ No newline at end of file +} diff --git a/testdata/systemhooks/push.json b/testdata/systemhooks/push.json index 8eb7be171..f28ce97b3 100644 --- a/testdata/systemhooks/push.json +++ b/testdata/systemhooks/push.json @@ -47,4 +47,4 @@ } ], "total_commits_count": 1 -} \ No newline at end of file +} diff --git a/testdata/systemhooks/repository_update.json b/testdata/systemhooks/repository_update.json index ecc69fbe7..7dfcf3f57 100644 --- a/testdata/systemhooks/repository_update.json +++ b/testdata/systemhooks/repository_update.json @@ -29,4 +29,4 @@ } ], "refs":["refs/heads/master"] -} \ No newline at end of file +} diff --git a/testdata/systemhooks/tag_push.json b/testdata/systemhooks/tag_push.json index 0b4224faa..96064104a 100644 --- a/testdata/systemhooks/tag_push.json +++ b/testdata/systemhooks/tag_push.json @@ -35,4 +35,4 @@ }, "commits": [], "total_commits_count": 0 -} \ No newline at end of file +} diff --git a/testdata/systemhooks/user_add_to_group.json b/testdata/systemhooks/user_add_to_group.json index 8f07c9f6d..1330d44ca 100644 --- a/testdata/systemhooks/user_add_to_group.json +++ b/testdata/systemhooks/user_add_to_group.json @@ -10,4 +10,4 @@ "user_name": "John Smith", "user_username": "johnsmith", "user_id": 41 -} \ No newline at end of file +} diff --git a/testdata/systemhooks/user_add_to_team.json b/testdata/systemhooks/user_add_to_team.json index 74ee8353d..b320cdb58 100644 --- a/testdata/systemhooks/user_add_to_team.json +++ b/testdata/systemhooks/user_add_to_team.json @@ -12,4 +12,4 @@ "user_username": "johnsmith", "user_id": 41, "project_visibility": "visibilitylevel|private" -} \ No newline at end of file +} diff --git a/testdata/systemhooks/user_create.json b/testdata/systemhooks/user_create.json index 289ea9f2b..ede85e1df 100644 --- a/testdata/systemhooks/user_create.json +++ b/testdata/systemhooks/user_create.json @@ -6,4 +6,4 @@ "name": "John Smith", "username": "js", "user_id": 41 -} \ No newline at end of file +} diff --git a/testdata/systemhooks/user_destroy.json b/testdata/systemhooks/user_destroy.json index cf07b2e0a..b1a9a1600 100644 --- a/testdata/systemhooks/user_destroy.json +++ b/testdata/systemhooks/user_destroy.json @@ -6,4 +6,4 @@ "name": "John Smith", "username": "js", "user_id": 41 -} \ No newline at end of file +} diff --git a/testdata/systemhooks/user_failed_login.json b/testdata/systemhooks/user_failed_login.json index 5ab3cd503..358988939 100644 --- a/testdata/systemhooks/user_failed_login.json +++ b/testdata/systemhooks/user_failed_login.json @@ -7,4 +7,4 @@ "user_id": 26, "username": "user4", "state": "blocked" -} \ No newline at end of file +} diff --git a/testdata/systemhooks/user_remove_from_group.json b/testdata/systemhooks/user_remove_from_group.json index 951e5ac32..9010bb4fa 100644 --- a/testdata/systemhooks/user_remove_from_group.json +++ b/testdata/systemhooks/user_remove_from_group.json @@ -10,4 +10,4 @@ "user_name": "John Smith", "user_username": "johnsmith", "user_id": 41 -} \ No newline at end of file +} diff --git a/testdata/systemhooks/user_remove_from_team.json b/testdata/systemhooks/user_remove_from_team.json index 386835b57..f42c9f908 100644 --- a/testdata/systemhooks/user_remove_from_team.json +++ b/testdata/systemhooks/user_remove_from_team.json @@ -12,4 +12,4 @@ "user_username": "johnsmith", "user_id": 41, "project_visibility": "visibilitylevel|private" -} \ No newline at end of file +} diff --git a/testdata/systemhooks/user_rename.json b/testdata/systemhooks/user_rename.json index e64e06711..e6de4420a 100644 --- a/testdata/systemhooks/user_rename.json +++ b/testdata/systemhooks/user_rename.json @@ -7,4 +7,4 @@ "user_id": 58, "username": "new-exciting-name", "old_username": "old-boring-name" -} \ No newline at end of file +} diff --git a/testdata/systemhooks/user_update_for_group.json b/testdata/systemhooks/user_update_for_group.json index 44dfd0f27..e24f11b71 100644 --- a/testdata/systemhooks/user_update_for_group.json +++ b/testdata/systemhooks/user_update_for_group.json @@ -10,4 +10,4 @@ "user_name": "John Smith", "user_username": "johnsmith", "user_id": 41 -} \ No newline at end of file +} diff --git a/testdata/systemhooks/user_update_for_team.json b/testdata/systemhooks/user_update_for_team.json index 28dd18772..92543edef 100644 --- a/testdata/systemhooks/user_update_for_team.json +++ b/testdata/systemhooks/user_update_for_team.json @@ -12,4 +12,4 @@ "user_username": "johnsmith", "user_id": 41, "project_visibility": "visibilitylevel|private" -} \ No newline at end of file +} diff --git a/testdata/webhooks/build.json b/testdata/webhooks/build.json index 546dfd4ee..43eec004b 100644 --- a/testdata/webhooks/build.json +++ b/testdata/webhooks/build.json @@ -39,4 +39,4 @@ "git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git", "visibility_level": 20 } -} \ No newline at end of file +} diff --git a/testdata/webhooks/group_merge_request.json b/testdata/webhooks/group_merge_request.json index 7220709ff..688cb453f 100644 --- a/testdata/webhooks/group_merge_request.json +++ b/testdata/webhooks/group_merge_request.json @@ -110,4 +110,4 @@ "username": "root", "avatar_url": "http://www.gravatar.com/avatar/d22738dc40839e3d95fca77ca3eac067?s=80\u0026d=identicon" } -} \ No newline at end of file +} diff --git a/testdata/webhooks/issue.json b/testdata/webhooks/issue.json index 98eeafda6..0dbfcc5b8 100644 --- a/testdata/webhooks/issue.json +++ b/testdata/webhooks/issue.json @@ -104,4 +104,4 @@ }] } } -} \ No newline at end of file +} diff --git a/testdata/webhooks/merge_request.json b/testdata/webhooks/merge_request.json index 144c0a098..f7d051e37 100644 --- a/testdata/webhooks/merge_request.json +++ b/testdata/webhooks/merge_request.json @@ -143,4 +143,4 @@ }] } } -} \ No newline at end of file +} diff --git a/testdata/webhooks/note_commit.json b/testdata/webhooks/note_commit.json index c454bfced..6aaf6e334 100644 --- a/testdata/webhooks/note_commit.json +++ b/testdata/webhooks/note_commit.json @@ -64,4 +64,4 @@ "email": "dmitriy.zaporozhets@gmail.com" } } -} \ No newline at end of file +} diff --git a/testdata/webhooks/note_issue.json b/testdata/webhooks/note_issue.json index dcb66fac3..eeccaa53c 100644 --- a/testdata/webhooks/note_issue.json +++ b/testdata/webhooks/note_issue.json @@ -61,4 +61,4 @@ "state": "closed", "iid": 17 } -} \ No newline at end of file +} diff --git a/testdata/webhooks/note_merge_request.json b/testdata/webhooks/note_merge_request.json index d015ca5c8..16f438fc2 100644 --- a/testdata/webhooks/note_merge_request.json +++ b/testdata/webhooks/note_merge_request.json @@ -111,4 +111,4 @@ "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" } } -} \ No newline at end of file +} diff --git a/testdata/webhooks/note_snippet.json b/testdata/webhooks/note_snippet.json index baf72bea4..6c8d2d1c4 100644 --- a/testdata/webhooks/note_snippet.json +++ b/testdata/webhooks/note_snippet.json @@ -58,4 +58,4 @@ "type": "ProjectSnippet", "visibility_level": 0 } -} \ No newline at end of file +} diff --git a/testdata/webhooks/pipeline.json b/testdata/webhooks/pipeline.json index efe5fd50b..5ebad70a5 100644 --- a/testdata/webhooks/pipeline.json +++ b/testdata/webhooks/pipeline.json @@ -172,4 +172,4 @@ } } ] -} \ No newline at end of file +} diff --git a/testdata/webhooks/push.json b/testdata/webhooks/push.json index 9abe73e8c..6e699054e 100644 --- a/testdata/webhooks/push.json +++ b/testdata/webhooks/push.json @@ -65,4 +65,4 @@ } ], "total_commits_count": 4 -} \ No newline at end of file +} diff --git a/testdata/webhooks/tag_push.json b/testdata/webhooks/tag_push.json index 06040b952..32dc1a3f4 100644 --- a/testdata/webhooks/tag_push.json +++ b/testdata/webhooks/tag_push.json @@ -36,4 +36,4 @@ }, "commits": [], "total_commits_count": 0 -} \ No newline at end of file +} diff --git a/testdata/webhooks/wiki_page.json b/testdata/webhooks/wiki_page.json index e944c9768..839d4c19f 100644 --- a/testdata/webhooks/wiki_page.json +++ b/testdata/webhooks/wiki_page.json @@ -38,4 +38,4 @@ "url": "http://example.com/root/awesome-project/wikis/awesome", "action": "create" } -} \ No newline at end of file +}