From bba5196bced02a9e88272219ad6e61518bac66dc Mon Sep 17 00:00:00 2001 From: Elliot Maincourt Date: Wed, 9 Jan 2019 05:19:54 +0100 Subject: [PATCH 1/6] [Github] Add installation_repositories event (#55) I've recently been using your type definitions while playing around with the Github Webhooks and I realised the `install_repositories` event was missing. I've added it and updated the tests. --- github/github.go | 5 ++ github/github_test.go | 10 +++ github/payload.go | 80 +++++++++++++++++++ .../github/installation-repositories.json | 77 ++++++++++++++++++ 4 files changed, 172 insertions(+) create mode 100644 testdata/github/installation-repositories.json diff --git a/github/github.go b/github/github.go index 1fee4ca..cc8d3e7 100644 --- a/github/github.go +++ b/github/github.go @@ -36,6 +36,7 @@ const ( ForkEvent Event = "fork" GollumEvent Event = "gollum" InstallationEvent Event = "installation" + InstallationRepositoriesEvent Event = "installation_repositories" IntegrationInstallationEvent Event = "integration_installation" IssueCommentEvent Event = "issue_comment" IssuesEvent Event = "issues" @@ -193,6 +194,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) var pl InstallationPayload err = json.Unmarshal([]byte(payload), &pl) return pl, err + case InstallationRepositoriesEvent: + var pl InstallationRepositoriesPayload + err = json.Unmarshal([]byte(payload), &pl) + return pl, err case IssueCommentEvent: var pl IssueCommentPayload err = json.Unmarshal([]byte(payload), &pl) diff --git a/github/github_test.go b/github/github_test.go index c41b5c4..122d562 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -213,6 +213,16 @@ func TestWebhooks(t *testing.T) { "X-Hub-Signature": []string{"sha1=2058cf6cc28570710afbc638e669f5c67305a2db"}, }, }, + { + name: "InstallationRepositoriesEvent", + event: InstallationRepositoriesEvent, + typ: InstallationRepositoriesPayload{}, + filename: "../testdata/github/installation-repositories.json", + headers: http.Header{ + "X-Github-Event": []string{"installation_repositories"}, + "X-Hub-Signature": []string{"sha1=c587fbd9dd169db8ae592b3bcc80b08e2e6f4f45"}, + }, + }, { name: "IntegrationInstallationEvent", event: IntegrationInstallationEvent, diff --git a/github/payload.go b/github/payload.go index 9291e9c..5e1592c 100644 --- a/github/payload.go +++ b/github/payload.go @@ -1073,6 +1073,86 @@ type InstallationPayload struct { } `json:"sender"` } +// InstallationRepositoriesPayload contains the information for GitHub's installation_repositories hook events +type InstallationRepositoriesPayload 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"` + VulnerabilityAlerts string `json:"vulnerability_alerts"` + Statuses string `json:"statuses"` + Administration string `json:"administration"` + Deployments string `json:"deployments"` + Contents string `json:"contents"` + } `json:"permissions"` + Events []string `json:"events"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` + SingleFileName *string `json:"single_file_name"` + } `json:"installation"` + RepositoriesAdded []struct { + ID int64 `json:"id"` + Name string `json:"name"` + FullName string `json:"full_name"` + Private bool `json:"private"` + } `json:"repositories_added"` + RepositoriesRemoved []struct { + ID int64 `json:"id"` + Name string `json:"name"` + FullName string `json:"full_name"` + Private bool `json:"private"` + } `json:"repositories_removed"` + 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 type IssueCommentPayload struct { Action string `json:"action"` diff --git a/testdata/github/installation-repositories.json b/testdata/github/installation-repositories.json new file mode 100644 index 0000000..017c4fe --- /dev/null +++ b/testdata/github/installation-repositories.json @@ -0,0 +1,77 @@ +{ + "action": "removed", + "installation": { + "id": 2, + "account": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + }, + "repository_selection": "selected", + "access_tokens_url": "https://api.github.com/installations/2/access_tokens", + "repositories_url": "https://api.github.com/installation/repositories", + "html_url": "https://github.com/settings/installations/2", + "app_id": 5725, + "target_id": 3880403, + "target_type": "User", + "permissions": { + "metadata": "read", + "contents": "read", + "issues": "write" + }, + "events": [ + "push", + "pull_request" + ], + "created_at": 1525109898, + "updated_at": 1525109899, + "single_file_name": "config.yml" + }, + "repository_selection": "selected", + "repositories_added": [ + + ], + "repositories_removed": [ + { + "id": 1296269, + "name": "Hello-World", + "full_name": "octocat/Hello-World", + "private": false + } + ], + "sender": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + } + } \ No newline at end of file From dee47c0482156a3a4eb5dea512713b98bcb23f4b Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Tue, 8 Jan 2019 20:21:48 -0800 Subject: [PATCH 2/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aa088de..bba8b88 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Library webhooks ================ -![Project status](https://img.shields.io/badge/version-5.4.0-green.svg) +![Project status](https://img.shields.io/badge/version-5.5.0-green.svg) [![Build Status](https://travis-ci.org/go-playground/webhooks.svg?branch=v5)](https://travis-ci.org/go-playground/webhooks) [![Coverage Status](https://coveralls.io/repos/go-playground/webhooks/badge.svg?branch=v5&service=github)](https://coveralls.io/github/go-playground/webhooks?branch=v5) [![Go Report Card](https://goreportcard.com/badge/go-playground/webhooks)](https://goreportcard.com/report/go-playground/webhooks) From b2ca22db96bd6da1406fdf017d172b93edc7934d Mon Sep 17 00:00:00 2001 From: Manjunath A Kumatagi Date: Tue, 12 Feb 2019 20:20:05 +0530 Subject: [PATCH 3/6] Add Label to issuespayload (#58) --- github/payload.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/github/payload.go b/github/payload.go index 5e1592c..36b6adb 100644 --- a/github/payload.go +++ b/github/payload.go @@ -1493,6 +1493,7 @@ type IssuesPayload struct { SiteAdmin bool `json:"site_admin"` } `json:"sender"` Assignee *Assignee `json:"assignee"` + Label *Label `json:"label"` } // LabelPayload contains the information for GitHub's label hook event @@ -5187,3 +5188,12 @@ type Parent struct { URL string `json:"url"` Sha string `json:"sha"` } + +// Label contains Issue's Label information +type Label struct { + ID int64 `json:"id"` + URL string `json:"url"` + Name string `json:"name"` + Color string `json:"color"` + Default bool `json:"default"` +} From e157e8e469450f09d409b709446b90b4e7ee6842 Mon Sep 17 00:00:00 2001 From: kenji sakoda Date: Tue, 12 Feb 2019 23:51:04 +0900 Subject: [PATCH 4/6] add in_reply_to_id in PullRequestReviewCommentPayload (#57) --- github/payload.go | 1 + 1 file changed, 1 insertion(+) diff --git a/github/payload.go b/github/payload.go index 36b6adb..c0c111d 100644 --- a/github/payload.go +++ b/github/payload.go @@ -3749,6 +3749,7 @@ type PullRequestReviewCommentPayload struct { Href string `json:"href"` } `json:"pull_request"` } `json:"_links"` + InReplyToId int64 `json:"in_reply_to_id"` } `json:"comment"` PullRequest struct { URL string `json:"url"` From ac198c9e6ac4688f6a29d10de34cd1a0cf6e8d9f Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Tue, 12 Feb 2019 06:52:07 -0800 Subject: [PATCH 5/6] change InReplyToId to InReplyToID --- github/payload.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/payload.go b/github/payload.go index c0c111d..69d0c77 100644 --- a/github/payload.go +++ b/github/payload.go @@ -3749,7 +3749,7 @@ type PullRequestReviewCommentPayload struct { Href string `json:"href"` } `json:"pull_request"` } `json:"_links"` - InReplyToId int64 `json:"in_reply_to_id"` + InReplyToID int64 `json:"in_reply_to_id"` } `json:"comment"` PullRequest struct { URL string `json:"url"` From a1051fd87156d8848620b91a6c8b06b2c27774fb Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Tue, 12 Feb 2019 07:05:05 -0800 Subject: [PATCH 6/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bba8b88..0650ff1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Library webhooks ================ -![Project status](https://img.shields.io/badge/version-5.5.0-green.svg) +![Project status](https://img.shields.io/badge/version-5.6.0-green.svg) [![Build Status](https://travis-ci.org/go-playground/webhooks.svg?branch=v5)](https://travis-ci.org/go-playground/webhooks) [![Coverage Status](https://coveralls.io/repos/go-playground/webhooks/badge.svg?branch=v5&service=github)](https://coveralls.io/github/go-playground/webhooks?branch=v5) [![Go Report Card](https://goreportcard.com/badge/go-playground/webhooks)](https://goreportcard.com/report/go-playground/webhooks)