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
16 changes: 16 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ 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
31 changes: 25 additions & 6 deletions github/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,25 @@ func (s *RepositoriesService) DisableVulnerabilityAlerts(ctx context.Context, ow
return s.client.Do(ctx, req, nil)
}

// GetAutomatedSecurityFixes checks if the automated security fixes for a repository are enabled.
//
// GitHub API docs: https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#check-if-automated-security-fixes-are-enabled-for-a-repository
func (s *RepositoriesService) GetAutomatedSecurityFixes(ctx context.Context, owner, repository string) (*AutomatedSecurityFixes, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/automated-security-fixes", owner, repository)

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

p := new(AutomatedSecurityFixes)
resp, err := s.client.Do(ctx, req, p)
if err != nil {
return nil, resp, err
}
return p, resp, nil
}

// EnableAutomatedSecurityFixes enables the automated security fixes for a repository.
//
// GitHub API docs: https://docs.github.com/en/rest/repos/repos#enable-automated-security-fixes
Expand All @@ -698,9 +717,6 @@ func (s *RepositoriesService) EnableAutomatedSecurityFixes(ctx context.Context,
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)
}

Expand All @@ -715,9 +731,6 @@ func (s *RepositoriesService) DisableAutomatedSecurityFixes(ctx context.Context,
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)
}

Expand Down Expand Up @@ -1212,6 +1225,12 @@ type SignaturesProtectedBranch struct {
Enabled *bool `json:"enabled,omitempty"`
}

// AutomatedSecurityFixes represents their status.
type AutomatedSecurityFixes struct {
Enabled *bool `json:"enabled"`
Paused *bool `json:"paused"`
Comment thread
gmlewis marked this conversation as resolved.
}

// ListBranches lists branches for the specified repository.
//
// GitHub API docs: https://docs.github.com/en/rest/branches/branches#list-branches
Expand Down
39 changes: 37 additions & 2 deletions github/repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@ func TestRepositoriesService_EnableAutomatedSecurityFixes(t *testing.T) {

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)
})
Expand All @@ -664,13 +663,49 @@ func TestRepositoriesService_EnableAutomatedSecurityFixes(t *testing.T) {
}
}

func TestRepositoriesService_GetAutomatedSecurityFixes(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, "GET")
fmt.Fprint(w, `{"enabled": true, "paused": false}`)
})

ctx := context.Background()
fixes, _, err := client.Repositories.GetAutomatedSecurityFixes(ctx, "o", "r")
if err != nil {
t.Errorf("Repositories.GetAutomatedSecurityFixes returned errpr: #{err}")
}

want := &AutomatedSecurityFixes{
Enabled: Bool(true),
Paused: Bool(false),
}
if !cmp.Equal(fixes, want) {
t.Errorf("Repositories.GetAutomatedSecurityFixes returned #{fixes}, want #{want}")
}

const methodName = "GetAutomatedSecurityFixes"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Repositories.GetAutomatedSecurityFixes(ctx, "\n", "\n")
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Repositories.GetAutomatedSecurityFixes(ctx, "o", "r")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
Comment thread
grahamhar marked this conversation as resolved.

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)
})
Expand Down