Skip to content

Commit 2d733ae

Browse files
committed
fix: add missing fields to SecurityAdvisoryEvent
1 parent a0e8f35 commit 2d733ae

File tree

4 files changed

+405
-0
lines changed

4 files changed

+405
-0
lines changed

github/event_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,8 @@ type WorkflowRunEvent struct {
15911591
//
15921592
// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#security_advisory
15931593
type SecurityAdvisory struct {
1594+
CVSs *AdvisoryCVSs `json:"cvss,omitempty"`
1595+
CWEs []*AdvisoryCWEs `json:"cwes,omitempty"`
15941596
GHSAID *string `json:"ghsa_id,omitempty"`
15951597
Summary *string `json:"summary,omitempty"`
15961598
Description *string `json:"description,omitempty"`
@@ -1639,6 +1641,13 @@ type FirstPatchedVersion struct {
16391641
type SecurityAdvisoryEvent struct {
16401642
Action *string `json:"action,omitempty"`
16411643
SecurityAdvisory *SecurityAdvisory `json:"security_advisory,omitempty"`
1644+
1645+
// The following fields are only populated by Webhook events.
1646+
Enterprise *Enterprise `json:"enterprise,omitempty"`
1647+
Installation *Installation `json:"installation,omitempty"`
1648+
Organization *Organization `json:"organization,omitempty"`
1649+
Repository *Repository `json:"repository,omitempty"`
1650+
Sender *User `json:"sender,omitempty"`
16421651
}
16431652

16441653
// CodeScanningAlertEvent is triggered when a code scanning finds a potential vulnerability or error in your code.

github/event_types_test.go

Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16308,6 +16308,16 @@ func TestSecurityAdvisoryEvent_Marshal(t *testing.T) {
1630816308
u := &SecurityAdvisoryEvent{
1630916309
Action: String("published"),
1631016310
SecurityAdvisory: &SecurityAdvisory{
16311+
CVSs: &AdvisoryCVSs{
16312+
Score: Float64(1.0),
16313+
VectorString: String("vs"),
16314+
},
16315+
CWEs: []*AdvisoryCWEs{
16316+
{
16317+
CWEID: String("cweid"),
16318+
Name: String("n"),
16319+
},
16320+
},
1631116321
GHSAID: String("GHSA-rf4j-j272-some"),
1631216322
Summary: String("Siuuuuuuuuu"),
1631316323
Description: String("desc"),
@@ -16340,13 +16350,164 @@ func TestSecurityAdvisoryEvent_Marshal(t *testing.T) {
1634016350
},
1634116351
},
1634216352
},
16353+
Enterprise: &Enterprise{
16354+
ID: Int(1),
16355+
Slug: String("s"),
16356+
Name: String("n"),
16357+
NodeID: String("nid"),
16358+
AvatarURL: String("au"),
16359+
Description: String("d"),
16360+
WebsiteURL: String("wu"),
16361+
HTMLURL: String("hu"),
16362+
CreatedAt: &Timestamp{referenceTime},
16363+
UpdatedAt: &Timestamp{referenceTime},
16364+
},
16365+
Installation: &Installation{
16366+
ID: Int64(1),
16367+
NodeID: String("nid"),
16368+
AppID: Int64(1),
16369+
AppSlug: String("as"),
16370+
TargetID: Int64(1),
16371+
Account: &User{
16372+
Login: String("l"),
16373+
ID: Int64(1),
16374+
URL: String("u"),
16375+
AvatarURL: String("a"),
16376+
GravatarID: String("g"),
16377+
Name: String("n"),
16378+
Company: String("c"),
16379+
Blog: String("b"),
16380+
Location: String("l"),
16381+
Email: String("e"),
16382+
Hireable: Bool(true),
16383+
Bio: String("b"),
16384+
TwitterUsername: String("t"),
16385+
PublicRepos: Int(1),
16386+
Followers: Int(1),
16387+
Following: Int(1),
16388+
CreatedAt: &Timestamp{referenceTime},
16389+
SuspendedAt: &Timestamp{referenceTime},
16390+
},
16391+
AccessTokensURL: String("atu"),
16392+
RepositoriesURL: String("ru"),
16393+
HTMLURL: String("hu"),
16394+
TargetType: String("tt"),
16395+
SingleFileName: String("sfn"),
16396+
RepositorySelection: String("rs"),
16397+
Events: []string{"e"},
16398+
SingleFilePaths: []string{"s"},
16399+
Permissions: &InstallationPermissions{
16400+
Actions: String("a"),
16401+
Administration: String("ad"),
16402+
Checks: String("c"),
16403+
Contents: String("co"),
16404+
ContentReferences: String("cr"),
16405+
Deployments: String("d"),
16406+
Environments: String("e"),
16407+
Issues: String("i"),
16408+
Metadata: String("md"),
16409+
Members: String("m"),
16410+
OrganizationAdministration: String("oa"),
16411+
OrganizationHooks: String("oh"),
16412+
OrganizationPlan: String("op"),
16413+
OrganizationPreReceiveHooks: String("opr"),
16414+
OrganizationProjects: String("op"),
16415+
OrganizationSecrets: String("os"),
16416+
OrganizationSelfHostedRunners: String("osh"),
16417+
OrganizationUserBlocking: String("oub"),
16418+
Packages: String("pkg"),
16419+
Pages: String("pg"),
16420+
PullRequests: String("pr"),
16421+
RepositoryHooks: String("rh"),
16422+
RepositoryProjects: String("rp"),
16423+
RepositoryPreReceiveHooks: String("rprh"),
16424+
Secrets: String("s"),
16425+
SecretScanningAlerts: String("ssa"),
16426+
SecurityEvents: String("se"),
16427+
SingleFile: String("sf"),
16428+
Statuses: String("s"),
16429+
TeamDiscussions: String("td"),
16430+
VulnerabilityAlerts: String("va"),
16431+
Workflows: String("w"),
16432+
},
16433+
CreatedAt: &Timestamp{referenceTime},
16434+
UpdatedAt: &Timestamp{referenceTime},
16435+
HasMultipleSingleFiles: Bool(false),
16436+
SuspendedBy: &User{
16437+
Login: String("l"),
16438+
ID: Int64(1),
16439+
URL: String("u"),
16440+
AvatarURL: String("a"),
16441+
GravatarID: String("g"),
16442+
Name: String("n"),
16443+
Company: String("c"),
16444+
Blog: String("b"),
16445+
Location: String("l"),
16446+
Email: String("e"),
16447+
Hireable: Bool(true),
16448+
Bio: String("b"),
16449+
TwitterUsername: String("t"),
16450+
PublicRepos: Int(1),
16451+
Followers: Int(1),
16452+
Following: Int(1),
16453+
CreatedAt: &Timestamp{referenceTime},
16454+
SuspendedAt: &Timestamp{referenceTime},
16455+
},
16456+
SuspendedAt: &Timestamp{referenceTime},
16457+
},
16458+
Organization: &Organization{
16459+
BillingEmail: String("be"),
16460+
Blog: String("b"),
16461+
Company: String("c"),
16462+
Email: String("e"),
16463+
TwitterUsername: String("tu"),
16464+
Location: String("loc"),
16465+
Name: String("n"),
16466+
Description: String("d"),
16467+
IsVerified: Bool(true),
16468+
HasOrganizationProjects: Bool(true),
16469+
HasRepositoryProjects: Bool(true),
16470+
DefaultRepoPermission: String("drp"),
16471+
MembersCanCreateRepos: Bool(true),
16472+
MembersCanCreateInternalRepos: Bool(true),
16473+
MembersCanCreatePrivateRepos: Bool(true),
16474+
MembersCanCreatePublicRepos: Bool(false),
16475+
MembersAllowedRepositoryCreationType: String("marct"),
16476+
MembersCanCreatePages: Bool(true),
16477+
MembersCanCreatePublicPages: Bool(false),
16478+
MembersCanCreatePrivatePages: Bool(true),
16479+
},
16480+
Repository: &Repository{
16481+
ID: Int64(1),
16482+
URL: String("s"),
16483+
Name: String("n"),
16484+
},
16485+
Sender: &User{
16486+
Login: String("l"),
16487+
ID: Int64(1),
16488+
NodeID: String("n"),
16489+
URL: String("u"),
16490+
ReposURL: String("r"),
16491+
EventsURL: String("e"),
16492+
AvatarURL: String("a"),
16493+
},
1634316494
}
1634416495

1634516496
want := `{
1634616497
"action": "published",
1634716498
"security_advisory": {
1634816499
"ghsa_id": "GHSA-rf4j-j272-some",
1634916500
"summary": "Siuuuuuuuuu",
16501+
"cvss": {
16502+
"score": 1.0,
16503+
"vector_string": "vs"
16504+
},
16505+
"cwes": [
16506+
{
16507+
"cwe_id": "cweid",
16508+
"name": "n"
16509+
}
16510+
],
1635016511
"description": "desc",
1635116512
"severity": "moderate",
1635216513
"identifiers": [
@@ -16376,6 +16537,151 @@ func TestSecurityAdvisoryEvent_Marshal(t *testing.T) {
1637616537
}
1637716538
}
1637816539
]
16540+
},
16541+
"enterprise": {
16542+
"id": 1,
16543+
"slug": "s",
16544+
"name": "n",
16545+
"node_id": "nid",
16546+
"avatar_url": "au",
16547+
"description": "d",
16548+
"website_url": "wu",
16549+
"html_url": "hu",
16550+
"created_at": ` + referenceTimeStr + `,
16551+
"updated_at": ` + referenceTimeStr + `
16552+
},
16553+
"installation": {
16554+
"id": 1,
16555+
"node_id": "nid",
16556+
"app_id": 1,
16557+
"app_slug": "as",
16558+
"target_id": 1,
16559+
"account": {
16560+
"login": "l",
16561+
"id": 1,
16562+
"avatar_url": "a",
16563+
"gravatar_id": "g",
16564+
"name": "n",
16565+
"company": "c",
16566+
"blog": "b",
16567+
"location": "l",
16568+
"email": "e",
16569+
"hireable": true,
16570+
"bio": "b",
16571+
"twitter_username": "t",
16572+
"public_repos": 1,
16573+
"followers": 1,
16574+
"following": 1,
16575+
"created_at": ` + referenceTimeStr + `,
16576+
"suspended_at": ` + referenceTimeStr + `,
16577+
"url": "u"
16578+
},
16579+
"access_tokens_url": "atu",
16580+
"repositories_url": "ru",
16581+
"html_url": "hu",
16582+
"target_type": "tt",
16583+
"single_file_name": "sfn",
16584+
"repository_selection": "rs",
16585+
"events": [
16586+
"e"
16587+
],
16588+
"single_file_paths": [
16589+
"s"
16590+
],
16591+
"permissions": {
16592+
"actions": "a",
16593+
"administration": "ad",
16594+
"checks": "c",
16595+
"contents": "co",
16596+
"content_references": "cr",
16597+
"deployments": "d",
16598+
"environments": "e",
16599+
"issues": "i",
16600+
"metadata": "md",
16601+
"members": "m",
16602+
"organization_administration": "oa",
16603+
"organization_hooks": "oh",
16604+
"organization_plan": "op",
16605+
"organization_pre_receive_hooks": "opr",
16606+
"organization_projects": "op",
16607+
"organization_secrets": "os",
16608+
"organization_self_hosted_runners": "osh",
16609+
"organization_user_blocking": "oub",
16610+
"packages": "pkg",
16611+
"pages": "pg",
16612+
"pull_requests": "pr",
16613+
"repository_hooks": "rh",
16614+
"repository_projects": "rp",
16615+
"repository_pre_receive_hooks": "rprh",
16616+
"secrets": "s",
16617+
"secret_scanning_alerts": "ssa",
16618+
"security_events": "se",
16619+
"single_file": "sf",
16620+
"statuses": "s",
16621+
"team_discussions": "td",
16622+
"vulnerability_alerts": "va",
16623+
"workflows": "w"
16624+
},
16625+
"created_at": ` + referenceTimeStr + `,
16626+
"updated_at": ` + referenceTimeStr + `,
16627+
"has_multiple_single_files": false,
16628+
"suspended_by": {
16629+
"login": "l",
16630+
"id": 1,
16631+
"avatar_url": "a",
16632+
"gravatar_id": "g",
16633+
"name": "n",
16634+
"company": "c",
16635+
"blog": "b",
16636+
"location": "l",
16637+
"email": "e",
16638+
"hireable": true,
16639+
"bio": "b",
16640+
"twitter_username": "t",
16641+
"public_repos": 1,
16642+
"followers": 1,
16643+
"following": 1,
16644+
"created_at": ` + referenceTimeStr + `,
16645+
"suspended_at": ` + referenceTimeStr + `,
16646+
"url": "u"
16647+
},
16648+
"suspended_at": ` + referenceTimeStr + `
16649+
},
16650+
"organization": {
16651+
"name": "n",
16652+
"company": "c",
16653+
"blog": "b",
16654+
"location": "loc",
16655+
"email": "e",
16656+
"twitter_username": "tu",
16657+
"description": "d",
16658+
"billing_email": "be",
16659+
"is_verified": true,
16660+
"has_organization_projects": true,
16661+
"has_repository_projects": true,
16662+
"default_repository_permission": "drp",
16663+
"members_can_create_repositories": true,
16664+
"members_can_create_public_repositories": false,
16665+
"members_can_create_private_repositories": true,
16666+
"members_can_create_internal_repositories": true,
16667+
"members_allowed_repository_creation_type": "marct",
16668+
"members_can_create_pages": true,
16669+
"members_can_create_public_pages": false,
16670+
"members_can_create_private_pages": true
16671+
},
16672+
"repository": {
16673+
"id": 1,
16674+
"url": "s",
16675+
"name": "n"
16676+
},
16677+
"sender": {
16678+
"login": "l",
16679+
"id": 1,
16680+
"node_id": "n",
16681+
"avatar_url": "a",
16682+
"url": "u",
16683+
"events_url": "e",
16684+
"repos_url": "r"
1637916685
}
1638016686
}`
1638116687

0 commit comments

Comments
 (0)