Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f553bfaa59 | |||
| 903279e458 | |||
| 5462959f1e | |||
| 4964805803 | |||
| 13e6611c00 | |||
| b9424ab72e | |||
| 203bf4218b | |||
| 5e4be82c0b | |||
| cd89a10b64 | |||
| e120e3b3ba |
@@ -1,6 +1,6 @@
|
||||
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://coveralls.io/github/go-playground/webhooks?branch=v3)
|
||||
[](https://goreportcard.com/report/go-playground/webhooks)
|
||||
|
||||
@@ -2940,6 +2940,13 @@ type PullRequestPayload struct {
|
||||
Deletions int64 `json:"deletions"`
|
||||
ChangedFiles int64 `json:"changed_files"`
|
||||
} `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 {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
||||
+14
-8
@@ -26,14 +26,15 @@ type Event string
|
||||
|
||||
// GitLab hook types
|
||||
const (
|
||||
PushEvents Event = "Push Hook"
|
||||
TagEvents Event = "Tag Push Hook"
|
||||
IssuesEvents Event = "Issue Hook"
|
||||
CommentEvents Event = "Note Hook"
|
||||
MergeRequestEvents Event = "Merge Request Hook"
|
||||
WikiPageEvents Event = "Wiki Page Hook"
|
||||
PipelineEvents Event = "Pipeline Hook"
|
||||
BuildEvents Event = "Build Hook"
|
||||
PushEvents Event = "Push Hook"
|
||||
TagEvents Event = "Tag Push Hook"
|
||||
IssuesEvents Event = "Issue Hook"
|
||||
ConfidentialIssuesEvents Event = "Confidential Issue Hook"
|
||||
CommentEvents Event = "Note Hook"
|
||||
MergeRequestEvents Event = "Merge Request Hook"
|
||||
WikiPageEvents Event = "Wiki Page Hook"
|
||||
PipelineEvents Event = "Pipeline Hook"
|
||||
BuildEvents Event = "Build Hook"
|
||||
)
|
||||
|
||||
// New creates and returns a WebHook instance denoted by the Provider type
|
||||
@@ -112,6 +113,11 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
|
||||
json.Unmarshal([]byte(payload), &te)
|
||||
hook.runProcessPayloadFunc(fn, te, hd)
|
||||
|
||||
case ConfidentialIssuesEvents:
|
||||
var cie ConfidentialIssueEventPayload
|
||||
json.Unmarshal([]byte(payload), &cie)
|
||||
hook.runProcessPayloadFunc(fn, cie, hd)
|
||||
|
||||
case IssuesEvents:
|
||||
var ie IssueEventPayload
|
||||
json.Unmarshal([]byte(payload), &ie)
|
||||
|
||||
@@ -43,6 +43,7 @@ func TestMain(m *testing.M) {
|
||||
PushEvents,
|
||||
TagEvents,
|
||||
IssuesEvents,
|
||||
ConfidentialIssuesEvents,
|
||||
CommentEvents,
|
||||
MergeRequestEvents,
|
||||
WikiPageEvents,
|
||||
@@ -349,6 +350,78 @@ func TestIssueEvent(t *testing.T) {
|
||||
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) {
|
||||
|
||||
payload := `{
|
||||
|
||||
+8
-1
@@ -40,6 +40,13 @@ type IssueEventPayload struct {
|
||||
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
|
||||
type MergeRequestEventPayload struct {
|
||||
ObjectKind string `json:"object_kind"`
|
||||
@@ -312,7 +319,7 @@ type MergeRequest struct {
|
||||
ID int64 `json:"id"`
|
||||
TargetBranch string `json:"target_branch"`
|
||||
SourceBranch string `json:"source_branch"`
|
||||
SourceProjectID string `json:"source_project_id"`
|
||||
SourceProjectID int64 `json:"source_project_id"`
|
||||
AssigneeID int64 `json:"assignee_id"`
|
||||
AuthorID int64 `json:"author_id"`
|
||||
Title string `json:"title"`
|
||||
|
||||
Reference in New Issue
Block a user