Skip to content

Commit

Permalink
Add support for check private vulnerability reporting endpoint (#3157)
Browse files Browse the repository at this point in the history
Fixes: #3152.
  • Loading branch information
Sairaviteja27 committed May 5, 2024
1 parent faa0e7c commit 5868a66
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
24 changes: 24 additions & 0 deletions github/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -2402,3 +2402,27 @@ func (s *RepositoriesService) DisablePrivateReporting(ctx context.Context, owner

return resp, nil
}

// checkPrivateReporting represents whether private vulnerability reporting is enabled.
type checkPrivateReporting struct {
Enabled bool `json:"enabled,omitempty"`
}

// IsPrivateReportingEnabled checks if private vulnerability reporting is enabled
// for the repository and returns a boolean indicating the status.
//
// GitHub API docs: https://docs.github.com/rest/repos/repos#check-if-private-vulnerability-reporting-is-enabled-for-a-repository
//
//meta:operation GET /repos/{owner}/{repo}/private-vulnerability-reporting
func (s *RepositoriesService) IsPrivateReportingEnabled(ctx context.Context, owner, repo string) (bool, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/private-vulnerability-reporting", owner, repo)

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

privateReporting := new(checkPrivateReporting)
resp, err := s.client.Do(ctx, req, privateReporting)
return privateReporting.Enabled, resp, err
}
33 changes: 33 additions & 0 deletions github/repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4430,3 +4430,36 @@ func TestRepositoriesService_DisablePrivateReporting(t *testing.T) {
return client.Repositories.DisablePrivateReporting(ctx, "owner", "repo")
})
}

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

mux.HandleFunc("/repos/owner/repo/private-vulnerability-reporting", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"enabled": true}`)
})

ctx := context.Background()
enabled, _, err := client.Repositories.IsPrivateReportingEnabled(ctx, "owner", "repo")
if err != nil {
t.Errorf("Repositories.IsPrivateReportingEnabled returned error: %v", err)
}
if want := true; enabled != want {
t.Errorf("Repositories.IsPrivateReportingEnabled returned %+v, want %+v", enabled, want)
}

const methodName = "IsPrivateReportingEnabled"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Repositories.IsPrivateReportingEnabled(ctx, "\n", "\n")
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Repositories.IsPrivateReportingEnabled(ctx, "owner", "repo")
if got {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want false", methodName, got)
}
return resp, err
})
}

0 comments on commit 5868a66

Please sign in to comment.