Skip to content

Commit 461d387

Browse files
Implement installation_target webhook event type (#2829)
1 parent d783bb1 commit 461d387

File tree

7 files changed

+582
-0
lines changed

7 files changed

+582
-0
lines changed

github/event.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
6767
payload = &InstallationEvent{}
6868
case "InstallationRepositoriesEvent":
6969
payload = &InstallationRepositoriesEvent{}
70+
case "InstallationTargetEvent":
71+
payload = &InstallationTargetEvent{}
7072
case "IssueCommentEvent":
7173
payload = &IssueCommentEvent{}
7274
case "IssuesEvent":

github/event_types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,38 @@ type InstallationRepositoriesEvent struct {
505505
Installation *Installation `json:"installation,omitempty"`
506506
}
507507

508+
// InstallationLoginChange represents a change in login on an installation.
509+
type InstallationLoginChange struct {
510+
From *string `json:"from,omitempty"`
511+
}
512+
513+
// InstallationSlugChange represents a change in slug on an installation.
514+
type InstallationSlugChange struct {
515+
From *string `json:"from,omitempty"`
516+
}
517+
518+
// InstallationChanges represents a change in slug or login on an installation.
519+
type InstallationChanges struct {
520+
Login *InstallationLoginChange `json:"login,omitempty"`
521+
Slug *InstallationSlugChange `json:"slug,omitempty"`
522+
}
523+
524+
// InstallationTargetEvent is triggered when there is activity on an installation from a user or organization account.
525+
// The Webhook event name is "installation_target".
526+
//
527+
// GitHub API docs: https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#installation_target
528+
type InstallationTargetEvent struct {
529+
Account *User `json:"account,omitempty"`
530+
Action *string `json:"action,omitempty"`
531+
Changes *InstallationChanges `json:"changes,omitempty"`
532+
Enterprise *Enterprise `json:"enterprise,omitempty"`
533+
Installation *Installation `json:"installation,omitempty"`
534+
Organization *Organization `json:"organization,omitempty"`
535+
Repository *Repository `json:"repository,omitempty"`
536+
Sender *User `json:"sender,omitempty"`
537+
TargetType *string `json:"target_type,omitempty"`
538+
}
539+
508540
// IssueCommentEvent is triggered when an issue comment is created on an issue
509541
// or pull request.
510542
// The Webhook event name is "issue_comment".

github/event_types_test.go

Lines changed: 336 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,342 @@ func TestInstallationRepositoriesEvent_Marshal(t *testing.T) {
13321332
testJSONMarshal(t, u, want)
13331333
}
13341334

1335+
func TestInstallationTargetEvent_Marshal(t *testing.T) {
1336+
testJSONMarshal(t, &InstallationTargetEvent{}, "{}")
1337+
1338+
u := &InstallationTargetEvent{
1339+
Account: &User{
1340+
Login: String("u"),
1341+
ID: Int64(1),
1342+
NodeID: String("n"),
1343+
URL: String("u"),
1344+
ReposURL: String("r"),
1345+
EventsURL: String("e"),
1346+
AvatarURL: String("l"),
1347+
},
1348+
Action: String("a"),
1349+
Changes: &InstallationChanges{
1350+
Login: &InstallationLoginChange{
1351+
From: String("p"),
1352+
},
1353+
Slug: &InstallationSlugChange{
1354+
From: String("j"),
1355+
},
1356+
},
1357+
Enterprise: &Enterprise{
1358+
ID: Int(1),
1359+
Slug: String("s"),
1360+
Name: String("n"),
1361+
NodeID: String("nid"),
1362+
AvatarURL: String("au"),
1363+
Description: String("d"),
1364+
WebsiteURL: String("wu"),
1365+
HTMLURL: String("hu"),
1366+
CreatedAt: &Timestamp{referenceTime},
1367+
UpdatedAt: &Timestamp{referenceTime},
1368+
},
1369+
Installation: &Installation{
1370+
ID: Int64(1),
1371+
NodeID: String("nid"),
1372+
AppID: Int64(1),
1373+
AppSlug: String("as"),
1374+
TargetID: Int64(1),
1375+
Account: &User{
1376+
Login: String("l"),
1377+
ID: Int64(1),
1378+
URL: String("u"),
1379+
AvatarURL: String("a"),
1380+
GravatarID: String("g"),
1381+
Name: String("n"),
1382+
Company: String("c"),
1383+
Blog: String("b"),
1384+
Location: String("l"),
1385+
Email: String("e"),
1386+
Hireable: Bool(true),
1387+
Bio: String("b"),
1388+
TwitterUsername: String("t"),
1389+
PublicRepos: Int(1),
1390+
Followers: Int(1),
1391+
Following: Int(1),
1392+
CreatedAt: &Timestamp{referenceTime},
1393+
SuspendedAt: &Timestamp{referenceTime},
1394+
},
1395+
AccessTokensURL: String("atu"),
1396+
RepositoriesURL: String("ru"),
1397+
HTMLURL: String("hu"),
1398+
TargetType: String("tt"),
1399+
SingleFileName: String("sfn"),
1400+
RepositorySelection: String("rs"),
1401+
Events: []string{"e"},
1402+
SingleFilePaths: []string{"s"},
1403+
Permissions: &InstallationPermissions{
1404+
Actions: String("a"),
1405+
Administration: String("ad"),
1406+
Checks: String("c"),
1407+
Contents: String("co"),
1408+
ContentReferences: String("cr"),
1409+
Deployments: String("d"),
1410+
Environments: String("e"),
1411+
Issues: String("i"),
1412+
Metadata: String("md"),
1413+
Members: String("m"),
1414+
OrganizationAdministration: String("oa"),
1415+
OrganizationHooks: String("oh"),
1416+
OrganizationPlan: String("op"),
1417+
OrganizationPreReceiveHooks: String("opr"),
1418+
OrganizationProjects: String("op"),
1419+
OrganizationSecrets: String("os"),
1420+
OrganizationSelfHostedRunners: String("osh"),
1421+
OrganizationUserBlocking: String("oub"),
1422+
Packages: String("pkg"),
1423+
Pages: String("pg"),
1424+
PullRequests: String("pr"),
1425+
RepositoryHooks: String("rh"),
1426+
RepositoryProjects: String("rp"),
1427+
RepositoryPreReceiveHooks: String("rprh"),
1428+
Secrets: String("s"),
1429+
SecretScanningAlerts: String("ssa"),
1430+
SecurityEvents: String("se"),
1431+
SingleFile: String("sf"),
1432+
Statuses: String("s"),
1433+
TeamDiscussions: String("td"),
1434+
VulnerabilityAlerts: String("va"),
1435+
Workflows: String("w"),
1436+
},
1437+
CreatedAt: &Timestamp{referenceTime},
1438+
UpdatedAt: &Timestamp{referenceTime},
1439+
HasMultipleSingleFiles: Bool(false),
1440+
SuspendedBy: &User{
1441+
Login: String("l"),
1442+
ID: Int64(1),
1443+
URL: String("u"),
1444+
AvatarURL: String("a"),
1445+
GravatarID: String("g"),
1446+
Name: String("n"),
1447+
Company: String("c"),
1448+
Blog: String("b"),
1449+
Location: String("l"),
1450+
Email: String("e"),
1451+
Hireable: Bool(true),
1452+
Bio: String("b"),
1453+
TwitterUsername: String("t"),
1454+
PublicRepos: Int(1),
1455+
Followers: Int(1),
1456+
Following: Int(1),
1457+
CreatedAt: &Timestamp{referenceTime},
1458+
SuspendedAt: &Timestamp{referenceTime},
1459+
},
1460+
SuspendedAt: &Timestamp{referenceTime},
1461+
},
1462+
Organization: &Organization{
1463+
BillingEmail: String("be"),
1464+
Blog: String("b"),
1465+
Company: String("c"),
1466+
Email: String("e"),
1467+
TwitterUsername: String("tu"),
1468+
Location: String("loc"),
1469+
Name: String("n"),
1470+
Description: String("d"),
1471+
IsVerified: Bool(true),
1472+
HasOrganizationProjects: Bool(true),
1473+
HasRepositoryProjects: Bool(true),
1474+
DefaultRepoPermission: String("drp"),
1475+
MembersCanCreateRepos: Bool(true),
1476+
MembersCanCreateInternalRepos: Bool(true),
1477+
MembersCanCreatePrivateRepos: Bool(true),
1478+
MembersCanCreatePublicRepos: Bool(false),
1479+
MembersAllowedRepositoryCreationType: String("marct"),
1480+
MembersCanCreatePages: Bool(true),
1481+
MembersCanCreatePublicPages: Bool(false),
1482+
MembersCanCreatePrivatePages: Bool(true),
1483+
},
1484+
Repository: &Repository{
1485+
ID: Int64(1),
1486+
URL: String("s"),
1487+
Name: String("n"),
1488+
},
1489+
Sender: &User{
1490+
Login: String("l"),
1491+
ID: Int64(1),
1492+
NodeID: String("n"),
1493+
URL: String("u"),
1494+
ReposURL: String("r"),
1495+
EventsURL: String("e"),
1496+
AvatarURL: String("a"),
1497+
},
1498+
TargetType: String("running"),
1499+
}
1500+
1501+
want := `{
1502+
"account": {
1503+
"login": "u",
1504+
"id": 1,
1505+
"node_id": "n",
1506+
"avatar_url": "l",
1507+
"url": "u",
1508+
"events_url": "e",
1509+
"repos_url": "r"
1510+
},
1511+
"action": "a",
1512+
"changes": {
1513+
"login": {
1514+
"from": "p"
1515+
},
1516+
"slug": {
1517+
"from": "j"
1518+
}
1519+
},
1520+
"enterprise": {
1521+
"id": 1,
1522+
"slug": "s",
1523+
"name": "n",
1524+
"node_id": "nid",
1525+
"avatar_url": "au",
1526+
"description": "d",
1527+
"website_url": "wu",
1528+
"html_url": "hu",
1529+
"created_at": ` + referenceTimeStr + `,
1530+
"updated_at": ` + referenceTimeStr + `
1531+
},
1532+
"installation": {
1533+
"id": 1,
1534+
"node_id": "nid",
1535+
"app_id": 1,
1536+
"app_slug": "as",
1537+
"target_id": 1,
1538+
"account": {
1539+
"login": "l",
1540+
"id": 1,
1541+
"avatar_url": "a",
1542+
"gravatar_id": "g",
1543+
"name": "n",
1544+
"company": "c",
1545+
"blog": "b",
1546+
"location": "l",
1547+
"email": "e",
1548+
"hireable": true,
1549+
"bio": "b",
1550+
"twitter_username": "t",
1551+
"public_repos": 1,
1552+
"followers": 1,
1553+
"following": 1,
1554+
"created_at": ` + referenceTimeStr + `,
1555+
"suspended_at": ` + referenceTimeStr + `,
1556+
"url": "u"
1557+
},
1558+
"access_tokens_url": "atu",
1559+
"repositories_url": "ru",
1560+
"html_url": "hu",
1561+
"target_type": "tt",
1562+
"single_file_name": "sfn",
1563+
"repository_selection": "rs",
1564+
"events": [
1565+
"e"
1566+
],
1567+
"single_file_paths": [
1568+
"s"
1569+
],
1570+
"permissions": {
1571+
"actions": "a",
1572+
"administration": "ad",
1573+
"checks": "c",
1574+
"contents": "co",
1575+
"content_references": "cr",
1576+
"deployments": "d",
1577+
"environments": "e",
1578+
"issues": "i",
1579+
"metadata": "md",
1580+
"members": "m",
1581+
"organization_administration": "oa",
1582+
"organization_hooks": "oh",
1583+
"organization_plan": "op",
1584+
"organization_pre_receive_hooks": "opr",
1585+
"organization_projects": "op",
1586+
"organization_secrets": "os",
1587+
"organization_self_hosted_runners": "osh",
1588+
"organization_user_blocking": "oub",
1589+
"packages": "pkg",
1590+
"pages": "pg",
1591+
"pull_requests": "pr",
1592+
"repository_hooks": "rh",
1593+
"repository_projects": "rp",
1594+
"repository_pre_receive_hooks": "rprh",
1595+
"secrets": "s",
1596+
"secret_scanning_alerts": "ssa",
1597+
"security_events": "se",
1598+
"single_file": "sf",
1599+
"statuses": "s",
1600+
"team_discussions": "td",
1601+
"vulnerability_alerts": "va",
1602+
"workflows": "w"
1603+
},
1604+
"created_at": ` + referenceTimeStr + `,
1605+
"updated_at": ` + referenceTimeStr + `,
1606+
"has_multiple_single_files": false,
1607+
"suspended_by": {
1608+
"login": "l",
1609+
"id": 1,
1610+
"avatar_url": "a",
1611+
"gravatar_id": "g",
1612+
"name": "n",
1613+
"company": "c",
1614+
"blog": "b",
1615+
"location": "l",
1616+
"email": "e",
1617+
"hireable": true,
1618+
"bio": "b",
1619+
"twitter_username": "t",
1620+
"public_repos": 1,
1621+
"followers": 1,
1622+
"following": 1,
1623+
"created_at": ` + referenceTimeStr + `,
1624+
"suspended_at": ` + referenceTimeStr + `,
1625+
"url": "u"
1626+
},
1627+
"suspended_at": ` + referenceTimeStr + `
1628+
},
1629+
"organization": {
1630+
"name": "n",
1631+
"company": "c",
1632+
"blog": "b",
1633+
"location": "loc",
1634+
"email": "e",
1635+
"twitter_username": "tu",
1636+
"description": "d",
1637+
"billing_email": "be",
1638+
"is_verified": true,
1639+
"has_organization_projects": true,
1640+
"has_repository_projects": true,
1641+
"default_repository_permission": "drp",
1642+
"members_can_create_repositories": true,
1643+
"members_can_create_public_repositories": false,
1644+
"members_can_create_private_repositories": true,
1645+
"members_can_create_internal_repositories": true,
1646+
"members_allowed_repository_creation_type": "marct",
1647+
"members_can_create_pages": true,
1648+
"members_can_create_public_pages": false,
1649+
"members_can_create_private_pages": true
1650+
},
1651+
"repository": {
1652+
"id": 1,
1653+
"url": "s",
1654+
"name": "n"
1655+
},
1656+
"sender": {
1657+
"login": "l",
1658+
"id": 1,
1659+
"node_id": "n",
1660+
"avatar_url": "a",
1661+
"url": "u",
1662+
"events_url": "e",
1663+
"repos_url": "r"
1664+
},
1665+
"target_type": "running"
1666+
}`
1667+
1668+
testJSONMarshal(t, u, want)
1669+
}
1670+
13351671
func TestEditTitle_Marshal(t *testing.T) {
13361672
testJSONMarshal(t, &EditTitle{}, "{}")
13371673

0 commit comments

Comments
 (0)