Skip to content

Commit

Permalink
[Github] Add installation_repositories event (#55)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
emaincourt authored and deankarn committed Jan 9, 2019
1 parent 80aa7fa commit bba5196
Show file tree
Hide file tree
Showing 4 changed files with 172 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 @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
80 changes: 80 additions & 0 deletions github/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
77 changes: 77 additions & 0 deletions testdata/github/installation-repositories.json
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit bba5196

Please sign in to comment.