Repository: google/go-github
Pull request #1166 (2019-05-07 12:52:19)

add vulnerability-alerts endpoint
Adding vulnerability-alerts endpoint

fixes: https://github.com/google/go-github/issues/1164

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1166?src=pr&el=h1) Report
> Merging [#1166](https://codecov.io/gh/google/go-github/pull/1166?src=pr&el=desc) into [master](https://codecov.io/gh/google/go-github/commit/1fef44b9b427e6c43f92b2f20918e496c275393f?src=pr&el=desc) will **decrease** coverage by `0.03%`.
> The diff coverage is `60%`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/1166/graphs/tree.svg?width=650&token=EgYjGjZlI0&height=150&src=pr)](https://codecov.io/gh/google/go-github/pull/1166?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1166      +/-   ##
==========================================
- Coverage    70.2%   70.17%   -0.04%     
==========================================
  Files          84       84              
  Lines        5830     5850      +20     
==========================================
+ Hits         4093     4105      +12     
- Misses        952      956       +4     
- Partials      785      789       +4
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1166?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/github.go](https://codecov.io/gh/google/go-github/pull/1166/diff?src=pr&el=tree#diff-Z2l0aHViL2dpdGh1Yi5nbw==) | `87.53% <ø> (ø)` | :arrow_up: |
| [github/repos.go](https://codecov.io/gh/google/go-github/pull/1166/diff?src=pr&el=tree#diff-Z2l0aHViL3JlcG9zLmdv) | `66.89% <60%> (-0.34%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1166?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/1166?src=pr&el=footer). Last update [1fef44b...77e2f3c](https://codecov.io/gh/google/go-github/pull/1166?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/github/event_types.go b/github/event_types.go
index 0be42e4c..8ba922a2 100644
--- a/github/event_types.go
+++ b/github/event_types.go
@@ -13,7 +13,7 @@ type RequestedAction struct {
 	Identifier string `json:"identifier"` // The integrator reference of the action requested by the user.
 }
 
-// CheckRunEvent is triggered when a check run is "created", "updated", or "re-requested".
+// CheckRunEvent is triggered when a check run is "created", "updated", or "rerequested".
 // The Webhook event name is "check_run".
 //
 // GitHub API docs: https://developer.github.com/v3/activity/events/types/#checkrunevent
@@ -32,13 +32,13 @@ type CheckRunEvent struct {
 	RequestedAction *RequestedAction `json:"requested_action,omitempty"` //
 }
 
-// CheckSuiteEvent is triggered when a check suite is "completed", "requested", or "re-requested".
+// CheckSuiteEvent is triggered when a check suite is "completed", "requested", or "rerequested".
 // The Webhook event name is "check_suite".
 //
 // GitHub API docs: https://developer.github.com/v3/activity/events/types/#checksuiteevent
 type CheckSuiteEvent struct {
 	CheckSuite *CheckSuite `json:"check_suite,omitempty"`
-	// The action performed. Possible values are: "completed", "requested" or "re-requested".
+	// The action performed. Possible values are: "completed", "requested" or "rerequested".
 	Action *string `json:"action,omitempty"`
 
 	// The following fields are only populated by Webhook events.
@@ -585,11 +585,14 @@ type PullRequestEvent struct {
 	// RequestedReviewer is populated in "review_requested", "review_request_removed" event deliveries.
 	// A request affecting multiple reviewers at once is split into multiple
 	// such event deliveries, each with a single, different RequestedReviewer.
-	RequestedReviewer *User         `json:"requested_reviewer,omitempty"`
-	Repo              *Repository   `json:"repository,omitempty"`
-	Sender            *User         `json:"sender,omitempty"`
-	Installation      *Installation `json:"installation,omitempty"`
-	Label             *Label        `json:"label,omitempty"` // Populated in "labeled" event deliveries.
+	RequestedReviewer *User `json:"requested_reviewer,omitempty"`
+	// In the event that a team is requested instead of a user, "requested_team" gets sent in place of
+	// "requested_user" with the same delivery behavior.
+	RequestedTeam *Team         `json:"requested_team,omitempty"`
+	Repo          *Repository   `json:"repository,omitempty"`
+	Sender        *User         `json:"sender,omitempty"`
+	Installation  *Installation `json:"installation,omitempty"`
+	Label         *Label        `json:"label,omitempty"` // Populated in "labeled" event deliveries.
 
 	// The following field is only present when the webhook is triggered on
 	// a repository belonging to an organization.
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 6bc19de8..9129909a 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -7828,6 +7828,14 @@ func (p *PullRequestEvent) GetRequestedReviewer() *User {
 	return p.RequestedReviewer
 }
 
+// GetRequestedTeam returns the RequestedTeam field.
+func (p *PullRequestEvent) GetRequestedTeam() *Team {
+	if p == nil {
+		return nil
+	}
+	return p.RequestedTeam
+}
+
 // GetSender returns the Sender field.
 func (p *PullRequestEvent) GetSender() *User {
 	if p == nil {
diff --git a/github/github.go b/github/github.go
index 44f30944..7c3d8c95 100644
--- a/github/github.go
+++ b/github/github.go
@@ -134,6 +134,9 @@ const (
 
 	// https://developer.github.com/changes/2019-03-14-enabling-disabling-pages/
 	mediaTypeEnablePagesAPIPreview = "application/vnd.github.switcheroo-preview+json"
+
+	// https://developer.github.com/changes/2019-04-24-vulnerability-alerts/
+	mediaTypeRequiredVulnerabilityAlertsPreview = "application/vnd.github.dorian-preview+json"
 )
 
 // A Client manages communication with the GitHub API.
diff --git a/github/repos.go b/github/repos.go
index 0416b0ec..154d28bb 100644
--- a/github/repos.go
+++ b/github/repos.go
@@ -462,6 +462,40 @@ type ListContributorsOptions struct {
 	ListOptions
 }
 
+// EnableVulnerabilityAlerts enables vulnerability alerts and the dependency graph for a repository.
+//
+// GitHub API docs: https://developer.github.com/v3/repos/#enable-vulnerability-alerts
+func (s *RepositoriesService) EnableVulnerabilityAlerts(ctx context.Context, owner, repository string) (*Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/vulnerability-alerts", owner, repository)
+
+	req, err := s.client.NewRequest("PUT", u, nil)
+	if err != nil {
+		return nil, err
+	}
+
+	// TODO: remove custom Accept header when this API fully launches
+	req.Header.Set("Accept", mediaTypeRequiredVulnerabilityAlertsPreview)
+
+	return s.client.Do(ctx, req, nil)
+}
+
+// DisableVulnerabilityAlerts disables vulnerability alerts and the dependency graph for a repository.
+//
+// GitHub API docs: https://developer.github.com/v3/repos/#disable-vulnerability-alerts
+func (s *RepositoriesService) DisableVulnerabilityAlerts(ctx context.Context, owner, repository string) (*Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/vulnerability-alerts", owner, repository)
+
+	req, err := s.client.NewRequest("DELETE", u, nil)
+	if err != nil {
+		return nil, err
+	}
+
+	// TODO: remove custom Accept header when this API fully launches
+	req.Header.Set("Accept", mediaTypeRequiredVulnerabilityAlertsPreview)
+
+	return s.client.Do(ctx, req, nil)
+}
+
 // ListContributors lists contributors for a repository.
 //
 // GitHub API docs: https://developer.github.com/v3/repos/#list-contributors


Test patch:
diff --git a/github/repos_test.go b/github/repos_test.go
index 6f4a8a3f..cb91a386 100644
--- a/github/repos_test.go
+++ b/github/repos_test.go
@@ -367,6 +367,38 @@ func TestRepositoriesService_Edit_invalidOwner(t *testing.T) {
 	testURLParseError(t, err)
 }
 
+func TestRepositoriesService_EnableVulnerabilityAlerts(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/vulnerability-alerts", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "PUT")
+		testHeader(t, r, "Accept", mediaTypeRequiredVulnerabilityAlertsPreview)
+
+		w.WriteHeader(http.StatusNoContent)
+	})
+
+	if _, err := client.Repositories.EnableVulnerabilityAlerts(context.Background(), "o", "r"); err != nil {
+		t.Errorf("Repositories.EnableVulnerabilityAlerts returned error: %v", err)
+	}
+}
+
+func TestRepositoriesService_DisableVulnerabilityAlerts(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/vulnerability-alerts", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "DELETE")
+		testHeader(t, r, "Accept", mediaTypeRequiredVulnerabilityAlertsPreview)
+
+		w.WriteHeader(http.StatusNoContent)
+	})
+
+	if _, err := client.Repositories.DisableVulnerabilityAlerts(context.Background(), "o", "r"); err != nil {
+		t.Errorf("Repositories.DisableVulnerabilityAlerts returned error: %v", err)
+	}
+}
+
 func TestRepositoriesService_ListContributors(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()