Skip to content

Commit bba5196

Browse files
emaincourtDean Karn
authored and
Dean Karn
committed
[Github] Add installation_repositories event (#55)
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.
1 parent 80aa7fa commit bba5196

File tree

4 files changed

+172
-0
lines changed

4 files changed

+172
-0
lines changed

github/github.go

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const (
3636
ForkEvent Event = "fork"
3737
GollumEvent Event = "gollum"
3838
InstallationEvent Event = "installation"
39+
InstallationRepositoriesEvent Event = "installation_repositories"
3940
IntegrationInstallationEvent Event = "integration_installation"
4041
IssueCommentEvent Event = "issue_comment"
4142
IssuesEvent Event = "issues"
@@ -193,6 +194,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
193194
var pl InstallationPayload
194195
err = json.Unmarshal([]byte(payload), &pl)
195196
return pl, err
197+
case InstallationRepositoriesEvent:
198+
var pl InstallationRepositoriesPayload
199+
err = json.Unmarshal([]byte(payload), &pl)
200+
return pl, err
196201
case IssueCommentEvent:
197202
var pl IssueCommentPayload
198203
err = json.Unmarshal([]byte(payload), &pl)

github/github_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ func TestWebhooks(t *testing.T) {
213213
"X-Hub-Signature": []string{"sha1=2058cf6cc28570710afbc638e669f5c67305a2db"},
214214
},
215215
},
216+
{
217+
name: "InstallationRepositoriesEvent",
218+
event: InstallationRepositoriesEvent,
219+
typ: InstallationRepositoriesPayload{},
220+
filename: "../testdata/github/installation-repositories.json",
221+
headers: http.Header{
222+
"X-Github-Event": []string{"installation_repositories"},
223+
"X-Hub-Signature": []string{"sha1=c587fbd9dd169db8ae592b3bcc80b08e2e6f4f45"},
224+
},
225+
},
216226
{
217227
name: "IntegrationInstallationEvent",
218228
event: IntegrationInstallationEvent,

github/payload.go

+80
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,86 @@ type InstallationPayload struct {
10731073
} `json:"sender"`
10741074
}
10751075

1076+
// InstallationRepositoriesPayload contains the information for GitHub's installation_repositories hook events
1077+
type InstallationRepositoriesPayload struct {
1078+
Action string `json:"action"`
1079+
Installation struct {
1080+
ID int64 `json:"id"`
1081+
Account struct {
1082+
Login string `json:"login"`
1083+
ID int64 `json:"id"`
1084+
AvatarURL string `json:"avatar_url"`
1085+
GravatarID string `json:"gravatar_id"`
1086+
URL string `json:"url"`
1087+
HTMLURL string `json:"html_url"`
1088+
FollowersURL string `json:"followers_url"`
1089+
FollowingURL string `json:"following_url"`
1090+
GistsURL string `json:"gists_url"`
1091+
StarredURL string `json:"starred_url"`
1092+
SubscriptionsURL string `json:"subscriptions_url"`
1093+
OrganizationsURL string `json:"organizations_url"`
1094+
ReposURL string `json:"repos_url"`
1095+
EventsURL string `json:"events_url"`
1096+
ReceivedEventsURL string `json:"received_events_url"`
1097+
Type string `json:"type"`
1098+
SiteAdmin bool `json:"site_admin"`
1099+
} `json:"account"`
1100+
RepositorySelection string `json:"repository_selection"`
1101+
AccessTokensURL string `json:"access_tokens_url"`
1102+
RepositoriesURL string `json:"repositories_url"`
1103+
HTMLURL string `json:"html_url"`
1104+
AppID int `json:"app_id"`
1105+
TargetID int `json:"target_id"`
1106+
TargetType string `json:"target_type"`
1107+
Permissions struct {
1108+
Issues string `json:"issues"`
1109+
Metadata string `json:"metadata"`
1110+
PullRequests string `json:"pull_requests"`
1111+
RepositoryProjects string `json:"repository_projects"`
1112+
VulnerabilityAlerts string `json:"vulnerability_alerts"`
1113+
Statuses string `json:"statuses"`
1114+
Administration string `json:"administration"`
1115+
Deployments string `json:"deployments"`
1116+
Contents string `json:"contents"`
1117+
} `json:"permissions"`
1118+
Events []string `json:"events"`
1119+
CreatedAt int64 `json:"created_at"`
1120+
UpdatedAt int64 `json:"updated_at"`
1121+
SingleFileName *string `json:"single_file_name"`
1122+
} `json:"installation"`
1123+
RepositoriesAdded []struct {
1124+
ID int64 `json:"id"`
1125+
Name string `json:"name"`
1126+
FullName string `json:"full_name"`
1127+
Private bool `json:"private"`
1128+
} `json:"repositories_added"`
1129+
RepositoriesRemoved []struct {
1130+
ID int64 `json:"id"`
1131+
Name string `json:"name"`
1132+
FullName string `json:"full_name"`
1133+
Private bool `json:"private"`
1134+
} `json:"repositories_removed"`
1135+
Sender struct {
1136+
Login string `json:"login"`
1137+
ID int64 `json:"id"`
1138+
AvatarURL string `json:"avatar_url"`
1139+
GravatarID string `json:"gravatar_id"`
1140+
URL string `json:"url"`
1141+
HTMLURL string `json:"html_url"`
1142+
FollowersURL string `json:"followers_url"`
1143+
FollowingURL string `json:"following_url"`
1144+
GistsURL string `json:"gists_url"`
1145+
StarredURL string `json:"starred_url"`
1146+
SubscriptionsURL string `json:"subscriptions_url"`
1147+
OrganizationsURL string `json:"organizations_url"`
1148+
ReposURL string `json:"repos_url"`
1149+
EventsURL string `json:"events_url"`
1150+
ReceivedEventsURL string `json:"received_events_url"`
1151+
Type string `json:"type"`
1152+
SiteAdmin bool `json:"site_admin"`
1153+
} `json:"sender"`
1154+
}
1155+
10761156
// IssueCommentPayload contains the information for GitHub's issue_comment hook event
10771157
type IssueCommentPayload struct {
10781158
Action string `json:"action"`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"action": "removed",
3+
"installation": {
4+
"id": 2,
5+
"account": {
6+
"login": "octocat",
7+
"id": 1,
8+
"node_id": "MDQ6VXNlcjE=",
9+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
10+
"gravatar_id": "",
11+
"url": "https://api.github.com/users/octocat",
12+
"html_url": "https://github.com/octocat",
13+
"followers_url": "https://api.github.com/users/octocat/followers",
14+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
15+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
16+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
17+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
18+
"organizations_url": "https://api.github.com/users/octocat/orgs",
19+
"repos_url": "https://api.github.com/users/octocat/repos",
20+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
21+
"received_events_url": "https://api.github.com/users/octocat/received_events",
22+
"type": "User",
23+
"site_admin": false
24+
},
25+
"repository_selection": "selected",
26+
"access_tokens_url": "https://api.github.com/installations/2/access_tokens",
27+
"repositories_url": "https://api.github.com/installation/repositories",
28+
"html_url": "https://github.com/settings/installations/2",
29+
"app_id": 5725,
30+
"target_id": 3880403,
31+
"target_type": "User",
32+
"permissions": {
33+
"metadata": "read",
34+
"contents": "read",
35+
"issues": "write"
36+
},
37+
"events": [
38+
"push",
39+
"pull_request"
40+
],
41+
"created_at": 1525109898,
42+
"updated_at": 1525109899,
43+
"single_file_name": "config.yml"
44+
},
45+
"repository_selection": "selected",
46+
"repositories_added": [
47+
48+
],
49+
"repositories_removed": [
50+
{
51+
"id": 1296269,
52+
"name": "Hello-World",
53+
"full_name": "octocat/Hello-World",
54+
"private": false
55+
}
56+
],
57+
"sender": {
58+
"login": "octocat",
59+
"id": 1,
60+
"node_id": "MDQ6VXNlcjE=",
61+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
62+
"gravatar_id": "",
63+
"url": "https://api.github.com/users/octocat",
64+
"html_url": "https://github.com/octocat",
65+
"followers_url": "https://api.github.com/users/octocat/followers",
66+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
67+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
68+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
69+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
70+
"organizations_url": "https://api.github.com/users/octocat/orgs",
71+
"repos_url": "https://api.github.com/users/octocat/repos",
72+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
73+
"received_events_url": "https://api.github.com/users/octocat/received_events",
74+
"type": "User",
75+
"site_admin": false
76+
}
77+
}

0 commit comments

Comments
 (0)