From 659b2a276b2274719c30d765f4328ed340f01904 Mon Sep 17 00:00:00 2001 From: Sachin Prasad <83265393+pansachin@users.noreply.github.com> Date: Sun, 21 May 2023 20:28:41 +0530 Subject: [PATCH] Support for `github_app_authorization` event. (#157) Adding support for [github_app_authorization](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#github_app_authorization) event. --- github/github.go | 5 ++++ github/github_test.go | 10 ++++++++ github/payload.go | 25 +++++++++++++++++++ testdata/github/github-app-authorization.json | 23 +++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 testdata/github/github-app-authorization.json diff --git a/github/github.go b/github/github.go index 8d7fc95..2578556 100644 --- a/github/github.go +++ b/github/github.go @@ -73,6 +73,7 @@ const ( WorkflowDispatchEvent Event = "workflow_dispatch" WorkflowJobEvent Event = "workflow_job" WorkflowRunEvent Event = "workflow_run" + GitHubAppAuthorizationEvent Event = "github_app_authorization" ) // EventSubtype defines a GitHub Hook Event subtype @@ -345,6 +346,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) var pl WorkflowRunPayload err = json.Unmarshal([]byte(payload), &pl) return pl, err + case GitHubAppAuthorizationEvent: + var pl GitHubAppAuthorizationPayload + err = json.Unmarshal([]byte(payload), &pl) + return pl, err default: return nil, fmt.Errorf("unknown event %s", gitHubEvent) } diff --git a/github/github_test.go b/github/github_test.go index c2f6b96..15d49f2 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -593,6 +593,16 @@ func TestWebhooks(t *testing.T) { "X-Hub-Signature": []string{"sha1=c54d046b1ce440bc3434c8de5ad73e0a630d7cbe"}, }, }, + { + name: "GitHubAppAuthorizationEvent", + event: GitHubAppAuthorizationEvent, + typ: GitHubAppAuthorizationPayload{}, + filename: "../testdata/github/github-app-authorization.json", + headers: http.Header{ + "X-Github-Event": []string{"github_app_authorization"}, + "X-Hub-Signature": []string{"sha1=4f18624a7fe3a9c525b51bdbd0e3da8230d753d6"}, + }, + }, } for _, tt := range tests { diff --git a/github/payload.go b/github/payload.go index be87f35..a544fbb 100644 --- a/github/payload.go +++ b/github/payload.go @@ -7142,3 +7142,28 @@ type Step struct { StartedAt time.Time `json:"started_at"` CompletedAt time.Time `json:"completed_at"` } + +// GitHubAppAuthorizationPayload contains revoke action payload +type GitHubAppAuthorizationPayload struct { + Action string `json:"action"` + Sender struct { + Login string `json:"login"` + ID int64 `json:"id"` + NodeID string `json:"node_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:"orranizations_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"` +} diff --git a/testdata/github/github-app-authorization.json b/testdata/github/github-app-authorization.json new file mode 100644 index 0000000..c509f44 --- /dev/null +++ b/testdata/github/github-app-authorization.json @@ -0,0 +1,23 @@ +{ + "action": "revoked", + "sender": { + "login": "pansachin", + "id": 83265393, + "node_id": "MDQ6VXNlcjgzMjY1Mzkz", + "avatar_url": "https://avatars.githubusercontent.com/u/83265393?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/pansachin", + "html_url": "https://github.com/pansachin", + "followers_url": "https://api.github.com/users/pansachin/followers", + "following_url": "https://api.github.com/users/pansachin/following{/other_user}", + "gists_url": "https://api.github.com/users/pansachin/gists{/gist_id}", + "starred_url": "https://api.github.com/users/pansachin/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/pansachin/subscriptions", + "organizations_url": "https://api.github.com/users/pansachin/orgs", + "repos_url": "https://api.github.com/users/pansachin/repos", + "events_url": "https://api.github.com/users/pansachin/events{/privacy}", + "received_events_url": "https://api.github.com/users/pansachin/received_events", + "type": "User", + "site_admin": false + } +}