Compare commits

...

13 Commits

Author SHA1 Message Date
Dean Karn ad5392160c Update README.md 2017-12-17 22:05:38 -08:00
Dean Karn 19cab958b6 Merge pull request #21 from Mingan/master
[GitLab] Parse label changes on issue and MR events
2017-12-17 22:05:13 -08:00
Štěpán Pilař 78ce03b046 [GitLab] Parse label changes on issue and MR events 2017-12-17 17:50:34 +01:00
Dean Karn ced2e979bc Merge pull request #19 from kairen/add-author-association
Add parse author association for GitHub comment
2017-10-22 09:17:54 -07:00
kairen d60a03e52a Add parse author association for GitHub comment 2017-10-20 16:14:26 +08:00
Dean Karn f553bfaa59 Update README.md 2017-10-01 19:29:18 -07:00
Dean Karn 903279e458 add test for confidential issues gitlab 2017-10-01 19:24:09 -07:00
Dean Karn 5462959f1e Merge pull request #18 from tulir/patch-2
[GitLab] Add support for confidential issues
2017-10-01 19:17:33 -07:00
Dean Karn 4964805803 Merge pull request #17 from tulir/patch-1
[GitLab] Fix type of SourceProjectID in MergeRequest struct
2017-10-01 19:16:55 -07:00
Tulir Asokan 13e6611c00 Add separate payload type for confidential issues 2017-10-01 23:13:19 +03:00
Tulir Asokan b9424ab72e Add support for confidential GitLab issues 2017-10-01 13:56:19 +03:00
Tulir Asokan 203bf4218b Fix type of SourceProjectID in MergeRequest struct
It should be an int64, but was a string.
https://docs.gitlab.com/ce/user/project/integrations/webhooks.html#comment-on-merge-request

The incorrect type caused the MergeRequest field in comment event payloads to be empty.
2017-09-29 19:54:03 +00:00
Dean Karn 5e4be82c0b Update README.md 2017-08-17 08:39:34 -07:00
5 changed files with 142 additions and 26 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
Library webhooks Library webhooks
================ ================
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v3/logo.png">![Project status](https://img.shields.io/badge/version-3.2.0-green.svg) <img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v3/logo.png">![Project status](https://img.shields.io/badge/version-3.5.0-green.svg)
[![Build Status](https://travis-ci.org/go-playground/webhooks.svg?branch=v3)](https://travis-ci.org/go-playground/webhooks) [![Build Status](https://travis-ci.org/go-playground/webhooks.svg?branch=v3)](https://travis-ci.org/go-playground/webhooks)
[![Coverage Status](https://coveralls.io/repos/go-playground/webhooks/badge.svg?branch=v3&service=github)](https://coveralls.io/github/go-playground/webhooks?branch=v3) [![Coverage Status](https://coveralls.io/repos/go-playground/webhooks/badge.svg?branch=v3&service=github)](https://coveralls.io/github/go-playground/webhooks?branch=v3)
[![Go Report Card](https://goreportcard.com/badge/go-playground/webhooks)](https://goreportcard.com/report/go-playground/webhooks) [![Go Report Card](https://goreportcard.com/badge/go-playground/webhooks)](https://goreportcard.com/report/go-playground/webhooks)
+3
View File
@@ -35,6 +35,7 @@ type CommitCommentPayload struct {
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"`
@@ -1079,6 +1080,7 @@ type IssueCommentPayload struct {
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"`
@@ -3532,6 +3534,7 @@ type PullRequestReviewCommentPayload struct {
SiteAdmin bool `json:"site_admin"` SiteAdmin bool `json:"site_admin"`
} `json:"user"` } `json:"user"`
Body string `json:"body"` Body string `json:"body"`
AuthorAssociation string `json:"author_association"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`
HTMLURL string `json:"html_url"` HTMLURL string `json:"html_url"`
+6
View File
@@ -29,6 +29,7 @@ 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"
@@ -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)
+73
View File
@@ -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 := `{
+35 -1
View File
@@ -38,6 +38,14 @@ type IssueEventPayload struct {
Repository Repository `json:"repository"` Repository Repository `json:"repository"`
ObjectAttributes ObjectAttributes `json:"object_attributes"` ObjectAttributes ObjectAttributes `json:"object_attributes"`
Assignee Assignee `json:"assignee"` Assignee Assignee `json:"assignee"`
Changes Changes `json:"changes"`
}
// 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
@@ -45,6 +53,7 @@ type MergeRequestEventPayload struct {
ObjectKind string `json:"object_kind"` ObjectKind string `json:"object_kind"`
User User `json:"user"` User User `json:"user"`
ObjectAttributes ObjectAttributes `json:"object_attributes"` ObjectAttributes ObjectAttributes `json:"object_attributes"`
Changes Changes `json:"changes"`
} }
// PushEventPayload contains the information for GitLab's push event // PushEventPayload contains the information for GitLab's push event
@@ -312,7 +321,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"`
@@ -402,3 +411,28 @@ type Author struct {
Name string `json:"name"` Name string `json:"name"`
Email string `json:"email"` Email string `json:"email"`
} }
// Changes contains all changes associated with a GitLab issue or MR
type Changes struct {
LabelChanges LabelChanges `json:"labels"`
}
// LabelChanges contains changes in labels assocatiated with a GitLab issue or MR
type LabelChanges struct {
Previous []Label `json:"previous"`
Current []Label `json:"current"`
}
// Label contains all of the GitLab label information
type Label struct {
Id int64 `json:"id"`
Title string `json:"title"`
Color string `json:"color"`
ProjectId int64 `json:"project_id"`
CreatedAt customTime `json:"created_at"`
UpdatedAt customTime `json:"updated_at"`
Template bool `json:"template"`
Description string `json:"description"`
Type string `json:"type"`
GroupId int64 `json:"group_id"`
}