Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ced2e979bc | |||
| d60a03e52a | |||
| f553bfaa59 | |||
| 903279e458 | |||
| 5462959f1e | |||
| 4964805803 | |||
| 13e6611c00 | |||
| b9424ab72e | |||
| 203bf4218b | |||
| 5e4be82c0b |
@@ -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)
|
||||||
|
|||||||
+19
-16
@@ -28,13 +28,14 @@ type CommitCommentPayload struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
SiteAdmin bool `json:"site_admin"`
|
SiteAdmin bool `json:"site_admin"`
|
||||||
} `json:"user"`
|
} `json:"user"`
|
||||||
Position *int64 `json:"position"`
|
Position *int64 `json:"position"`
|
||||||
Line *int64 `json:"line"`
|
Line *int64 `json:"line"`
|
||||||
Path *string `json:"path"`
|
Path *string `json:"path"`
|
||||||
CommitID string `json:"commit_id"`
|
CommitID string `json:"commit_id"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
|
AuthorAssociation string `json:"author_association"`
|
||||||
} `json:"comment"`
|
} `json:"comment"`
|
||||||
Repository struct {
|
Repository struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
@@ -1076,9 +1077,10 @@ type IssueCommentPayload struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
SiteAdmin bool `json:"site_admin"`
|
SiteAdmin bool `json:"site_admin"`
|
||||||
} `json:"user"`
|
} `json:"user"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
|
AuthorAssociation string `json:"author_association"`
|
||||||
} `json:"comment"`
|
} `json:"comment"`
|
||||||
Repository struct {
|
Repository struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
@@ -3531,12 +3533,13 @@ type PullRequestReviewCommentPayload 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"`
|
AuthorAssociation string `json:"author_association"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
HTMLURL string `json:"html_url"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
PullRequestURL string `json:"pull_request_url"`
|
HTMLURL string `json:"html_url"`
|
||||||
Links struct {
|
PullRequestURL string `json:"pull_request_url"`
|
||||||
|
Links struct {
|
||||||
Self struct {
|
Self struct {
|
||||||
Href string `json:"href"`
|
Href string `json:"href"`
|
||||||
} `json:"self"`
|
} `json:"self"`
|
||||||
|
|||||||
+14
-8
@@ -26,14 +26,15 @@ type Event string
|
|||||||
|
|
||||||
// GitLab hook types
|
// GitLab hook types
|
||||||
const (
|
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"
|
||||||
CommentEvents Event = "Note Hook"
|
ConfidentialIssuesEvents Event = "Confidential Issue Hook"
|
||||||
MergeRequestEvents Event = "Merge Request Hook"
|
CommentEvents Event = "Note Hook"
|
||||||
WikiPageEvents Event = "Wiki Page Hook"
|
MergeRequestEvents Event = "Merge Request Hook"
|
||||||
PipelineEvents Event = "Pipeline Hook"
|
WikiPageEvents Event = "Wiki Page Hook"
|
||||||
BuildEvents Event = "Build Hook"
|
PipelineEvents Event = "Pipeline Hook"
|
||||||
|
BuildEvents Event = "Build Hook"
|
||||||
)
|
)
|
||||||
|
|
||||||
// New creates and returns a WebHook instance denoted by the Provider type
|
// 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)
|
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,6 +43,7 @@ func TestMain(m *testing.M) {
|
|||||||
PushEvents,
|
PushEvents,
|
||||||
TagEvents,
|
TagEvents,
|
||||||
IssuesEvents,
|
IssuesEvents,
|
||||||
|
ConfidentialIssuesEvents,
|
||||||
CommentEvents,
|
CommentEvents,
|
||||||
MergeRequestEvents,
|
MergeRequestEvents,
|
||||||
WikiPageEvents,
|
WikiPageEvents,
|
||||||
@@ -349,6 +350,78 @@ 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 := `{
|
||||||
|
|||||||
+8
-1
@@ -40,6 +40,13 @@ 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"`
|
||||||
@@ -312,7 +319,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 string `json:"source_project_id"`
|
SourceProjectID int64 `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