Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c271ec3e32 | |||
| 0c4911f7f5 | |||
| 3667088d60 | |||
| 9cafa895ff |
@@ -80,10 +80,14 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
webhooks.DefaultLog.Debug(fmt.Sprintf("X-Hook-UUID:%s", uuid))
|
webhooks.DefaultLog.Debug(fmt.Sprintf("X-Hook-UUID:%s", uuid))
|
||||||
|
|
||||||
if uuid != hook.uuid {
|
if len(hook.uuid) > 0 {
|
||||||
webhooks.DefaultLog.Error(fmt.Sprintf("X-Hook-UUID does not match configured uuid of %s", hook.uuid))
|
if uuid != hook.uuid {
|
||||||
http.Error(w, "403 Forbidden - X-Hook-UUID does not match", http.StatusForbidden)
|
webhooks.DefaultLog.Error(fmt.Sprintf("X-Hook-UUID %s does not match configured uuid of %s", uuid, hook.uuid))
|
||||||
return
|
http.Error(w, "403 Forbidden - X-Hook-UUID does not match", http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
webhooks.DefaultLog.Debug("hook uuid not defined - recommend setting for improved security")
|
||||||
}
|
}
|
||||||
|
|
||||||
event := r.Header.Get("X-Event-Key")
|
event := r.Header.Get("X-Event-Key")
|
||||||
|
|||||||
+129
-66
@@ -807,82 +807,145 @@ func TestCommentSunippetEvent(t *testing.T) {
|
|||||||
func TestMergeRequestEvent(t *testing.T) {
|
func TestMergeRequestEvent(t *testing.T) {
|
||||||
|
|
||||||
payload := `{
|
payload := `{
|
||||||
"object_kind": "merge_request",
|
"object_kind": "merge_request",
|
||||||
"user": {
|
"user": {
|
||||||
"name": "Administrator",
|
"name": "Administrator",
|
||||||
"username": "root",
|
"username": "root",
|
||||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||||
},
|
|
||||||
"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",
|
|
||||||
"st_commits": null,
|
|
||||||
"st_diffs": null,
|
|
||||||
"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": {
|
"project": {
|
||||||
"name":"Awesome Project",
|
"id": 1,
|
||||||
|
"name":"Gitlab Test",
|
||||||
"description":"Aut reprehenderit ut est.",
|
"description":"Aut reprehenderit ut est.",
|
||||||
"web_url":"http://example.com/awesome_space/awesome_project",
|
"web_url":"http://example.com/gitlabhq/gitlab-test",
|
||||||
"avatar_url":null,
|
"avatar_url":null,
|
||||||
"git_ssh_url":"git@example.com:awesome_space/awesome_project.git",
|
"git_ssh_url":"git@example.com:gitlabhq/gitlab-test.git",
|
||||||
"git_http_url":"http://example.com/awesome_space/awesome_project.git",
|
"git_http_url":"http://example.com/gitlabhq/gitlab-test.git",
|
||||||
"namespace":"Awesome Space",
|
"namespace":"GitlabHQ",
|
||||||
"visibility_level":20,
|
"visibility_level":20,
|
||||||
"path_with_namespace":"awesome_space/awesome_project",
|
"path_with_namespace":"gitlabhq/gitlab-test",
|
||||||
"default_branch":"master",
|
"default_branch":"master",
|
||||||
"homepage":"http://example.com/awesome_space/awesome_project",
|
"homepage":"http://example.com/gitlabhq/gitlab-test",
|
||||||
"url":"http://example.com/awesome_space/awesome_project.git",
|
"url":"http://example.com/gitlabhq/gitlab-test.git",
|
||||||
"ssh_url":"git@example.com:awesome_space/awesome_project.git",
|
"ssh_url":"git@example.com:gitlabhq/gitlab-test.git",
|
||||||
"http_url":"http://example.com/awesome_space/awesome_project.git"
|
"http_url":"http://example.com/gitlabhq/gitlab-test.git"
|
||||||
},
|
},
|
||||||
"last_commit": {
|
"repository": {
|
||||||
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
"name": "Gitlab Test",
|
||||||
"message": "fixed readme",
|
"url": "http://example.com/gitlabhq/gitlab-test.git",
|
||||||
"timestamp": "2012-01-03T23:36:29+02:00",
|
"description": "Aut reprehenderit ut est.",
|
||||||
"url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
"homepage": "http://example.com/gitlabhq/gitlab-test"
|
||||||
"author": {
|
},
|
||||||
"name": "GitLab dev user",
|
"object_attributes": {
|
||||||
"email": "gitlabdev@dv6700.(none)"
|
"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"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"work_in_progress": false,
|
"labels": [{
|
||||||
"url": "http://example.com/diaspora/merge_requests/1",
|
"id": 206,
|
||||||
"action": "open",
|
"title": "API",
|
||||||
"assignee": {
|
"color": "#ffffff",
|
||||||
"name": "User1",
|
"project_id": 14,
|
||||||
"username": "user1",
|
"created_at": "2013-12-03T17:15:43Z",
|
||||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
"updated_at": "2013-12-03T17:15:43Z",
|
||||||
|
"template": false,
|
||||||
|
"description": "API related issues",
|
||||||
|
"type": "ProjectLabel",
|
||||||
|
"group_id": 41
|
||||||
|
}],
|
||||||
|
"changes": {
|
||||||
|
"updated_by_id": [null, 1],
|
||||||
|
"updated_at": ["2017-09-15 16:50:55 UTC", "2017-09-15 16:52:00 UTC"],
|
||||||
|
"labels": {
|
||||||
|
"previous": [{
|
||||||
|
"id": 206,
|
||||||
|
"title": "API",
|
||||||
|
"color": "#ffffff",
|
||||||
|
"project_id": 14,
|
||||||
|
"created_at": "2013-12-03T17:15:43Z",
|
||||||
|
"updated_at": "2013-12-03T17:15:43Z",
|
||||||
|
"template": false,
|
||||||
|
"description": "API related issues",
|
||||||
|
"type": "ProjectLabel",
|
||||||
|
"group_id": 41
|
||||||
|
}],
|
||||||
|
"current": [{
|
||||||
|
"id": 205,
|
||||||
|
"title": "Platform",
|
||||||
|
"color": "#123123",
|
||||||
|
"project_id": 14,
|
||||||
|
"created_at": "2013-12-03T17:15:43Z",
|
||||||
|
"updated_at": "2013-12-03T17:15:43Z",
|
||||||
|
"template": false,
|
||||||
|
"description": "Platform related issues",
|
||||||
|
"type": "ProjectLabel",
|
||||||
|
"group_id": 41
|
||||||
|
}]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
`
|
`
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3011/webhooks", bytes.NewBuffer([]byte(payload)))
|
req, err := http.NewRequest("POST", "http://127.0.0.1:3011/webhooks", bytes.NewBuffer([]byte(payload)))
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ type MergeRequestEventPayload struct {
|
|||||||
User User `json:"user"`
|
User User `json:"user"`
|
||||||
ObjectAttributes ObjectAttributes `json:"object_attributes"`
|
ObjectAttributes ObjectAttributes `json:"object_attributes"`
|
||||||
Changes Changes `json:"changes"`
|
Changes Changes `json:"changes"`
|
||||||
|
Project Project `json:"project"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PushEventPayload contains the information for GitLab's push event
|
// PushEventPayload contains the information for GitLab's push event
|
||||||
|
|||||||
Reference in New Issue
Block a user