Skip to content

Commit 0a9a3aa

Browse files
author
Dean Karn
authored
Merge pull request #76 from v4lproik/add-repository-vulnerability-alert
Add repository vulnerability alert event
2 parents 6edb377 + 43ffb31 commit 0a9a3aa

File tree

4 files changed

+120
-38
lines changed

4 files changed

+120
-38
lines changed

github/github.go

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,44 @@ type Event string
2828

2929
// GitHub hook types
3030
const (
31-
CheckRunEvent Event = "check_run"
32-
CheckSuiteEvent Event = "check_suite"
33-
CommitCommentEvent Event = "commit_comment"
34-
CreateEvent Event = "create"
35-
DeleteEvent Event = "delete"
36-
DeploymentEvent Event = "deployment"
37-
DeploymentStatusEvent Event = "deployment_status"
38-
ForkEvent Event = "fork"
39-
GollumEvent Event = "gollum"
40-
InstallationEvent Event = "installation"
41-
InstallationRepositoriesEvent Event = "installation_repositories"
42-
IntegrationInstallationEvent Event = "integration_installation"
43-
IssueCommentEvent Event = "issue_comment"
44-
IssuesEvent Event = "issues"
45-
LabelEvent Event = "label"
46-
MemberEvent Event = "member"
47-
MembershipEvent Event = "membership"
48-
MilestoneEvent Event = "milestone"
49-
OrganizationEvent Event = "organization"
50-
OrgBlockEvent Event = "org_block"
51-
PageBuildEvent Event = "page_build"
52-
PingEvent Event = "ping"
53-
ProjectCardEvent Event = "project_card"
54-
ProjectColumnEvent Event = "project_column"
55-
ProjectEvent Event = "project"
56-
PublicEvent Event = "public"
57-
PullRequestEvent Event = "pull_request"
58-
PullRequestReviewEvent Event = "pull_request_review"
59-
PullRequestReviewCommentEvent Event = "pull_request_review_comment"
60-
PushEvent Event = "push"
61-
ReleaseEvent Event = "release"
62-
RepositoryEvent Event = "repository"
63-
SecurityAdvisoryEvent Event = "security_advisory"
64-
StatusEvent Event = "status"
65-
TeamEvent Event = "team"
66-
TeamAddEvent Event = "team_add"
67-
WatchEvent Event = "watch"
31+
CheckRunEvent Event = "check_run"
32+
CheckSuiteEvent Event = "check_suite"
33+
CommitCommentEvent Event = "commit_comment"
34+
CreateEvent Event = "create"
35+
DeleteEvent Event = "delete"
36+
DeploymentEvent Event = "deployment"
37+
DeploymentStatusEvent Event = "deployment_status"
38+
ForkEvent Event = "fork"
39+
GollumEvent Event = "gollum"
40+
InstallationEvent Event = "installation"
41+
InstallationRepositoriesEvent Event = "installation_repositories"
42+
IntegrationInstallationEvent Event = "integration_installation"
43+
IssueCommentEvent Event = "issue_comment"
44+
IssuesEvent Event = "issues"
45+
LabelEvent Event = "label"
46+
MemberEvent Event = "member"
47+
MembershipEvent Event = "membership"
48+
MilestoneEvent Event = "milestone"
49+
OrganizationEvent Event = "organization"
50+
OrgBlockEvent Event = "org_block"
51+
PageBuildEvent Event = "page_build"
52+
PingEvent Event = "ping"
53+
ProjectCardEvent Event = "project_card"
54+
ProjectColumnEvent Event = "project_column"
55+
ProjectEvent Event = "project"
56+
PublicEvent Event = "public"
57+
PullRequestEvent Event = "pull_request"
58+
PullRequestReviewEvent Event = "pull_request_review"
59+
PullRequestReviewCommentEvent Event = "pull_request_review_comment"
60+
PushEvent Event = "push"
61+
ReleaseEvent Event = "release"
62+
RepositoryEvent Event = "repository"
63+
RepositoryVulnerabilityAlertEvent Event = "repository_vulnerability_alert"
64+
SecurityAdvisoryEvent Event = "security_advisory"
65+
StatusEvent Event = "status"
66+
TeamEvent Event = "team"
67+
TeamAddEvent Event = "team_add"
68+
WatchEvent Event = "watch"
6869
)
6970

7071
// EventSubtype defines a GitHub Hook Event subtype
@@ -289,6 +290,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
289290
var pl RepositoryPayload
290291
err = json.Unmarshal([]byte(payload), &pl)
291292
return pl, err
293+
case RepositoryVulnerabilityAlertEvent:
294+
var pl RepositoryVulnerabilityAlertPayload
295+
err = json.Unmarshal([]byte(payload), &pl)
296+
return pl, err
292297
case SecurityAdvisoryEvent:
293298
var pl SecurityAdvisoryPayload
294299
err = json.Unmarshal([]byte(payload), &pl)

