Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 59fb74817c | |||
| aa941874be | |||
| bfd950a988 | |||
| 9d685f3a73 | |||
| 1f42c84783 | |||
| ee81f21da7 | |||
| 03cee75fc3 | |||
| 86c24d8570 | |||
| 30fb8f885f | |||
| 957d07ee07 | |||
| a5ce17cac3 | |||
| efae47c3b9 | |||
| b616136c50 | |||
| 303483bff4 | |||
| 4156f32687 | |||
| b03dc868a0 | |||
| 9f0c3ac5d7 | |||
| f4ad678f8e | |||
| a23062206a | |||
| 7c046447e2 | |||
| 9a9f42e1b8 |
+8
-8
@@ -1,16 +1,16 @@
|
||||
language: go
|
||||
go:
|
||||
- 1.12.1
|
||||
- tip
|
||||
- 1.13.15
|
||||
- tip
|
||||
matrix:
|
||||
allow_failures:
|
||||
- go: tip
|
||||
|
||||
notifications:
|
||||
email:
|
||||
recipients: dean.karn@gmail.com
|
||||
on_success: change
|
||||
on_failure: always
|
||||
email:
|
||||
recipients: dean.karn@gmail.com
|
||||
on_success: change
|
||||
on_failure: always
|
||||
|
||||
before_install:
|
||||
- go get -u github.com/go-playground/overalls
|
||||
@@ -26,9 +26,9 @@ before_script:
|
||||
- go get -t ./...
|
||||
|
||||
script:
|
||||
- make test
|
||||
- make test
|
||||
|
||||
after_success: |
|
||||
[ $TRAVIS_GO_VERSION = 1.11.2 ] &&
|
||||
[ $TRAVIS_GO_VERSION = 1.13.15 ] &&
|
||||
overalls -project="github.com/go-playground/webhooks" -covermode=count -ignore=.git,_examples,testdata -debug &&
|
||||
goveralls -coverprofile=overalls.coverprofile -service travis-ci -repotoken $COVERALLS_TOKEN
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Library webhooks
|
||||
================
|
||||
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v5/logo.png">
|
||||
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v5/logo.png">
|
||||
[](https://travis-ci.org/go-playground/webhooks)
|
||||
[](https://coveralls.io/github/go-playground/webhooks?branch=v5)
|
||||
[](https://goreportcard.com/report/go-playground/webhooks)
|
||||
|
||||
@@ -32,11 +32,12 @@ const (
|
||||
RepositoryCommentEditedEvent Event = "repo:comment:edited"
|
||||
RepositoryCommentDeletedEvent Event = "repo:comment:deleted"
|
||||
|
||||
PullRequestOpenedEvent Event = "pr:opened"
|
||||
PullRequestModifiedEvent Event = "pr:modified"
|
||||
PullRequestMergedEvent Event = "pr:merged"
|
||||
PullRequestDeclinedEvent Event = "pr:declined"
|
||||
PullRequestDeletedEvent Event = "pr:deleted"
|
||||
PullRequestOpenedEvent Event = "pr:opened"
|
||||
PullRequestFromReferenceUpdatedEvent Event = "pr:from_ref_updated"
|
||||
PullRequestModifiedEvent Event = "pr:modified"
|
||||
PullRequestMergedEvent Event = "pr:merged"
|
||||
PullRequestDeclinedEvent Event = "pr:declined"
|
||||
PullRequestDeletedEvent Event = "pr:deleted"
|
||||
|
||||
PullRequestReviewerUpdatedEvent Event = "pr:reviewer:updated"
|
||||
PullRequestReviewerApprovedEvent Event = "pr:reviewer:approved"
|
||||
@@ -168,6 +169,10 @@ func (hook *Webhook) Parse(r *http.Request, events ...Event) (interface{}, error
|
||||
var pl PullRequestOpenedPayload
|
||||
err = json.Unmarshal([]byte(payload), &pl)
|
||||
return pl, err
|
||||
case PullRequestFromReferenceUpdatedEvent:
|
||||
var pl PullRequestFromReferenceUpdatedPayload
|
||||
err = json.Unmarshal([]byte(payload), &pl)
|
||||
return pl, err
|
||||
case PullRequestModifiedEvent:
|
||||
var pl PullRequestModifiedPayload
|
||||
err = json.Unmarshal([]byte(payload), &pl)
|
||||
|
||||
@@ -66,6 +66,14 @@ type PullRequestOpenedPayload struct {
|
||||
PullRequest PullRequest `json:"pullRequest"`
|
||||
}
|
||||
|
||||
type PullRequestFromReferenceUpdatedPayload struct {
|
||||
Date Date `json:"date"`
|
||||
EventKey Event `json:"eventKey"`
|
||||
Actor User `json:"actor"`
|
||||
PullRequest PullRequest `json:"pullRequest"`
|
||||
PreviousFromHash string `json:"previousFromHash"`
|
||||
}
|
||||
|
||||
type PullRequestModifiedPayload struct {
|
||||
Date Date `json:"date"`
|
||||
EventKey Event `json:"eventKey"`
|
||||
|
||||
@@ -380,7 +380,7 @@ func TestWebhooks(t *testing.T) {
|
||||
filename: "../testdata/github/project-card.json",
|
||||
headers: http.Header{
|
||||
"X-Github-Event": []string{"project_card"},
|
||||
"X-Hub-Signature": []string{"sha1=495dec0d6449d16b71f2ddcd37d595cb9b04b1d8"},
|
||||
"X-Hub-Signature": []string{"sha1=f5ed1572b04f0e03c8d5f5e3f7fa63737bef76d7"},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -420,7 +420,7 @@ func TestWebhooks(t *testing.T) {
|
||||
filename: "../testdata/github/pull-request.json",
|
||||
headers: http.Header{
|
||||
"X-Github-Event": []string{"pull_request"},
|
||||
"X-Hub-Signature": []string{"sha1=35712c8d2bc197b7d07621dcf20d2fb44620508f"},
|
||||
"X-Hub-Signature": []string{"sha1=88972f972db301178aa13dafaf112d26416a15e6"},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
+22
-7
@@ -1662,6 +1662,11 @@ type IssueCommentPayload struct {
|
||||
Body string `json:"body"`
|
||||
AuthorAssociation string `json:"author_association"`
|
||||
} `json:"comment"`
|
||||
Changes *struct {
|
||||
Body *struct {
|
||||
From string `json:"from"`
|
||||
} `json:"body"`
|
||||
} `json:"changes"`
|
||||
Repository struct {
|
||||
ID int64 `json:"id"`
|
||||
NodeID string `json:"node_id"`
|
||||
@@ -1826,6 +1831,14 @@ type IssuesPayload struct {
|
||||
ClosedAt *time.Time `json:"closed_at"`
|
||||
Body string `json:"body"`
|
||||
} `json:"issue"`
|
||||
Changes *struct {
|
||||
Title *struct {
|
||||
From string `json:"from"`
|
||||
} `json:"title"`
|
||||
Body *struct {
|
||||
From string `json:"from"`
|
||||
} `json:"body"`
|
||||
} `json:"changes"`
|
||||
Repository struct {
|
||||
ID int64 `json:"id"`
|
||||
NodeID string `json:"node_id"`
|
||||
@@ -2986,13 +2999,14 @@ type PingPayload struct {
|
||||
type ProjectCardPayload struct {
|
||||
Action string `json:"action"`
|
||||
ProjectCard struct {
|
||||
URL string `json:"url"`
|
||||
ColumnURL string `json:"column_url"`
|
||||
ColumnID int64 `json:"column_id"`
|
||||
ID int64 `json:"id"`
|
||||
NodeID string `json:"node_id"`
|
||||
Note *string `json:"note"`
|
||||
Creator struct {
|
||||
URL string `json:"url"`
|
||||
ProjectURL string `json:"project_url"`
|
||||
ColumnURL string `json:"column_url"`
|
||||
ColumnID int64 `json:"column_id"`
|
||||
ID int64 `json:"id"`
|
||||
NodeID string `json:"node_id"`
|
||||
Note *string `json:"note"`
|
||||
Creator struct {
|
||||
Login string `json:"login"`
|
||||
ID int64 `json:"id"`
|
||||
NodeID string `json:"node_id"`
|
||||
@@ -3589,6 +3603,7 @@ type PullRequestPayload struct {
|
||||
Assignee *Assignee `json:"assignee"`
|
||||
Assignees []*Assignee `json:"assignees"`
|
||||
Milestone *Milestone `json:"milestone"`
|
||||
Draft bool `json:"draft"`
|
||||
CommitsURL string `json:"commits_url"`
|
||||
ReviewCommentsURL string `json:"review_comments_url"`
|
||||
ReviewCommentURL string `json:"review_comment_url"`
|
||||
|
||||
+10
-1
@@ -191,7 +191,16 @@ func eventParsing(gitLabEvent Event, events []Event, payload []byte) (interface{
|
||||
case objectMergeRequest:
|
||||
return eventParsing(MergeRequestEvents, events, payload)
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown system hook event %s", gitLabEvent)
|
||||
switch pl.EventName {
|
||||
case objectPush:
|
||||
return eventParsing(PushEvents, events, payload)
|
||||
case objectTag:
|
||||
return eventParsing(TagEvents, events, payload)
|
||||
case objectMergeRequest:
|
||||
return eventParsing(MergeRequestEvents, events, payload)
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown system hook event %s", gitLabEvent)
|
||||
}
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown event %s", gitLabEvent)
|
||||
|
||||
@@ -286,19 +286,19 @@ func TestSystemHooks(t *testing.T) {
|
||||
name: "PushEvent",
|
||||
event: PushEvents,
|
||||
typ: PushEventPayload{},
|
||||
filename: "../testdata/gitlab/push-event.json",
|
||||
filename: "../testdata/gitlab/system-push-event.json",
|
||||
},
|
||||
{
|
||||
name: "TagEvent",
|
||||
event: TagEvents,
|
||||
typ: TagEventPayload{},
|
||||
filename: "../testdata/gitlab/tag-event.json",
|
||||
filename: "../testdata/gitlab/system-tag-event.json",
|
||||
},
|
||||
{
|
||||
name: "MergeRequestEvent",
|
||||
event: MergeRequestEvents,
|
||||
typ: MergeRequestEventPayload{},
|
||||
filename: "../testdata/gitlab/merge-request-event.json",
|
||||
filename: "../testdata/gitlab/system-merge-request-event.json",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -56,6 +56,7 @@ type MergeRequestEventPayload struct {
|
||||
Changes Changes `json:"changes"`
|
||||
Project Project `json:"project"`
|
||||
Repository Repository `json:"repository"`
|
||||
Labels []Label `json:"labels"`
|
||||
}
|
||||
|
||||
// PushEventPayload contains the information for GitLab's push event
|
||||
@@ -176,6 +177,7 @@ type JobEventPayload struct {
|
||||
// SystemHookPayload contains the ObjectKind to match with real hook events
|
||||
type SystemHookPayload struct {
|
||||
ObjectKind string `json:"object_kind"`
|
||||
EventName string `json:"event_name"`
|
||||
}
|
||||
|
||||
// Issue contains all of the GitLab issue information
|
||||
|
||||
Vendored
+3
-2
@@ -2,6 +2,7 @@
|
||||
"action": "created",
|
||||
"project_card": {
|
||||
"url": "https://api.github.com/projects/columns/cards/1266091",
|
||||
"project_url": "https://api.github.com/projects/6047634",
|
||||
"column_url": "https://api.github.com/projects/columns/515520",
|
||||
"column_id": 515520,
|
||||
"id": 1266091,
|
||||
@@ -27,7 +28,7 @@
|
||||
},
|
||||
"created_at": 1483569391,
|
||||
"updated_at": 1483569391,
|
||||
"content_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/2"
|
||||
"content_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/2"
|
||||
},
|
||||
"repository": {
|
||||
"id": 35129377,
|
||||
@@ -145,4 +146,4 @@
|
||||
"type": "User",
|
||||
"site_admin": false
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+1
@@ -39,6 +39,7 @@
|
||||
"merge_commit_sha": null,
|
||||
"assignee": null,
|
||||
"milestone": null,
|
||||
"draft": false,
|
||||
"commits_url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/1/commits",
|
||||
"review_comments_url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/1/comments",
|
||||
"review_comment_url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/comments{/number}",
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
{
|
||||
"object_kind": "merge_request",
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
|
||||
},
|
||||
"project": {
|
||||
"name": "Example",
|
||||
"description": "",
|
||||
"web_url": "http://example.com/jsmith/example",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:jsmith/example.git",
|
||||
"git_http_url": "http://example.com/jsmith/example.git",
|
||||
"namespace": "Jsmith",
|
||||
"visibility_level": 0,
|
||||
"path_with_namespace": "jsmith/example",
|
||||
"default_branch": "master",
|
||||
"ci_config_path": "",
|
||||
"homepage": "http://example.com/jsmith/example",
|
||||
"url": "git@example.com:jsmith/example.git",
|
||||
"ssh_url": "git@example.com:jsmith/example.git",
|
||||
"http_url": "http://example.com/jsmith/example.git"
|
||||
},
|
||||
"object_attributes": {
|
||||
"id": 90,
|
||||
"target_branch": "master",
|
||||
"source_branch": "ms-viewport",
|
||||
"source_project_id": 14,
|
||||
"author_id": 51,
|
||||
"assignee_id": 6,
|
||||
"title": "MS-Viewport",
|
||||
"created_at": "2017-09-20T08:31:45.944Z",
|
||||
"updated_at": "2017-09-28T12:23:42.365Z",
|
||||
"milestone_id": null,
|
||||
"state": "opened",
|
||||
"merge_status": "unchecked",
|
||||
"target_project_id": 14,
|
||||
"iid": 1,
|
||||
"description": "",
|
||||
"updated_by_id": 1,
|
||||
"merge_error": null,
|
||||
"merge_params": {
|
||||
"force_remove_source_branch": "0"
|
||||
},
|
||||
"merge_when_pipeline_succeeds": false,
|
||||
"merge_user_id": null,
|
||||
"merge_commit_sha": null,
|
||||
"deleted_at": null,
|
||||
"in_progress_merge_commit_sha": null,
|
||||
"lock_version": 5,
|
||||
"time_estimate": 0,
|
||||
"last_edited_at": "2017-09-27T12:43:37.558Z",
|
||||
"last_edited_by_id": 1,
|
||||
"head_pipeline_id": 61,
|
||||
"ref_fetched": true,
|
||||
"merge_jid": null,
|
||||
"source": {
|
||||
"name": "Awesome Project",
|
||||
"description": "",
|
||||
"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": "root",
|
||||
"visibility_level": 0,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"ci_config_path": "",
|
||||
"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": 0,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"ci_config_path": "",
|
||||
"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": "ba3e0d8ff79c80d5b0bbb4f3e2e343e0aaa662b7",
|
||||
"message": "fixed readme",
|
||||
"timestamp": "2017-09-26T16:12:57Z",
|
||||
"url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"author": {
|
||||
"name": "GitLab dev user",
|
||||
"email": "gitlabdev@dv6700.(none)"
|
||||
}
|
||||
},
|
||||
"work_in_progress": false,
|
||||
"total_time_spent": 0,
|
||||
"human_total_time_spent": null,
|
||||
"human_time_estimate": null
|
||||
},
|
||||
"labels": null,
|
||||
"repository": {
|
||||
"name": "git-gpg-test",
|
||||
"url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"description": "",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project"
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"event_name": "push",
|
||||
"before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
|
||||
"after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"ref": "refs/heads/master",
|
||||
"checkout_sha": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"user_id": 4,
|
||||
"user_name": "John Smith",
|
||||
"user_email": "john@example.com",
|
||||
"user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
|
||||
"project_id": 15,
|
||||
"project":{
|
||||
"name":"Diaspora",
|
||||
"description":"",
|
||||
"web_url":"http://example.com/mike/diaspora",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:mike/diaspora.git",
|
||||
"git_http_url":"http://example.com/mike/diaspora.git",
|
||||
"namespace":"Mike",
|
||||
"visibility_level":0,
|
||||
"path_with_namespace":"mike/diaspora",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/mike/diaspora",
|
||||
"url":"git@example.com:mike/diaspora.git",
|
||||
"ssh_url":"git@example.com:mike/diaspora.git",
|
||||
"http_url":"http://example.com/mike/diaspora.git"
|
||||
},
|
||||
"repository":{
|
||||
"name": "Diaspora",
|
||||
"url": "git@example.com:mike/diaspora.git",
|
||||
"description": "",
|
||||
"homepage": "http://example.com/mike/diaspora",
|
||||
"git_http_url":"http://example.com/mike/diaspora.git",
|
||||
"git_ssh_url":"git@example.com:mike/diaspora.git",
|
||||
"visibility_level":0
|
||||
},
|
||||
"commits": [
|
||||
{
|
||||
"id": "c5feabde2d8cd023215af4d2ceeb7a64839fc428",
|
||||
"message": "Add simple search to projects in public area",
|
||||
"timestamp": "2013-05-13T18:18:08+00:00",
|
||||
"url": "https://dev.gitlab.org/gitlab/gitlabhq/commit/c5feabde2d8cd023215af4d2ceeb7a64839fc428",
|
||||
"author": {
|
||||
"name": "Example User",
|
||||
"email": "user@example.com"
|
||||
}
|
||||
}
|
||||
],
|
||||
"total_commits_count": 1
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"event_name": "tag_push",
|
||||
"before": "0000000000000000000000000000000000000000",
|
||||
"after": "82b3d5ae55f7080f1e6022629cdb57bfae7cccc7",
|
||||
"ref": "refs/tags/v1.0.0",
|
||||
"checkout_sha": "5937ac0a7beb003549fc5fd26fc247adbce4a52e",
|
||||
"user_id": 1,
|
||||
"user_name": "John Smith",
|
||||
"user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
|
||||
"project_id": 1,
|
||||
"project":{
|
||||
"name":"Example",
|
||||
"description":"",
|
||||
"web_url":"http://example.com/jsmith/example",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:jsmith/example.git",
|
||||
"git_http_url":"http://example.com/jsmith/example.git",
|
||||
"namespace":"Jsmith",
|
||||
"visibility_level":0,
|
||||
"path_with_namespace":"jsmith/example",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/jsmith/example",
|
||||
"url":"git@example.com:jsmith/example.git",
|
||||
"ssh_url":"git@example.com:jsmith/example.git",
|
||||
"http_url":"http://example.com/jsmith/example.git"
|
||||
},
|
||||
"repository":{
|
||||
"name": "Example",
|
||||
"url": "ssh://git@example.com/jsmith/example.git",
|
||||
"description": "",
|
||||
"homepage": "http://example.com/jsmith/example",
|
||||
"git_http_url":"http://example.com/jsmith/example.git",
|
||||
"git_ssh_url":"git@example.com:jsmith/example.git",
|
||||
"visibility_level":0
|
||||
},
|
||||
"commits": [],
|
||||
"total_commits_count": 0
|
||||
}
|
||||
Reference in New Issue
Block a user