Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f2acbcde40 | |||
| 3ad83a882d | |||
| 32331e68eb | |||
| 1253715fd8 | |||
| 1b6492ce45 | |||
| ea44f6921c | |||
| b6e930d373 | |||
| c271ec3e32 | |||
| 0c4911f7f5 | |||
| 3667088d60 | |||
| 9cafa895ff |
@@ -1,6 +1,6 @@
|
|||||||
Library webhooks
|
Library webhooks
|
||||||
================
|
================
|
||||||
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v3/logo.png">
|
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v3/logo.png">
|
||||||
[](https://travis-ci.org/go-playground/webhooks)
|
[](https://travis-ci.org/go-playground/webhooks)
|
||||||
[](https://coveralls.io/github/go-playground/webhooks?branch=v3)
|
[](https://coveralls.io/github/go-playground/webhooks?branch=v3)
|
||||||
[](https://goreportcard.com/report/go-playground/webhooks)
|
[](https://goreportcard.com/report/go-playground/webhooks)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const (
|
|||||||
PullRequestDeclinedEvent Event = "pullrequest:rejected"
|
PullRequestDeclinedEvent Event = "pullrequest:rejected"
|
||||||
PullRequestCommentCreatedEvent Event = "pullrequest:comment_created"
|
PullRequestCommentCreatedEvent Event = "pullrequest:comment_created"
|
||||||
PullRequestCommentUpdatedEvent Event = "pullrequest:comment_updated"
|
PullRequestCommentUpdatedEvent Event = "pullrequest:comment_updated"
|
||||||
PullRequestCommentDeletedEvent Event = "pull_request:comment_deleted"
|
PullRequestCommentDeletedEvent Event = "pullrequest:comment_deleted"
|
||||||
)
|
)
|
||||||
|
|
||||||
// New creates and returns a WebHook instance denoted by the Provider type
|
// New creates and returns a WebHook instance denoted by the Provider type
|
||||||
@@ -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")
|
||||||
|
|||||||
+33
-14
@@ -2759,20 +2759,39 @@ type PullRequestPayload struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
SiteAdmin bool `json:"site_admin"`
|
SiteAdmin bool `json:"site_admin"`
|
||||||
} `json:"user"`
|
} `json:"user"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
ClosedAt *time.Time `json:"closed_at"`
|
ClosedAt *time.Time `json:"closed_at"`
|
||||||
MergedAt *time.Time `json:"merged_at"`
|
MergedAt *time.Time `json:"merged_at"`
|
||||||
MergeCommitSha *string `json:"merge_commit_sha"`
|
MergeCommitSha *string `json:"merge_commit_sha"`
|
||||||
Assignee *Assignee `json:"assignee"`
|
Assignee *Assignee `json:"assignee"`
|
||||||
Milestone *Milestone `json:"milestone"`
|
Milestone *Milestone `json:"milestone"`
|
||||||
CommitsURL string `json:"commits_url"`
|
CommitsURL string `json:"commits_url"`
|
||||||
ReviewCommentsURL string `json:"review_comments_url"`
|
ReviewCommentsURL string `json:"review_comments_url"`
|
||||||
ReviewCommentURL string `json:"review_comment_url"`
|
ReviewCommentURL string `json:"review_comment_url"`
|
||||||
CommentsURL string `json:"comments_url"`
|
CommentsURL string `json:"comments_url"`
|
||||||
StatusesURL string `json:"statuses_url"`
|
StatusesURL string `json:"statuses_url"`
|
||||||
Head struct {
|
RequestedReviewers []struct {
|
||||||
|
Login string `json:"login"`
|
||||||
|
ID int `json:"id"`
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
GravatarID string `json:"gravatar_id"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
|
FollowersURL string `json:"followers_url"`
|
||||||
|
FollowingURL string `json:"following_url"`
|
||||||
|
GistsURL string `json:"gists_url"`
|
||||||
|
StarredURL string `json:"starred_url"`
|
||||||
|
SubscriptionsURL string `json:"subscriptions_url"`
|
||||||
|
OrganizationsURL string `json:"organizations_url"`
|
||||||
|
ReposURL string `json:"repos_url"`
|
||||||
|
EventsURL string `json:"events_url"`
|
||||||
|
ReceivedEventsURL string `json:"received_events_url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
SiteAdmin bool `json:"site_admin"`
|
||||||
|
} `json:"requested_reviewers,omitempty"`
|
||||||
|
Head struct {
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
Ref string `json:"ref"`
|
Ref string `json:"ref"`
|
||||||
Sha string `json:"sha"`
|
Sha string `json:"sha"`
|
||||||
|
|||||||
+130
-67
@@ -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