github/github_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,23 @@ func TestWebhooks(t *testing.T) {
453453
"X-Hub-Signature": []string{"sha1=df442a8af41edd2d42ccdd997938d1d111b0f94e"},
454454
},
455455
},
456+
{
457+
name: "RepositoryVulnerabilityAlertEvent",
458+
event: RepositoryVulnerabilityAlertEvent,
459+
typ: RepositoryVulnerabilityAlertPayload{},
460+
filename: "../testdata/github/repository-vulnerability-alert.json",
461+
headers: http.Header{
462+
"X-Github-Event": []string{"repository_vulnerability_alert"},
463+
"X-Hub-Signature": []string{"sha1=c42c0649e7e06413bcd756763edbab48dff400db"},
464+
},
465+
},
456466
{
457467
name: "SecurityAdvisoryEvent",
458468
event: SecurityAdvisoryEvent,
459469
typ: SecurityAdvisoryPayload{},
460470
filename: "../testdata/github/security-advisory.json",
461471
headers: http.Header{
462-
"X-Github-Event": []string{"security_advisory"},
472+
"X-Github-Event": []string{"security_advisory"},
463473
"X-Hub-Signature": []string{"sha1=6a71f24fa69f55469843a91dc3a5c3e29714a565"},
464474
},
465475
},

github/payload.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5260,6 +5260,40 @@ type RepositoryPayload struct {
52605260
} `json:"sender"`
52615261
}
52625262

5263+
// RepositoryVulnerabilityAlertEvent contains the information for GitHub's repository_vulnerability_alert hook event.
5264+
type RepositoryVulnerabilityAlertPayload struct {
5265+
Action string `json:"action"`
5266+
Alert struct {
5267+
ID int64 `json:"id"`
5268+
Summary string `json:"summary"`
5269+
AffectedRange string `json:"affected_range"`
5270+
AffectedPackageName string `json:"affected_package_name"`
5271+
ExternalReference string `json:"external_reference"`
5272+
ExternalIdentifier string `json:"external_identifier"`
5273+
FixedIn string `json:"fixed_in"`
5274+
Dismisser struct {
5275+
Login string `json:"login"`
5276+
ID int64 `json:"id"`
5277+
NodeID string `json:"node_id"`
5278+
AvatarURL string `json:"avatar_url"`
5279+
GravatarID string `json:"gravatar_id"`
5280+
URL string `json:"url"`
5281+
HTMLURL string `json:"html_url"`
5282+
FollowersURL string `json:"followers_url"`
5283+
FollowingURL string `json:"following_url"`
5284+
GistsURL string `json:"gists_url"`
5285+
StarredURL string `json:"starred_url"`
5286+
SubscriptionsURL string `json:"subscriptions_url"`
5287+
OrganizationsURL string `json:"organizations_url"`
5288+
ReposURL string `json:"repos_url"`
5289+
EventsURL string `json:"events_url"`
5290+
ReceivedEventsURL string `json:"received_events_url"`
5291+
Type string `json:"type"`
5292+
SiteAdmin bool `json:"site_admin"`
5293+
} `json:"dismisser"`
5294+
} `json:"alert"`
5295+
}
5296+
52635297
// SecurityAdvisoryPayload contains the information for GitHub's security_advisory hook event.
52645298
type SecurityAdvisoryPayload struct {
52655299
Action string `json:"action"`
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"action": "dismiss",
3+
"alert": {
4+
"id": 7649605,
5+
"affected_range": "0.2.0",
6+
"affected_package_name": "many_versioned_gem",
7+
"external_reference": "https://nvd.nist.gov/vuln/detail/CVE-2018-3728",
8+
"external_identifier": "CVE-2018-3728",
9+
"fixed_in": "0.2.5",
10+
"dismisser": {
11+
"login":"octocat",
12+
"id":1,
13+
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
14+
"avatar_url":"https://github.com/images/error/octocat_happy.gif",
15+
"gravatar_id":"",
16+
"url":"https://api.github.com/users/octocat",
17+
"html_url":"https://github.com/octocat",
18+
"followers_url":"https://api.github.com/users/octocat/followers",
19+
"following_url":"https://api.github.com/users/octocat/following{/other_user}",
20+
"gists_url":"https://api.github.com/users/octocat/gists{/gist_id}",
21+
"starred_url":"https://api.github.com/users/octocat/starred{/owner}{/repo}",
22+
"subscriptions_url":"https://api.github.com/users/octocat/subscriptions",
23+
"organizations_url":"https://api.github.com/users/octocat/orgs",
24+
"repos_url":"https://api.github.com/users/octocat/repos",
25+
"events_url":"https://api.github.com/users/octocat/events{/privacy}",
26+
"received_events_url":"https://api.github.com/users/octocat/received_events",
27+
"type":"User",
28+
"site_admin":true
29+
},
30+
"dismiss_reason": "No bandwidth to fix this",
31+
"dismissed_at": "2017-10-25T00:00:00+00:00"
32+
}
33+
}

0 commit comments

Comments
 (0)