Repository: google/go-github
Pull request #1025 (2018-10-03 16:16:45)

Repository Vulnerability alert patch
Added struct for `repository_vulnerability_alert` webhook event, as mentioned in [docs](https://developer.github.com/v3/activity/events/types/#repositoryvulnerabilityalertevent). 

Made changes where the payload is assigned and mapping done from webhook event to new struct.


Patch:
diff --git a/github/activity_events.go b/github/activity_events.go
index a919b11c..47f0c735 100644
--- a/github/activity_events.go
+++ b/github/activity_events.go
@@ -96,6 +96,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
 		payload = &ReleaseEvent{}
 	case "RepositoryEvent":
 		payload = &RepositoryEvent{}
+	case "RepositoryVulnerabilityAlertEvent":
+		payload = &RepositoryVulnerabilityAlertEvent{}
 	case "StatusEvent":
 		payload = &StatusEvent{}
 	case "TeamEvent":
diff --git a/github/event_types.go b/github/event_types.go
index 9f49b34f..1792f43c 100644
--- a/github/event_types.go
+++ b/github/event_types.go
@@ -710,6 +710,27 @@ type RepositoryEvent struct {
 	Installation *Installation `json:"installation,omitempty"`
 }
 
+// RepositoryVulnerabilityAlertEvent is triggered when a security alert is created, dismissed, or resolved.
+//
+// GitHub API docs: https://developer.github.com/v3/activity/events/types/#repositoryvulnerabilityalertevent
+type RepositoryVulnerabilityAlertEvent struct {
+	// Action is the action that was performed. This can be: "create", "dismiss", "resolve".
+	Action *string `json:"action,omitempty"`
+
+	//The security alert of the vulnerable dependency.
+	Alert *struct {
+		ID                  *int64     `json:"id,omitempty"`
+		AffectedRange       *string    `json:"affected_range,omitempty"`
+		AffectedPackageName *string    `json:"affected_package_name,omitempty"`
+		ExternalReference   *string    `json:"external_reference,omitempty"`
+		ExternalIdentifier  *string    `json:"external_identifier,omitempty"`
+		FixedIn             *string    `json:"fixed_in,omitempty"`
+		Dismisser           *User      `json:"dismisser,omitempty"`
+		DismissReason       *string    `json:"dismiss_reason,omitempty"`
+		DismissedAt         *Timestamp `json:"dismissed_at,omitempty"`
+	} `json:"alert,omitempty"`
+}
+
 // StatusEvent is triggered when the status of a Git commit changes.
 // The Webhook event name is "status".
 //
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 22b5c095..f66d3b09 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -9964,6 +9964,14 @@ func (r *RepositoryTag) GetZipballURL() string {
 	return *r.ZipballURL
 }
 
+// GetAction returns the Action field if it's non-nil, zero value otherwise.
+func (r *RepositoryVulnerabilityAlertEvent) GetAction() string {
+	if r == nil || r.Action == nil {
+		return ""
+	}
+	return *r.Action
+}
+
 // GetForkRepos returns the ForkRepos field if it's non-nil, zero value otherwise.
 func (r *RepoStats) GetForkRepos() int {
 	if r == nil || r.ForkRepos == nil {
diff --git a/github/messages.go b/github/messages.go
index 519c1c03..75bc7705 100644
--- a/github/messages.go
+++ b/github/messages.go
@@ -41,42 +41,43 @@ const (
 var (
 	// eventTypeMapping maps webhooks types to their corresponding go-github struct types.
 	eventTypeMapping = map[string]string{
-		"check_run":                   "CheckRunEvent",
-		"check_suite":                 "CheckSuiteEvent",
-		"commit_comment":              "CommitCommentEvent",
-		"create":                      "CreateEvent",
-		"delete":                      "DeleteEvent",
-		"deployment":                  "DeploymentEvent",
-		"deployment_status":           "DeploymentStatusEvent",
-		"fork":                        "ForkEvent",
-		"gollum":                      "GollumEvent",
-		"installation":                "InstallationEvent",
-		"installation_repositories":   "InstallationRepositoriesEvent",
-		"issue_comment":               "IssueCommentEvent",
-		"issues":                      "IssuesEvent",
-		"label":                       "LabelEvent",
-		"marketplace_purchase":        "MarketplacePurchaseEvent",
-		"member":                      "MemberEvent",
-		"membership":                  "MembershipEvent",
-		"milestone":                   "MilestoneEvent",
-		"organization":                "OrganizationEvent",
-		"org_block":                   "OrgBlockEvent",
-		"page_build":                  "PageBuildEvent",
-		"ping":                        "PingEvent",
-		"project":                     "ProjectEvent",
-		"project_card":                "ProjectCardEvent",
-		"project_column":              "ProjectColumnEvent",
-		"public":                      "PublicEvent",
-		"pull_request_review":         "PullRequestReviewEvent",
-		"pull_request_review_comment": "PullRequestReviewCommentEvent",
-		"pull_request":                "PullRequestEvent",
-		"push":                        "PushEvent",
-		"repository":                  "RepositoryEvent",
-		"release":                     "ReleaseEvent",
-		"status":                      "StatusEvent",
-		"team":                        "TeamEvent",
-		"team_add":                    "TeamAddEvent",
-		"watch":                       "WatchEvent",
+		"check_run":                      "CheckRunEvent",
+		"check_suite":                    "CheckSuiteEvent",
+		"commit_comment":                 "CommitCommentEvent",
+		"create":                         "CreateEvent",
+		"delete":                         "DeleteEvent",
+		"deployment":                     "DeploymentEvent",
+		"deployment_status":              "DeploymentStatusEvent",
+		"fork":                           "ForkEvent",
+		"gollum":                         "GollumEvent",
+		"installation":                   "InstallationEvent",
+		"installation_repositories":      "InstallationRepositoriesEvent",
+		"issue_comment":                  "IssueCommentEvent",
+		"issues":                         "IssuesEvent",
+		"label":                          "LabelEvent",
+		"marketplace_purchase":           "MarketplacePurchaseEvent",
+		"member":                         "MemberEvent",
+		"membership":                     "MembershipEvent",
+		"milestone":                      "MilestoneEvent",
+		"organization":                   "OrganizationEvent",
+		"org_block":                      "OrgBlockEvent",
+		"page_build":                     "PageBuildEvent",
+		"ping":                           "PingEvent",
+		"project":                        "ProjectEvent",
+		"project_card":                   "ProjectCardEvent",
+		"project_column":                 "ProjectColumnEvent",
+		"public":                         "PublicEvent",
+		"pull_request_review":            "PullRequestReviewEvent",
+		"pull_request_review_comment":    "PullRequestReviewCommentEvent",
+		"pull_request":                   "PullRequestEvent",
+		"push":                           "PushEvent",
+		"repository":                     "RepositoryEvent",
+		"repository_vulnerability_alert": "RepositoryVulnerabilityAlertEvent",
+		"release":                        "ReleaseEvent",
+		"status":                         "StatusEvent",
+		"team":                           "TeamEvent",
+		"team_add":                       "TeamAddEvent",
+		"watch":                          "WatchEvent",
 	}
 )
 
diff --git a/github/pulls.go b/github/pulls.go
index 32655651..a0c3c041 100644
--- a/github/pulls.go
+++ b/github/pulls.go
@@ -60,6 +60,10 @@ type PullRequest struct {
 	NodeID              *string    `json:"node_id,omitempty"`
 	RequestedReviewers  []*User    `json:"requested_reviewers,omitempty"`
 
+	// RequestedTeams is populated as part of the PullRequestEvent.
+	// See, https://developer.github.com/v3/activity/events/types/#pullrequestevent for an example.
+	RequestedTeams []*Team `json:"requested_teams,omitempty"`
+
 	Links *PRLinks           `json:"_links,omitempty"`
 	Head  *PullRequestBranch `json:"head,omitempty"`
 	Base  *PullRequestBranch `json:"base,omitempty"`


Test patch:
diff --git a/github/messages_test.go b/github/messages_test.go
index 0b677cac..b63f1946 100644
--- a/github/messages_test.go
+++ b/github/messages_test.go
@@ -290,6 +290,10 @@ func TestParseWebHook(t *testing.T) {
 			payload:     &RepositoryEvent{},
 			messageType: "repository",
 		},
+		{
+			payload:     &RepositoryVulnerabilityAlertEvent{},
+			messageType: "repository_vulnerability_alert",
+		},
 		{
 			payload:     &StatusEvent{},
 			messageType: "status",