Skip to content

Commit b9774ad

Browse files
authored
Add missing fields to SecurityAdvisoryEvent and rename others (#2889)
1 parent 8596515 commit b9774ad

File tree

5 files changed

+421
-16
lines changed

5 files changed

+421
-16
lines changed

github/dependabot_alerts.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type Dependency struct {
1717
Scope *string `json:"scope,omitempty"`
1818
}
1919

20-
// AdvisoryCVSs represents the advisory pertaining to the Common Vulnerability Scoring System.
21-
type AdvisoryCVSs struct {
20+
// AdvisoryCVSS represents the advisory pertaining to the Common Vulnerability Scoring System.
21+
type AdvisoryCVSS struct {
2222
Score *float64 `json:"score,omitempty"`
2323
VectorString *string `json:"vector_string,omitempty"`
2424
}
@@ -37,7 +37,7 @@ type DependabotSecurityAdvisory struct {
3737
Description *string `json:"description,omitempty"`
3838
Vulnerabilities []*AdvisoryVulnerability `json:"vulnerabilities,omitempty"`
3939
Severity *string `json:"severity,omitempty"`
40-
CVSs *AdvisoryCVSs `json:"cvss,omitempty"`
40+
CVSS *AdvisoryCVSS `json:"cvss,omitempty"`
4141
CWEs []*AdvisoryCWEs `json:"cwes,omitempty"`
4242
Identifiers []*AdvisoryIdentifier `json:"identifiers,omitempty"`
4343
References []*AdvisoryReference `json:"references,omitempty"`

github/event_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,8 @@ type WorkflowRunEvent struct {
16101610
//
16111611
// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#security_advisory
16121612
type SecurityAdvisory struct {
1613+
CVSS *AdvisoryCVSS `json:"cvss,omitempty"`
1614+
CWEs []*AdvisoryCWEs `json:"cwes,omitempty"`
16131615
GHSAID *string `json:"ghsa_id,omitempty"`
16141616
Summary *string `json:"summary,omitempty"`
16151617
Description *string `json:"description,omitempty"`
@@ -1658,6 +1660,13 @@ type FirstPatchedVersion struct {
16581660
type SecurityAdvisoryEvent struct {
16591661
Action *string `json:"action,omitempty"`
16601662
SecurityAdvisory *SecurityAdvisory `json:"security_advisory,omitempty"`
1663+
1664+
// The following fields are only populated by Webhook events.
1665+
Enterprise *Enterprise `json:"enterprise,omitempty"`
1666+
Installation *Installation `json:"installation,omitempty"`
1667+
Organization *Organization `json:"organization,omitempty"`
1668+
Repository *Repository `json:"repository,omitempty"`
1669+
Sender *User `json:"sender,omitempty"`
16611670
}
16621671

16631672
// 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
@@ -16769,6 +16769,16 @@ func TestSecurityAdvisoryEvent_Marshal(t *testing.T) {
1676916769
u := &SecurityAdvisoryEvent{
1677016770
Action: String("published"),
1677116771
SecurityAdvisory: &SecurityAdvisory{
16772+
CVSS: &AdvisoryCVSS{
16773+
Score: Float64(1.0),
16774+
VectorString: String("vs"),
16775+
},
16776+
CWEs: []*AdvisoryCWEs{
16777+
{
16778+
CWEID: String("cweid"),
16779+
Name: String("n"),
16780+
},
16781+
},
1677216782
GHSAID: String("GHSA-rf4j-j272-some"),
1677316783
Summary: String("Siuuuuuuuuu"),
1677416784
Description: String("desc"),
@@ -16801,13 +16811,164 @@ func TestSecurityAdvisoryEvent_Marshal(t *testing.T) {
1680116811
},
1680216812
},
1680316813
},
16814+
Enterprise: &Enterprise{
16815+
ID: Int(1),
16816+
Slug: String("s"),
16817+
Name: String("n"),
16818+
NodeID: String("nid"),
16819+
AvatarURL: String("au"),
16820+
Description: String("d"),
16821+
WebsiteURL: String("wu"),
16822+
HTMLURL: String("hu"),
16823+
CreatedAt: &Timestamp{referenceTime},
16824+
UpdatedAt: &Timestamp{referenceTime},
16825+
},
16826+
Installation: &Installation{
16827+
ID: Int64(1),
16828+
NodeID: String("nid"),
16829+
AppID: Int64(1),
16830+
AppSlug: String("as"),
16831+
TargetID: Int64(1),
16832+
Account: &User{
16833+
Login: String("l"),
16834+
ID: Int64(1),
16835+
URL: String("u"),
16836+
AvatarURL: String("a"),
16837+
GravatarID: String("g"),
16838+
Name: String("n"),
16839+
Company: String("c"),
16840+
Blog: String("b"),
16841+
Location: String("l"),
16842+
Email: String("e"),
16843+
Hireable: Bool(true),
16844+
Bio: String("b"),
16845+
TwitterUsername: String("t"),
16846+
PublicRepos: Int(1),
16847+
Followers: Int(1),
16848+
Following: Int(1),
16849+
CreatedAt: &Timestamp{referenceTime},
16850+
SuspendedAt: &Timestamp{referenceTime},
16851+
},
16852+
AccessTokensURL: String("atu"),
16853+
RepositoriesURL: String("ru"),
16854+
HTMLURL: String("hu"),
16855+
TargetType: String("tt"),
16856+
SingleFileName: String("sfn"),
16857+
RepositorySelection: String("rs"),
16858+
Events: []string{"e"},
16859+
SingleFilePaths: []string{"s"},
16860+
Permissions: &InstallationPermissions{
16861+
Actions: String("a"),
16862+
Administration: String("ad"),
16863+
Checks: String("c"),
16864+
Contents: String("co"),
16865+
ContentReferences: String("cr"),
16866+
Deployments: String("d"),
16867+
Environments: String("e"),
16868+
Issues: String("i"),
16869+
Metadata: String("md"),
16870+
Members: String("m"),
16871+
OrganizationAdministration: String("oa"),
16872+
OrganizationHooks: String("oh"),
16873+
OrganizationPlan: String("op"),
16874+
OrganizationPreReceiveHooks: String("opr"),
16875+
OrganizationProjects: String("op"),
16876+
OrganizationSecrets: String("os"),
16877+
OrganizationSelfHostedRunners: String("osh"),
16878+
OrganizationUserBlocking: String("oub"),
16879+
Packages: String("pkg"),
16880+
Pages: String("pg"),
16881+
PullRequests: String("pr"),
16882+
RepositoryHooks: String("rh"),
16883+
RepositoryProjects: String("rp"),
16884+
RepositoryPreReceiveHooks: String("rprh"),
16885+
Secrets: String("s"),
16886+
SecretScanningAlerts: String("ssa"),
16887+
SecurityEvents: String("se"),
16888+
SingleFile: String("sf"),
16889+
Statuses: String("s"),
16890+
TeamDiscussions: String("td"),
16891+
VulnerabilityAlerts: String("va"),
16892+
Workflows: String("w"),
16893+
},
16894+
CreatedAt: &Timestamp{referenceTime},
16895+
UpdatedAt: &Timestamp{referenceTime},
16896+
HasMultipleSingleFiles: Bool(false),
16897+
SuspendedBy: &User{
16898+
Login: String("l"),
16899+
ID: Int64(1),
16900+
URL: String("u"),
16901+
AvatarURL: String("a"),
16902+
GravatarID: String("g"),
16903+
Name: String("n"),
16904+
Company: String("c"),
16905+
Blog: String("b"),
16906+
Location: String("l"),
16907+
Email: String("e"),
16908+
Hireable: Bool(true),
16909+
Bio: String("b"),
16910+
TwitterUsername: String("t"),
16911+
PublicRepos: Int(1),
16912+
Followers: Int(1),
16913+
Following: Int(1),
16914+
CreatedAt: &Timestamp{referenceTime},
16915+
SuspendedAt: &Timestamp{referenceTime},
16916+
},
16917+
SuspendedAt: &Timestamp{referenceTime},
16918+
},
16919+
Organization: &Organization{
16920+
BillingEmail: String("be"),
16921+
Blog: String("b"),
16922+
Company: String("c"),
16923+
Email: String("e"),
16924+
TwitterUsername: String("tu"),
16925+
Location: String("loc"),
16926+
Name: String("n"),
16927+
Description: String("d"),
16928+
IsVerified: Bool(true),
16929+
HasOrganizationProjects: Bool(true),
16930+
HasRepositoryProjects: Bool(true),
16931+
DefaultRepoPermission: String("drp"),
16932+
MembersCanCreateRepos: Bool(true),
16933+
MembersCanCreateInternalRepos: Bool(true),
16934+
MembersCanCreatePrivateRepos: Bool(true),
16935+
MembersCanCreatePublicRepos: Bool(false),
16936+
MembersAllowedRepositoryCreationType: String("marct"),
16937+
MembersCanCreatePages: Bool(true),
16938+
MembersCanCreatePublicPages: Bool(false),
16939+
MembersCanCreatePrivatePages: Bool(true),
16940+
},
16941+
Repository: &Repository{
16942+
ID: Int64(1),
16943+
URL: String("s"),
16944+
Name: String("n"),
16945+
},
16946+
Sender: &User{
16947+
Login: String("l"),
16948+
ID: Int64(1),
16949+
NodeID: String("n"),
16950+
URL: String("u"),
16951+
ReposURL: String("r"),
16952+
EventsURL: String("e"),
16953+
AvatarURL: String("a"),
16954+
},
1680416955
}
1680516956

1680616957
want := `{
1680716958
"action": "published",
1680816959
"security_advisory": {
1680916960
"ghsa_id": "GHSA-rf4j-j272-some",
1681016961
"summary": "Siuuuuuuuuu",
16962+
"cvss": {
16963+
"score": 1.0,
16964+
"vector_string": "vs"
16965+
},
16966+
"cwes": [
16967+
{
16968+
"cwe_id": "cweid",
16969+
"name": "n"
16970+
}
16971+
],
1681116972
"description": "desc",
1681216973
"severity": "moderate",
1681316974
"identifiers": [
@@ -16837,6 +16998,151 @@ func TestSecurityAdvisoryEvent_Marshal(t *testing.T) {
1683716998
}
1683816999
}
1683917000
]
17001+
},
17002+
"enterprise": {
17003+
"id": 1,
17004+
"slug": "s",
17005+
"name": "n",
17006+
"node_id": "nid",
17007+
"avatar_url": "au",
17008+
"description": "d",
17009+
"website_url": "wu",
17010+
"html_url": "hu",
17011+
"created_at": ` + referenceTimeStr + `,
17012+
"updated_at": ` + referenceTimeStr + `
17013+
},
17014+
"installation": {
17015+
"id": 1,
17016+
"node_id": "nid",
17017+
"app_id": 1,
17018+
"app_slug": "as",
17019+
"target_id": 1,
17020+
"account": {
17021+
"login": "l",
17022+
"id": 1,
17023+
"avatar_url": "a",
17024+
"gravatar_id": "g",
17025+
"name": "n",
17026+
"company": "c",
17027+
"blog": "b",
17028+
"location": "l",
17029+
"email": "e",
17030+
"hireable": true,
17031+
"bio": "b",
17032+
"twitter_username": "t",
17033+
"public_repos": 1,
17034+
"followers": 1,
17035+
"following": 1,
17036+
"created_at": ` + referenceTimeStr + `,
17037+
"suspended_at": ` + referenceTimeStr + `,
17038+
"url": "u"
17039+
},
17040+
"access_tokens_url": "atu",
17041+
"repositories_url": "ru",
17042+
"html_url": "hu",
17043+
"target_type": "tt",
17044+
"single_file_name": "sfn",
17045+
"repository_selection": "rs",
17046+
"events": [
17047+
"e"
17048+
],
17049+
"single_file_paths": [
17050+
"s"
17051+
],
17052+
"permissions": {
17053+
"actions": "a",
17054+
"administration": "ad",
17055+
"checks": "c",
17056+
"contents": "co",
17057+
"content_references": "cr",
17058+
"deployments": "d",
17059+
"environments": "e",
17060+
"issues": "i",
17061+
"metadata": "md",
17062+
"members": "m",
17063+
"organization_administration": "oa",
17064+
"organization_hooks": "oh",
17065+
"organization_plan": "op",
17066+
"organization_pre_receive_hooks": "opr",
17067+
"organization_projects": "op",
17068+
"organization_secrets": "os",
17069+
"organization_self_hosted_runners": "osh",
17070+
"organization_user_blocking": "oub",
17071+
"packages": "pkg",
17072+
"pages": "pg",
17073+
"pull_requests": "pr",
17074+
"repository_hooks": "rh",
17075+
"repository_projects": "rp",
17076+
"repository_pre_receive_hooks": "rprh",
17077+
"secrets": "s",
17078+
"secret_scanning_alerts": "ssa",
17079+
"security_events": "se",
17080+
"single_file": "sf",
17081+
"statuses": "s",
17082+
"team_discussions": "td",
17083+
"vulnerability_alerts": "va",
17084+
"workflows": "w"
17085+
},
17086+
"created_at": ` + referenceTimeStr + `,
17087+
"updated_at": ` + referenceTimeStr + `,
17088+
"has_multiple_single_files": false,
17089+
"suspended_by": {
17090+
"login": "l",
17091+
"id": 1,
17092+
"avatar_url": "a",
17093+
"gravatar_id": "g",
17094+
"name": "n",
17095+
"company": "c",
17096+
"blog": "b",
17097+
"location": "l",
17098+
"email": "e",
17099+
"hireable": true,
17100+
"bio": "b",
17101+
"twitter_username": "t",
17102+
"public_repos": 1,
17103+
"followers": 1,
17104+
"following": 1,
17105+
"created_at": ` + referenceTimeStr + `,
17106+
"suspended_at": ` + referenceTimeStr + `,
17107+
"url": "u"
17108+
},
17109+
"suspended_at": ` + referenceTimeStr + `
17110+
},
17111+
"organization": {
17112+
"name": "n",
17113+
"company": "c",
17114+
"blog": "b",
17115+
"location": "loc",
17116+
"email": "e",
17117+
"twitter_username": "tu",
17118+
"description": "d",
17119+
"billing_email": "be",
17120+
"is_verified": true,
17121+
"has_organization_projects": true,
17122+
"has_repository_projects": true,
17123+
"default_repository_permission": "drp",
17124+
"members_can_create_repositories": true,
17125+
"members_can_create_public_repositories": false,
17126+
"members_can_create_private_repositories": true,
17127+
"members_can_create_internal_repositories": true,
17128+
"members_allowed_repository_creation_type": "marct",
17129+
"members_can_create_pages": true,
17130+
"members_can_create_public_pages": false,
17131+
"members_can_create_private_pages": true
17132+
},
17133+
"repository": {
17134+
"id": 1,
17135+
"url": "s",
17136+
"name": "n"
17137+
},
17138+
"sender": {
17139+
"login": "l",
17140+
"id": 1,
17141+
"node_id": "n",
17142+
"avatar_url": "a",
17143+
"url": "u",
17144+
"events_url": "e",
17145+
"repos_url": "r"
1684017146
}
1684117147
}`
1684217148

0 commit comments

Comments
 (0)