Skip to content

Commit 5868a66

Browse files
Add support for check private vulnerability reporting endpoint (#3157)
Fixes: #3152.
1 parent faa0e7c commit 5868a66

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

github/repos.go

+24
Original file line numberDiff line numberDiff line change
@@ -2402,3 +2402,27 @@ func (s *RepositoriesService) DisablePrivateReporting(ctx context.Context, owner
24022402

24032403
return resp, nil
24042404
}
2405+
2406+
// checkPrivateReporting represents whether private vulnerability reporting is enabled.
2407+
type checkPrivateReporting struct {
2408+
Enabled bool `json:"enabled,omitempty"`
2409+
}
2410+
2411+
// IsPrivateReportingEnabled checks if private vulnerability reporting is enabled
2412+
// for the repository and returns a boolean indicating the status.
2413+
//
2414+
// GitHub API docs: https://docs.github.com/rest/repos/repos#check-if-private-vulnerability-reporting-is-enabled-for-a-repository
2415+
//
2416+
//meta:operation GET /repos/{owner}/{repo}/private-vulnerability-reporting
2417+
func (s *RepositoriesService) IsPrivateReportingEnabled(ctx context.Context, owner, repo string) (bool, *Response, error) {
2418+
u := fmt.Sprintf("repos/%v/%v/private-vulnerability-reporting", owner, repo)
2419+
2420+
req, err := s.client.NewRequest("GET", u, nil)
2421+
if err != nil {
2422+
return false, nil, err
2423+
}
2424+
2425+
privateReporting := new(checkPrivateReporting)
2426+
resp, err := s.client.Do(ctx, req, privateReporting)
2427+
return privateReporting.Enabled, resp, err
2428+
}

github/repos_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -4430,3 +4430,36 @@ func TestRepositoriesService_DisablePrivateReporting(t *testing.T) {
44304430
return client.Repositories.DisablePrivateReporting(ctx, "owner", "repo")
44314431
})
44324432
}
4433+
4434+
func TestRepositoriesService_IsPrivateReportingEnabled(t *testing.T) {
4435+
client, mux, _, teardown := setup()
4436+
defer teardown()
4437+
4438+
mux.HandleFunc("/repos/owner/repo/private-vulnerability-reporting", func(w http.ResponseWriter, r *http.Request) {
4439+
testMethod(t, r, "GET")
4440+
fmt.Fprint(w, `{"enabled": true}`)
4441+
})
4442+
4443+
ctx := context.Background()
4444+
enabled, _, err := client.Repositories.IsPrivateReportingEnabled(ctx, "owner", "repo")
4445+
if err != nil {
4446+
t.Errorf("Repositories.IsPrivateReportingEnabled returned error: %v", err)
4447+
}
4448+
if want := true; enabled != want {
4449+
t.Errorf("Repositories.IsPrivateReportingEnabled returned %+v, want %+v", enabled, want)
4450+
}
4451+
4452+
const methodName = "IsPrivateReportingEnabled"
4453+
testBadOptions(t, methodName, func() (err error) {
4454+
_, _, err = client.Repositories.IsPrivateReportingEnabled(ctx, "\n", "\n")
4455+
return err
4456+
})
4457+
4458+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
4459+
got, resp, err := client.Repositories.IsPrivateReportingEnabled(ctx, "owner", "repo")
4460+
if got {
4461+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want false", methodName, got)
4462+
}
4463+
return resp, err
4464+
})
4465+
}

0 commit comments

Comments
 (0)