Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c26dda1ff8 | |||
| 993ec330d3 |
@@ -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)
|
||||||
|
|||||||
@@ -2940,13 +2940,6 @@ type PullRequestPayload struct {
|
|||||||
Deletions int64 `json:"deletions"`
|
Deletions int64 `json:"deletions"`
|
||||||
ChangedFiles int64 `json:"changed_files"`
|
ChangedFiles int64 `json:"changed_files"`
|
||||||
} `json:"pull_request"`
|
} `json:"pull_request"`
|
||||||
Label struct {
|
|
||||||
ID int64 `json:"id"`
|
|
||||||
URL string `json:"url"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Color string `json:"color"`
|
|
||||||
Default bool `json:"default"`
|
|
||||||
} `json:"label"`
|
|
||||||
Repository struct {
|
Repository struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ const (
|
|||||||
PushEvents Event = "Push Hook"
|
PushEvents Event = "Push Hook"
|
||||||
TagEvents Event = "Tag Push Hook"
|
TagEvents Event = "Tag Push Hook"
|
||||||
IssuesEvents Event = "Issue Hook"
|
IssuesEvents Event = "Issue Hook"
|
||||||
ConfidentialIssuesEvents Event = "Confidential Issue Hook"
|
|
||||||
CommentEvents Event = "Note Hook"
|
CommentEvents Event = "Note Hook"
|
||||||
MergeRequestEvents Event = "Merge Request Hook"
|
MergeRequestEvents Event = "Merge Request Hook"
|
||||||
WikiPageEvents Event = "Wiki Page Hook"
|
WikiPageEvents Event = "Wiki Page Hook"
|
||||||
@@ -113,11 +112,6 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
|
|||||||
json.Unmarshal([]byte(payload), &te)
|
json.Unmarshal([]byte(payload), &te)
|
||||||
hook.runProcessPayloadFunc(fn, te, hd)
|
hook.runProcessPayloadFunc(fn, te, hd)
|
||||||
|
|
||||||
case ConfidentialIssuesEvents:
|
|
||||||
var cie ConfidentialIssueEventPayload
|
|
||||||
json.Unmarshal([]byte(payload), &cie)
|
|
||||||
hook.runProcessPayloadFunc(fn, cie, hd)
|
|
||||||
|
|
||||||
case IssuesEvents:
|
case IssuesEvents:
|
||||||
var ie IssueEventPayload
|
var ie IssueEventPayload
|
||||||
json.Unmarshal([]byte(payload), &ie)
|
json.Unmarshal([]byte(payload), &ie)
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ func TestMain(m *testing.M) {
|
|||||||
PushEvents,
|
PushEvents,
|
||||||
TagEvents,
|
TagEvents,
|
||||||
IssuesEvents,
|
IssuesEvents,
|
||||||
ConfidentialIssuesEvents,
|
|
||||||
CommentEvents,
|
CommentEvents,
|
||||||
MergeRequestEvents,
|
MergeRequestEvents,
|
||||||
WikiPageEvents,
|
WikiPageEvents,
|
||||||
@@ -350,78 +349,6 @@ func TestIssueEvent(t *testing.T) {
|
|||||||
Equal(t, resp.StatusCode, http.StatusOK)
|
Equal(t, resp.StatusCode, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfidentialIssueEvent(t *testing.T) {
|
|
||||||
|
|
||||||
payload := `{
|
|
||||||
"object_kind": "issue",
|
|
||||||
"user": {
|
|
||||||
"name": "Administrator",
|
|
||||||
"username": "root",
|
|
||||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
|
||||||
},
|
|
||||||
"project":{
|
|
||||||
"name":"Gitlab Test",
|
|
||||||
"description":"Aut reprehenderit ut est.",
|
|
||||||
"web_url":"http://example.com/gitlabhq/gitlab-test",
|
|
||||||
"avatar_url":null,
|
|
||||||
"git_ssh_url":"git@example.com:gitlabhq/gitlab-test.git",
|
|
||||||
"git_http_url":"http://example.com/gitlabhq/gitlab-test.git",
|
|
||||||
"namespace":"GitlabHQ",
|
|
||||||
"visibility_level":20,
|
|
||||||
"path_with_namespace":"gitlabhq/gitlab-test",
|
|
||||||
"default_branch":"master",
|
|
||||||
"homepage":"http://example.com/gitlabhq/gitlab-test",
|
|
||||||
"url":"http://example.com/gitlabhq/gitlab-test.git",
|
|
||||||
"ssh_url":"git@example.com:gitlabhq/gitlab-test.git",
|
|
||||||
"http_url":"http://example.com/gitlabhq/gitlab-test.git"
|
|
||||||
},
|
|
||||||
"repository":{
|
|
||||||
"name": "Gitlab Test",
|
|
||||||
"url": "http://example.com/gitlabhq/gitlab-test.git",
|
|
||||||
"description": "Aut reprehenderit ut est.",
|
|
||||||
"homepage": "http://example.com/gitlabhq/gitlab-test"
|
|
||||||
},
|
|
||||||
"object_attributes": {
|
|
||||||
"id": 301,
|
|
||||||
"title": "New API: create/update/delete file",
|
|
||||||
"assignee_id": 51,
|
|
||||||
"author_id": 51,
|
|
||||||
"project_id": 14,
|
|
||||||
"created_at": "2013-12-03T17:15:43Z",
|
|
||||||
"updated_at": "2013-12-03T17:15:43Z",
|
|
||||||
"position": 0,
|
|
||||||
"branch_name": null,
|
|
||||||
"description": "Create new API for manipulations with repository",
|
|
||||||
"milestone_id": null,
|
|
||||||
"state": "opened",
|
|
||||||
"iid": 23,
|
|
||||||
"url": "http://example.com/diaspora/issues/23",
|
|
||||||
"action": "open"
|
|
||||||
},
|
|
||||||
"assignee": {
|
|
||||||
"name": "User1",
|
|
||||||
"username": "user1",
|
|
||||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "http://127.0.0.1:3011/webhooks", bytes.NewBuffer([]byte(payload)))
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
req.Header.Set("X-Gitlab-Event", "Confidential Issue Hook")
|
|
||||||
req.Header.Set("X-Gitlab-Token", "sampleToken!")
|
|
||||||
|
|
||||||
Equal(t, err, nil)
|
|
||||||
|
|
||||||
client := &http.Client{}
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
Equal(t, err, nil)
|
|
||||||
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
Equal(t, resp.StatusCode, http.StatusOK)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCommentCommitEvent(t *testing.T) {
|
func TestCommentCommitEvent(t *testing.T) {
|
||||||
|
|
||||||
payload := `{
|
payload := `{
|
||||||
|
|||||||
+1
-8
@@ -40,13 +40,6 @@ type IssueEventPayload struct {
|
|||||||
Assignee Assignee `json:"assignee"`
|
Assignee Assignee `json:"assignee"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfidentialIssueEventPayload contains the information for GitLab's confidential issue event
|
|
||||||
type ConfidentialIssueEventPayload struct {
|
|
||||||
// The data for confidential issues is currently the same as normal issues,
|
|
||||||
// so we can just embed the normal issue payload type here.
|
|
||||||
IssueEventPayload
|
|
||||||
}
|
|
||||||
|
|
||||||
// MergeRequestEventPayload contains the information for GitLab's merge request event
|
// MergeRequestEventPayload contains the information for GitLab's merge request event
|
||||||
type MergeRequestEventPayload struct {
|
type MergeRequestEventPayload struct {
|
||||||
ObjectKind string `json:"object_kind"`
|
ObjectKind string `json:"object_kind"`
|
||||||
@@ -319,7 +312,7 @@ type MergeRequest struct {
|
|||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
TargetBranch string `json:"target_branch"`
|
TargetBranch string `json:"target_branch"`
|
||||||
SourceBranch string `json:"source_branch"`
|
SourceBranch string `json:"source_branch"`
|
||||||
SourceProjectID int64 `json:"source_project_id"`
|
SourceProjectID string `json:"source_project_id"`
|
||||||
AssigneeID int64 `json:"assignee_id"`
|
AssigneeID int64 `json:"assignee_id"`
|
||||||
AuthorID int64 `json:"author_id"`
|
AuthorID int64 `json:"author_id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
|||||||
Reference in New Issue
Block a user