Skip to content

Commit 94f9d66

Browse files
author
Pedro Pombeiro
committed
Add support for installation and integration_installation events
1 parent ad53921 commit 94f9d66

File tree

3 files changed

+256
-0
lines changed

3 files changed

+256
-0
lines changed

github/github.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const (
3636
DeploymentStatusEvent Event = "deployment_status"
3737
ForkEvent Event = "fork"
3838
GollumEvent Event = "gollum"
39+
InstallationEvent Event = "installation"
40+
IntegrationInstallationEvent Event = "integration_installation"
3941
IssueCommentEvent Event = "issue_comment"
4042
IssuesEvent Event = "issues"
4143
LabelEvent Event = "label"
@@ -179,6 +181,10 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
179181
var g GollumPayload
180182
json.Unmarshal([]byte(payload), &g)
181183
hook.runProcessPayloadFunc(fn, g, hd)
184+
case InstallationEvent, IntegrationInstallationEvent:
185+
var i InstallationPayload
186+
json.Unmarshal([]byte(payload), &i)
187+
hook.runProcessPayloadFunc(fn, i, hd)
182188
case IssueCommentEvent:
183189
var i IssueCommentPayload
184190
json.Unmarshal([]byte(payload), &i)

github/github_test.go

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func TestMain(m *testing.M) {
4848
DeploymentStatusEvent,
4949
ForkEvent,
5050
GollumEvent,
51+
InstallationEvent,
52+
IntegrationInstallationEvent,
5153
IssueCommentEvent,
5254
IssuesEvent,
5355
LabelEvent,
@@ -1309,6 +1311,186 @@ func TestGollumEvent(t *testing.T) {
13091311
Equal(t, resp.StatusCode, http.StatusOK)
13101312
}
13111313

1314+
func TestInstallationEvent(t *testing.T) {
1315+
1316+
payload := `{
1317+
"action": "created",
1318+
"installation": {
1319+
"id": 80429,
1320+
"account": {
1321+
"login": "PombeirP",
1322+
"id": 138074,
1323+
"avatar_url": "https://avatars1.githubusercontent.com/u/138074?v=4",
1324+
"gravatar_id": "",
1325+
"url": "https://api.github.com/users/PombeirP",
1326+
"html_url": "https://github.com/PombeirP",
1327+
"followers_url": "https://api.github.com/users/PombeirP/followers",
1328+
"following_url": "https://api.github.com/users/PombeirP/following{/other_user}",
1329+
"gists_url": "https://api.github.com/users/PombeirP/gists{/gist_id}",
1330+
"starred_url": "https://api.github.com/users/PombeirP/starred{/owner}{/repo}",
1331+
"subscriptions_url": "https://api.github.com/users/PombeirP/subscriptions",
1332+
"organizations_url": "https://api.github.com/users/PombeirP/orgs",
1333+
"repos_url": "https://api.github.com/users/PombeirP/repos",
1334+
"events_url": "https://api.github.com/users/PombeirP/events{/privacy}",
1335+
"received_events_url": "https://api.github.com/users/PombeirP/received_events",
1336+
"type": "User",
1337+
"site_admin": false
1338+
},
1339+
"repository_selection": "selected",
1340+
"access_tokens_url": "https://api.github.com/installations/80429/access_tokens",
1341+
"repositories_url": "https://api.github.com/installation/repositories",
1342+
"html_url": "https://github.com/settings/installations/80429",
1343+
"app_id": 8157,
1344+
"target_id": 138074,
1345+
"target_type": "User",
1346+
"permissions": {
1347+
"repository_projects": "write",
1348+
"issues": "read",
1349+
"metadata": "read",
1350+
"pull_requests": "read"
1351+
},
1352+
"events": [
1353+
"pull_request"
1354+
],
1355+
"created_at": 1516025475,
1356+
"updated_at": 1516025475,
1357+
"single_file_name": null
1358+
},
1359+
"repositories": [
1360+
{
1361+
"id": 117381220,
1362+
"name": "status-github-bot",
1363+
"full_name": "PombeirP/status-github-bot"
1364+
}
1365+
],
1366+
"sender": {
1367+
"login": "PombeirP",
1368+
"id": 138074,
1369+
"avatar_url": "https://avatars1.githubusercontent.com/u/138074?v=4",
1370+
"gravatar_id": "",
1371+
"url": "https://api.github.com/users/PombeirP",
1372+
"html_url": "https://github.com/PombeirP",
1373+
"followers_url": "https://api.github.com/users/PombeirP/followers",
1374+
"following_url": "https://api.github.com/users/PombeirP/following{/other_user}",
1375+
"gists_url": "https://api.github.com/users/PombeirP/gists{/gist_id}",
1376+
"starred_url": "https://api.github.com/users/PombeirP/starred{/owner}{/repo}",
1377+
"subscriptions_url": "https://api.github.com/users/PombeirP/subscriptions",
1378+
"organizations_url": "https://api.github.com/users/PombeirP/orgs",
1379+
"repos_url": "https://api.github.com/users/PombeirP/repos",
1380+
"events_url": "https://api.github.com/users/PombeirP/events{/privacy}",
1381+
"received_events_url": "https://api.github.com/users/PombeirP/received_events",
1382+
"type": "User",
1383+
"site_admin": false
1384+
}
1385+
}
1386+
`
1387+
1388+
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
1389+
req.Header.Set("Content-Type", "application/json")
1390+
req.Header.Set("X-Github-Event", "installation")
1391+
req.Header.Set("X-Hub-Signature", "sha1=987338c6e5c21794ab6c258abe51284f9b1df728")
1392+
1393+
Equal(t, err, nil)
1394+
1395+
client := &http.Client{}
1396+
resp, err := client.Do(req)
1397+
Equal(t, err, nil)
1398+
1399+
defer resp.Body.Close()
1400+
1401+
Equal(t, resp.StatusCode, http.StatusOK)
1402+
}
1403+
1404+
func TestIntegrationInstallationEvent(t *testing.T) {
1405+
1406+
payload := `{
1407+
"action": "created",
1408+
"installation": {
1409+
"id": 80429,
1410+
"account": {
1411+
"login": "PombeirP",
1412+
"id": 138074,
1413+
"avatar_url": "https://avatars1.githubusercontent.com/u/138074?v=4",
1414+
"gravatar_id": "",
1415+
"url": "https://api.github.com/users/PombeirP",
1416+
"html_url": "https://github.com/PombeirP",
1417+
"followers_url": "https://api.github.com/users/PombeirP/followers",
1418+
"following_url": "https://api.github.com/users/PombeirP/following{/other_user}",
1419+
"gists_url": "https://api.github.com/users/PombeirP/gists{/gist_id}",
1420+
"starred_url": "https://api.github.com/users/PombeirP/starred{/owner}{/repo}",
1421+
"subscriptions_url": "https://api.github.com/users/PombeirP/subscriptions",
1422+
"organizations_url": "https://api.github.com/users/PombeirP/orgs",
1423+
"repos_url": "https://api.github.com/users/PombeirP/repos",
1424+
"events_url": "https://api.github.com/users/PombeirP/events{/privacy}",
1425+
"received_events_url": "https://api.github.com/users/PombeirP/received_events",
1426+
"type": "User",
1427+
"site_admin": false
1428+
},
1429+
"repository_selection": "selected",
1430+
"access_tokens_url": "https://api.github.com/installations/80429/access_tokens",
1431+
"repositories_url": "https://api.github.com/installation/repositories",
1432+
"html_url": "https://github.com/settings/installations/80429",
1433+
"app_id": 8157,
1434+
"target_id": 138074,
1435+
"target_type": "User",
1436+
"permissions": {
1437+
"repository_projects": "write",
1438+
"issues": "read",
1439+
"metadata": "read",
1440+
"pull_requests": "read"
1441+
},
1442+
"events": [
1443+
"pull_request"
1444+
],
1445+
"created_at": 1516025475,
1446+
"updated_at": 1516025475,
1447+
"single_file_name": null
1448+
},
1449+
"repositories": [
1450+
{
1451+
"id": 117381220,
1452+
"name": "status-github-bot",
1453+
"full_name": "PombeirP/status-github-bot"
1454+
}
1455+
],
1456+
"sender": {
1457+
"login": "PombeirP",
1458+
"id": 138074,
1459+
"avatar_url": "https://avatars1.githubusercontent.com/u/138074?v=4",
1460+
"gravatar_id": "",
1461+
"url": "https://api.github.com/users/PombeirP",
1462+
"html_url": "https://github.com/PombeirP",
1463+
"followers_url": "https://api.github.com/users/PombeirP/followers",
1464+
"following_url": "https://api.github.com/users/PombeirP/following{/other_user}",
1465+
"gists_url": "https://api.github.com/users/PombeirP/gists{/gist_id}",
1466+
"starred_url": "https://api.github.com/users/PombeirP/starred{/owner}{/repo}",
1467+
"subscriptions_url": "https://api.github.com/users/PombeirP/subscriptions",
1468+
"organizations_url": "https://api.github.com/users/PombeirP/orgs",
1469+
"repos_url": "https://api.github.com/users/PombeirP/repos",
1470+
"events_url": "https://api.github.com/users/PombeirP/events{/privacy}",
1471+
"received_events_url": "https://api.github.com/users/PombeirP/received_events",
1472+
"type": "User",
1473+
"site_admin": false
1474+
}
1475+
}
1476+
`
1477+
1478+
req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload)))
1479+
req.Header.Set("Content-Type", "application/json")
1480+
req.Header.Set("X-Github-Event", "integration_installation")
1481+
req.Header.Set("X-Hub-Signature", "sha1=987338c6e5c21794ab6c258abe51284f9b1df728")
1482+
1483+
Equal(t, err, nil)
1484+
1485+
client := &http.Client{}
1486+
resp, err := client.Do(req)
1487+
Equal(t, err, nil)
1488+
1489+
defer resp.Body.Close()
1490+
1491+
Equal(t, resp.StatusCode, http.StatusOK)
1492+
}
1493+
13121494
func TestIssueCommentEvent(t *testing.T) {
13131495

13141496
payload := `{

github/payload.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,74 @@ type GollumPayload struct {
10071007
} `json:"sender"`
10081008
}
10091009

1010+
// InstallationPayload contains the information for GitHub's installation and integration_installation hook events
1011+
type InstallationPayload struct {
1012+
Action string `json:"action"`
1013+
Installation struct {
1014+
ID int64 `json:"id"`
1015+
Account struct {
1016+
Login string `json:"login"`
1017+
ID int64 `json:"id"`
1018+
AvatarURL string `json:"avatar_url"`
1019+
GravatarID string `json:"gravatar_id"`
1020+
URL string `json:"url"`
1021+
HTMLURL string `json:"html_url"`
1022+
FollowersURL string `json:"followers_url"`
1023+
FollowingURL string `json:"following_url"`
1024+
GistsURL string `json:"gists_url"`
1025+
StarredURL string `json:"starred_url"`
1026+
SubscriptionsURL string `json:"subscriptions_url"`
1027+
OrganizationsURL string `json:"organizations_url"`
1028+
ReposURL string `json:"repos_url"`
1029+
EventsURL string `json:"events_url"`
1030+
ReceivedEventsURL string `json:"received_events_url"`
1031+
Type string `json:"type"`
1032+
SiteAdmin bool `json:"site_admin"`
1033+
} `json:"account"`
1034+
RepositorySelection string `json:"repository_selection"`
1035+
AccessTokensURL string `json:"access_tokens_url"`
1036+
RepositoriesURL string `json:"repositories_url"`
1037+
HTMLURL string `json:"html_url"`
1038+
AppID int `json:"app_id"`
1039+
TargetID int `json:"target_id"`
1040+
TargetType string `json:"target_type"`
1041+
Permissions struct {
1042+
Issues string `json:"issues"`
1043+
Metadata string `json:"metadata"`
1044+
PullRequests string `json:"pull_requests"`
1045+
RepositoryProjects string `json:"repository_projects"`
1046+
} `json:"permissions"`
1047+
Events []string `json:"events"`
1048+
CreatedAt int64 `json:"created_at"`
1049+
UpdatedAt int64 `json:"updated_at"`
1050+
SingleFileName *string `json:"single_file_name"`
1051+
} `json:"installation"`
1052+
Repositories []struct {
1053+
ID int64 `json:"id"`
1054+
Name string `json:"name"`
1055+
FullName string `json:"full_name"`
1056+
} `json:"repositories"`
1057+
Sender struct {
1058+
Login string `json:"login"`
1059+
ID int64 `json:"id"`
1060+
AvatarURL string `json:"avatar_url"`
1061+
GravatarID string `json:"gravatar_id"`
1062+
URL string `json:"url"`
1063+
HTMLURL string `json:"html_url"`
1064+
FollowersURL string `json:"followers_url"`
1065+
FollowingURL string `json:"following_url"`
1066+
GistsURL string `json:"gists_url"`
1067+
StarredURL string `json:"starred_url"`
1068+
SubscriptionsURL string `json:"subscriptions_url"`
1069+
OrganizationsURL string `json:"organizations_url"`
1070+
ReposURL string `json:"repos_url"`
1071+
EventsURL string `json:"events_url"`
1072+
ReceivedEventsURL string `json:"received_events_url"`
1073+
Type string `json:"type"`
1074+
SiteAdmin bool `json:"site_admin"`
1075+
} `json:"sender"`
1076+
}
1077+
10101078
// IssueCommentPayload contains the information for GitHub's issue_comment hook event
10111079
type IssueCommentPayload struct {
10121080
Action string `json:"action"`

0 commit comments

Comments
 (0)