Compare commits

...

24 Commits

Author SHA1 Message Date
Dean Karn 1b6492ce45 Merge pull request #26 from kuiro5/add-requested-reviewers
Add RequestedReviewers to PullRequestPayload
2018-03-19 08:41:56 -07:00
kuiros ea44f6921c Add RequestedReviewers to PullRequestPayload 2018-03-10 15:33:16 -08:00
Dean Karn b6e930d373 Update README.md 2018-02-23 05:13:07 -08:00
Dean Karn c271ec3e32 Merge pull request #25 from lukepatrick/v3
Update bitbucket uuid check to allow a non-specified uuid, similar to…
2018-02-23 05:10:58 -08:00
lukepatrick 0c4911f7f5 Update bitbucket uuid check to allow a non-specified uuid, similar to gitlab empty secret. 2018-02-22 15:27:54 -07:00
Dean Karn 3667088d60 Merge pull request #24 from lukepatrick/v3
update MergeRequestEvent payload with Project, Repo objects from the API
2018-02-15 07:22:55 -08:00
lukepatrick 9cafa895ff update MergeRequestEvent payload with Project, Repo objects from the API 2018-02-14 12:45:52 -07:00
Dean Karn 9494e434fc Update README.md 2018-01-19 08:54:08 -08:00
Dean Karn 97dd8f3564 Merge pull request #23 from PombeirP/add-installation-and-ping
Add installation and ping
2018-01-19 08:46:12 -08:00
Pedro Pombeiro 8f6fada23d Add support for ping events 2018-01-16 10:15:54 +01:00
Pedro Pombeiro 94f9d6694d Add support for installation and integration_installation events 2018-01-16 10:15:29 +01:00
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
8 changed files with 640 additions and 111 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.8.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)
+8 -4
View File
@@ -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")
+11
View File
@@ -36,6 +36,8 @@ const (
DeploymentStatusEvent Event = "deployment_status" DeploymentStatusEvent Event = "deployment_status"
ForkEvent Event = "fork" ForkEvent Event = "fork"
GollumEvent Event = "gollum" GollumEvent Event = "gollum"
InstallationEvent Event = "installation"
IntegrationInstallationEvent Event = "integration_installation"
IssueCommentEvent Event = "issue_comment" IssueCommentEvent Event = "issue_comment"
IssuesEvent Event = "issues" IssuesEvent Event = "issues"
LabelEvent Event = "label" LabelEvent Event = "label"
@@ -45,6 +47,7 @@ const (
OrganizationEvent Event = "organization" OrganizationEvent Event = "organization"
OrgBlockEvent Event = "org_block" OrgBlockEvent Event = "org_block"
PageBuildEvent Event = "page_build" PageBuildEvent Event = "page_build"
PingEvent Event = "ping"
ProjectCardEvent Event = "project_card" ProjectCardEvent Event = "project_card"
ProjectColumnEvent Event = "project_column" ProjectColumnEvent Event = "project_column"
ProjectEvent Event = "project" ProjectEvent Event = "project"
@@ -179,6 +182,10 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
var g GollumPayload var g GollumPayload
json.Unmarshal([]byte(payload), &g) json.Unmarshal([]byte(payload), &g)
hook.runProcessPayloadFunc(fn, g, hd) hook.runProcessPayloadFunc(fn, g, hd)
case InstallationEvent, IntegrationInstallationEvent:
var i InstallationPayload
json.Unmarshal([]byte(payload), &i)
hook.runProcessPayloadFunc(fn, i, hd)
case IssueCommentEvent: case IssueCommentEvent:
var i IssueCommentPayload var i IssueCommentPayload
json.Unmarshal([]byte(payload), &i) json.Unmarshal([]byte(payload), &i)
@@ -215,6 +222,10 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
var p PageBuildPayload var p PageBuildPayload
json.Unmarshal([]byte(payload), &p) json.Unmarshal([]byte(payload), &p)
hook.runProcessPayloadFunc(fn, p, hd) hook.runProcessPayloadFunc(fn, p, hd)
case PingEvent:
var p PingPayload
json.Unmarshal([]byte(payload), &p)
hook.runProcessPayloadFunc(fn, p, hd)
case ProjectCardEvent: case ProjectCardEvent:
var p ProjectCardPayload var p ProjectCardPayload
json.Unmarshal([]byte(payload), &p) json.Unmarshal([]byte(payload), &p)
+225
View File
@@ -48,6 +48,8 @@ func TestMain(m *testing.M) {
DeploymentStatusEvent, DeploymentStatusEvent,
ForkEvent, ForkEvent,
GollumEvent, GollumEvent,
InstallationEvent,
IntegrationInstallationEvent,
IssueCommentEvent, IssueCommentEvent,
IssuesEvent, IssuesEvent,
LabelEvent, LabelEvent,
@@ -57,6 +59,7 @@ func TestMain(m *testing.M) {
OrganizationEvent, OrganizationEvent,
OrgBlockEvent, OrgBlockEvent,
PageBuildEvent, PageBuildEvent,
PingEvent,
ProjectCardEvent, ProjectCardEvent,
ProjectColumnEvent, ProjectColumnEvent,
ProjectEvent, ProjectEvent,
@@ -1309,6 +1312,186 @@ func TestGollumEvent(t *testing.T) {
Equal(t, resp.StatusCode, http.StatusOK) Equal(t, resp.StatusCode, http.StatusOK)
} }
func TestInstallationEvent(t *testing.T) {
payload := `{
"action": "created",
"installation": {
"id": 80429,
"account": {
"login": "PombeirP",
"id": 138074,
"avatar_url": "https://avatars1.githubusercontent.com/u/138074?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/PombeirP",
"html_url": "https://github.com/PombeirP",
"followers_url": "https://api.github.com/users/PombeirP/followers",
"following_url": "https://api.github.com/users/PombeirP/following{/other_user}",
"gists_url": "https://api.github.com/users/PombeirP/gists{/gist_id}",
"starred_url": "https://api.github.com/users/PombeirP/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/PombeirP/subscriptions",
"organizations_url": "https://api.github.com/users/PombeirP/orgs",
"repos_url": "https://api.github.com/users/PombeirP/repos",
"events_url": "https://api.github.com/users/PombeirP/events{/privacy}",
"received_events_url": "https://api.github.com/users/PombeirP/received_events",
"type": "User",
"site_admin": false
},
"repository_selection": "selected",
"access_tokens_url": "https://api.github.com/installations/80429/access_tokens",
"repositories_url": "https://api.github.com/installation/repositories",
"html_url": "https://github.com/settings/installations/80429",
"app_id": 8157,
"target_id": 138074,
"target_type": "User",
"permissions": {
"repository_projects": "write",
"issues": "read",
"metadata": "read",
"pull_requests": "read"
},
"events": [
"pull_request"
],
"created_at": 1516025475,
"updated_at": 1516025475,
"single_file_name": null
},
"repositories": [
{
"id": 117381220,
"name": "status-github-bot",
"full_name": "PombeirP/status-github-bot"
}
],
"sender": {
"login": "PombeirP",
"id": 138074,
"avatar_url": "https://avatars1.githubusercontent.com/u/138074?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/PombeirP",
"html_url": "https://github.com/PombeirP",
"followers_url": "https://api.github.com/users/PombeirP/followers",
"following_url": "https://api.github.com/users/PombeirP/following{/other_user}",
"gists_url": "https://api.github.com/users/PombeirP/gists{/gist_id}",
"starred_url": "https://api.github.com/users/PombeirP/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/PombeirP/subscriptions",
"organizations_url": "https://api.github.com/users/PombeirP/orgs",
"repos_url": "https://api.github.com/users/PombeirP/repos",
"events_url": "https://api.github.com/users/PombeirP/events{/privacy}",
"received_events_url": "https://api.github.com/users/PombeirP/received_events",
"type": "User",
"site_admin": false
}
}
`
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Github-Event", "installation")
req.Header.Set("X-Hub-Signature", "sha1=987338c6e5c21794ab6c258abe51284f9b1df728")
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 TestIntegrationInstallationEvent(t *testing.T) {
payload := `{
"action": "created",
"installation": {
"id": 80429,
"account": {
"login": "PombeirP",
"id": 138074,
"avatar_url": "https://avatars1.githubusercontent.com/u/138074?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/PombeirP",
"html_url": "https://github.com/PombeirP",
"followers_url": "https://api.github.com/users/PombeirP/followers",
"following_url": "https://api.github.com/users/PombeirP/following{/other_user}",
"gists_url": "https://api.github.com/users/PombeirP/gists{/gist_id}",
"starred_url": "https://api.github.com/users/PombeirP/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/PombeirP/subscriptions",
"organizations_url": "https://api.github.com/users/PombeirP/orgs",
"repos_url": "https://api.github.com/users/PombeirP/repos",
"events_url": "https://api.github.com/users/PombeirP/events{/privacy}",
"received_events_url": "https://api.github.com/users/PombeirP/received_events",
"type": "User",
"site_admin": false
},
"repository_selection": "selected",
"access_tokens_url": "https://api.github.com/installations/80429/access_tokens",
"repositories_url": "https://api.github.com/installation/repositories",
"html_url": "https://github.com/settings/installations/80429",
"app_id": 8157,
"target_id": 138074,
"target_type": "User",
"permissions": {
"repository_projects": "write",
"issues": "read",
"metadata": "read",
"pull_requests": "read"
},
"events": [
"pull_request"
],
"created_at": 1516025475,
"updated_at": 1516025475,
"single_file_name": null
},
"repositories": [
{
"id": 117381220,
"name": "status-github-bot",
"full_name": "PombeirP/status-github-bot"
}
],
"sender": {
"login": "PombeirP",
"id": 138074,
"avatar_url": "https://avatars1.githubusercontent.com/u/138074?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/PombeirP",
"html_url": "https://github.com/PombeirP",
"followers_url": "https://api.github.com/users/PombeirP/followers",
"following_url": "https://api.github.com/users/PombeirP/following{/other_user}",
"gists_url": "https://api.github.com/users/PombeirP/gists{/gist_id}",
"starred_url": "https://api.github.com/users/PombeirP/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/PombeirP/subscriptions",
"organizations_url": "https://api.github.com/users/PombeirP/orgs",
"repos_url": "https://api.github.com/users/PombeirP/repos",
"events_url": "https://api.github.com/users/PombeirP/events{/privacy}",
"received_events_url": "https://api.github.com/users/PombeirP/received_events",
"type": "User",
"site_admin": false
}
}
`
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Github-Event", "integration_installation")
req.Header.Set("X-Hub-Signature", "sha1=987338c6e5c21794ab6c258abe51284f9b1df728")
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 TestIssueCommentEvent(t *testing.T) { func TestIssueCommentEvent(t *testing.T) {
payload := `{ payload := `{
@@ -2560,6 +2743,48 @@ func TestPageBuildEvent(t *testing.T) {
Equal(t, resp.StatusCode, http.StatusOK) Equal(t, resp.StatusCode, http.StatusOK)
} }
func TestPingEvent(t *testing.T) {
payload := `{
"zen": "Keep it logically awesome.",
"hook_id": 20081052,
"hook": {
"type": "App",
"id": 20081052,
"name": "web",
"active": true,
"events": [
"pull_request"
],
"config": {
"content_type": "json",
"insecure_ssl": "0",
"secret": "********",
"url": "https://ngrok.io/webhook"
},
"updated_at": "2018-01-15T10:48:54Z",
"created_at": "2018-01-15T10:48:54Z",
"app_id": 8157
}
}
`
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Github-Event", "ping")
req.Header.Set("X-Hub-Signature", "sha1=f82267eb5c6408d5986209da906747f57c11b33b")
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 TestProjectCardEvent(t *testing.T) { func TestProjectCardEvent(t *testing.T) {
payload := `{ payload := `{
+141 -30
View File
@@ -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"`
@@ -1006,6 +1007,74 @@ type GollumPayload struct {
} `json:"sender"` } `json:"sender"`
} }
// InstallationPayload contains the information for GitHub's installation and integration_installation hook events
type InstallationPayload struct {
Action string `json:"action"`
Installation struct {
ID int64 `json:"id"`
Account struct {
Login string `json:"login"`
ID int64 `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:"account"`
RepositorySelection string `json:"repository_selection"`
AccessTokensURL string `json:"access_tokens_url"`
RepositoriesURL string `json:"repositories_url"`
HTMLURL string `json:"html_url"`
AppID int `json:"app_id"`
TargetID int `json:"target_id"`
TargetType string `json:"target_type"`
Permissions struct {
Issues string `json:"issues"`
Metadata string `json:"metadata"`
PullRequests string `json:"pull_requests"`
RepositoryProjects string `json:"repository_projects"`
} `json:"permissions"`
Events []string `json:"events"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
SingleFileName *string `json:"single_file_name"`
} `json:"installation"`
Repositories []struct {
ID int64 `json:"id"`
Name string `json:"name"`
FullName string `json:"full_name"`
} `json:"repositories"`
Sender struct {
Login string `json:"login"`
ID int64 `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:"sender"`
}
// IssueCommentPayload contains the information for GitHub's issue_comment hook event // IssueCommentPayload contains the information for GitHub's issue_comment hook event
type IssueCommentPayload struct { type IssueCommentPayload struct {
Action string `json:"action"` Action string `json:"action"`
@@ -1076,9 +1145,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"`
@@ -2092,6 +2162,27 @@ type PageBuildPayload struct {
} `json:"sender"` } `json:"sender"`
} }
// PingPayload contains the information for GitHub's ping hook event
type PingPayload struct {
HookID int `json:"hook_id"`
Hook struct {
Type string `json:"type"`
ID int64 `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
Events []string `json:"events"`
AppID int `json:"app_id"`
Config struct {
ContentType string `json:"content_type"`
InsecureSSL int `json:"insecure_ssl"`
Secret string `json:"secret"`
URL string `json:"url"`
} `json:"config"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
} `json:"hook"`
}
// ProjectCardPayload contains the information for GitHub's project_payload hook event // ProjectCardPayload contains the information for GitHub's project_payload hook event
type ProjectCardPayload struct { type ProjectCardPayload struct {
Action string `json:"action"` Action string `json:"action"`
@@ -2668,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"`
@@ -3531,12 +3641,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
View File
@@ -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)
+203 -67
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 := `{
@@ -734,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)))
+37 -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,9 @@ 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"`
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
@@ -312,7 +323,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 +413,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"`
}