Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ const (
// https://developer.github.com/changes/2019-04-24-vulnerability-alerts/
mediaTypeRequiredVulnerabilityAlertsPreview = "application/vnd.github.dorian-preview+json"

// https://developer.github.com/changes/2019-06-04-automated-security-fixes/
mediaTypeRequiredAutomatedSecurityFixesPreview = "application/vnd.github.london-preview+json"

// https://developer.github.com/changes/2019-05-29-update-branch-api/
mediaTypeUpdatePullRequestBranchPreview = "application/vnd.github.lydian-preview+json"
)
Expand Down
34 changes: 34 additions & 0 deletions github/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,40 @@ func (s *RepositoriesService) DisableVulnerabilityAlerts(ctx context.Context, ow
return s.client.Do(ctx, req, nil)
}

// EnableAutomatedSecurityFixes enables the automated security fixes for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#enable-automated-security-fixes
func (s *RepositoriesService) EnableAutomatedSecurityFixes(ctx context.Context, owner, repository string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/automated-security-fixes", 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", mediaTypeRequiredAutomatedSecurityFixesPreview)

return s.client.Do(ctx, req, nil)
}

// DisableAutomatedSecurityFixes disables vulnerability alerts and the dependency graph for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#disable-automated-security-fixes
func (s *RepositoriesService) DisableAutomatedSecurityFixes(ctx context.Context, owner, repository string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/automated-security-fixes", 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", mediaTypeRequiredAutomatedSecurityFixesPreview)

return s.client.Do(ctx, req, nil)
}

// ListContributors lists contributors for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#list-contributors
Expand Down
32 changes: 32 additions & 0 deletions github/repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,38 @@ func TestRepositoriesService_DisableVulnerabilityAlerts(t *testing.T) {
}
}

func TestRepositoriesService_EnableAutomatedSecurityFixes(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/automated-security-fixes", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Accept", mediaTypeRequiredAutomatedSecurityFixesPreview)

w.WriteHeader(http.StatusNoContent)
})

if _, err := client.Repositories.EnableAutomatedSecurityFixes(context.Background(), "o", "r"); err != nil {
t.Errorf("Repositories.EnableAutomatedSecurityFixes returned error: %v", err)
}
}

func TestRepositoriesService_DisableAutomatedSecurityFixes(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/automated-security-fixes", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testHeader(t, r, "Accept", mediaTypeRequiredAutomatedSecurityFixesPreview)

w.WriteHeader(http.StatusNoContent)
})

if _, err := client.Repositories.DisableAutomatedSecurityFixes(context.Background(), "o", "r"); err != nil {
t.Errorf("Repositories.DisableAutomatedSecurityFixes returned error: %v", err)
}
}

func TestRepositoriesService_ListContributors(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down