Skip to content

Commit 659b2a2

Browse files
authored
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.
1 parent 0b453ca commit 659b2a2

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

github/github.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const (
7373
WorkflowDispatchEvent Event = "workflow_dispatch"
7474
WorkflowJobEvent Event = "workflow_job"
7575
WorkflowRunEvent Event = "workflow_run"
76+
GitHubAppAuthorizationEvent Event = "github_app_authorization"
7677
)
7778

7879
// EventSubtype defines a GitHub Hook Event subtype
@@ -345,6 +346,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
345346
var pl WorkflowRunPayload
346347
err = json.Unmarshal([]byte(payload), &pl)
347348
return pl, err
349+
case GitHubAppAuthorizationEvent:
350+
var pl GitHubAppAuthorizationPayload
351+
err = json.Unmarshal([]byte(payload), &pl)
352+
return pl, err
348353
default:
349354
return nil, fmt.Errorf("unknown event %s", gitHubEvent)
350355
}

github/github_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,16 @@ func TestWebhooks(t *testing.T) {
593593
"X-Hub-Signature": []string{"sha1=c54d046b1ce440bc3434c8de5ad73e0a630d7cbe"},
594594
},
595595
},
596+
{
597+
name: "GitHubAppAuthorizationEvent",
598+
event: GitHubAppAuthorizationEvent,
599+
typ: GitHubAppAuthorizationPayload{},
600+
filename: "../testdata/github/github-app-authorization.json",
601+
headers: http.Header{
602+
"X-Github-Event": []string{"github_app_authorization"},
603+
"X-Hub-Signature": []string{"sha1=4f18624a7fe3a9c525b51bdbd0e3da8230d753d6"},
604+
},
605+
},
596606
}
597607

598608
for _, tt := range tests {

github/payload.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7142,3 +7142,28 @@ type Step struct {
71427142
StartedAt time.Time `json:"started_at"`
71437143
CompletedAt time.Time `json:"completed_at"`
71447144
}
7145+
7146+
// GitHubAppAuthorizationPayload contains revoke action payload
7147+
type GitHubAppAuthorizationPayload struct {
7148+
Action string `json:"action"`
7149+
Sender struct {
7150+
Login string `json:"login"`
7151+
ID int64 `json:"id"`
7152+
NodeID string `json:"node_id"`
7153+
AvatarURL string `json:"avatar_url"`
7154+
GravatarID string `json:"gravatar_id"`
7155+
URL string `json:"url"`
7156+
HTMLURL string `json:"html_url"`
7157+
FollowersURL string `json:"followers_url"`
7158+
FollowingURL string `json:"following_url"`
7159+
GistsURL string `json:"gists_url"`
7160+
StarredURL string `json:"starred_url"`
7161+
SubscriptionsURL string `json:"subscriptions_url"`
7162+
OrganizationsURL string `json:"orranizations_url"`
7163+
ReposURL string `json:"repos_url"`
7164+
EventsURL string `json:"events_url"`
7165+
ReceivedEventsURL string `json:"received_events_url"`
7166+
Type string `json:"type"`
7167+
SiteAdmin bool `json:"site_admin"`
7168+
} `json:"sender"`
7169+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"action": "revoked",
3+
"sender": {
4+
"login": "pansachin",
5+
"id": 83265393,
6+
"node_id": "MDQ6VXNlcjgzMjY1Mzkz",
7+
"avatar_url": "https://avatars.githubusercontent.com/u/83265393?v=4",
8+
"gravatar_id": "",
9+
"url": "https://api.github.com/users/pansachin",
10+
"html_url": "https://github.com/pansachin",
11+
"followers_url": "https://api.github.com/users/pansachin/followers",
12+
"following_url": "https://api.github.com/users/pansachin/following{/other_user}",
13+
"gists_url": "https://api.github.com/users/pansachin/gists{/gist_id}",
14+
"starred_url": "https://api.github.com/users/pansachin/starred{/owner}{/repo}",
15+
"subscriptions_url": "https://api.github.com/users/pansachin/subscriptions",
16+
"organizations_url": "https://api.github.com/users/pansachin/orgs",
17+
"repos_url": "https://api.github.com/users/pansachin/repos",
18+
"events_url": "https://api.github.com/users/pansachin/events{/privacy}",
19+
"received_events_url": "https://api.github.com/users/pansachin/received_events",
20+
"type": "User",
21+
"site_admin": false
22+
}
23+
}

0 commit comments

Comments
 (0)