Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for github_app_authorization event. #157

Merged
merged 1 commit into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,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 @@ -340,6 +341,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 @@ -573,6 +573,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 @@ -6913,3 +6913,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
}
}