Skip to content

Commit

Permalink
Support for github_app_authorization event. (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
pansachin authored May 21, 2023
1 parent 0b453ca commit 659b2a2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 10 additions & 0 deletions github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions github/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
23 changes: 23 additions & 0 deletions testdata/github/github-app-authorization.json
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 659b2a2

Please sign in to comment.