Repository: google/go-github
Pull request #3157 (2024-05-01 03:53:12)

Add support for check private vulnerability reporting endpoint
fixes https://github.com/google/go-github/issues/3152

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/3157?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
Attention: Patch coverage is `66.66667%` with `4 lines` in your changes are missing coverage. Please review.
> Project coverage is 92.86%. Comparing base [(`2b8c7fa`)](https://app.codecov.io/gh/google/go-github/commit/2b8c7fa86fcd1cb4a89a44c8e7b5a49fe4be8a45?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) to head [(`7433012`)](https://app.codecov.io/gh/google/go-github/pull/3157?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> Report is 47 commits behind head on master.

| [Files](https://app.codecov.io/gh/google/go-github/pull/3157?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Patch % | Lines |
|---|---|---|
| [github/repos.go](https://app.codecov.io/gh/google/go-github/pull/3157?src=pr&el=tree&filepath=github%2Frepos.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL3JlcG9zLmdv) | 66.66% | [2 Missing and 2 partials :warning: ](https://app.codecov.io/gh/google/go-github/pull/3157?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #3157      +/-   ##
==========================================
- Coverage   97.72%   92.86%   -4.86%     
==========================================
  Files         153      170      +17     
  Lines       13390    11448    -1942     
==========================================
- Hits        13085    10631    -2454     
- Misses        215      725     +510     
- Partials       90       92       +2     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/google/go-github/pull/3157?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).

Sairaviteja27: @gmlewis I think code coverage check is failing. Could you suggest if I should I add tests in other methods? 
gmlewis: > @gmlewis I think code coverage check is failing. Could you suggest if I should I add tests in other methods?

Don't worry about that.  We've had some weirdness with codecov lately and I've made two reports with the problems we've seen and don't have any resolution yet.  Thanks, though.
gmlewis: Thank you, @be0x74a !
Merging.

Patch:
diff --git a/github/repos.go b/github/repos.go
index 6fb0030a..630ce748 100644
--- a/github/repos.go
+++ b/github/repos.go
@@ -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
+}


Test patch:
diff --git a/github/repos_test.go b/github/repos_test.go
index 2b742bef..e07b1b36 100644
--- a/github/repos_test.go
+++ b/github/repos_test.go
@@ -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
+	})
+}