Repository: google/go-github
Pull request #2653 (2023-02-01 08:24:53)

Add permission filter for list collaborators
Fixes https://github.com/google/go-github/issues/2651

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/2653?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2653](https://codecov.io/gh/google/go-github/pull/2653?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (f4de40c) into [master](https://codecov.io/gh/google/go-github/commit/72dd8ad734d4c10072d88321bfa91a6dea76181c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (72dd8ad) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #2653   +/-   ##
=======================================
  Coverage   98.10%   98.10%           
=======================================
  Files         131      131           
  Lines       11442    11442           
=======================================
  Hits        11225    11225           
  Misses        148      148           
  Partials       69       69           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/2653?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/repos\_collaborators.go](https://codecov.io/gh/google/go-github/pull/2653?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL3JlcG9zX2NvbGxhYm9yYXRvcnMuZ28=) | `100.00% <ø> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)


Patch:
diff --git a/github/repos_collaborators.go b/github/repos_collaborators.go
index abc4161c..c2396872 100644
--- a/github/repos_collaborators.go
+++ b/github/repos_collaborators.go
@@ -23,6 +23,13 @@ type ListCollaboratorsOptions struct {
 	// Default value is "all".
 	Affiliation string `url:"affiliation,omitempty"`
 
+	// Permission specifies how collaborators should be filtered by the permissions they have on the repository.
+	// Possible values are:
+	// "pull", "triage", "push", "maintain", "admin"
+	//
+	// If not specified, all collaborators will be returned.
+	Permission string `url:"permission,omitempty"`
+
 	ListOptions
 }
 


Test patch:
diff --git a/github/actions_artifacts_test.go b/github/actions_artifacts_test.go
index 345a0875..e35a873b 100644
--- a/github/actions_artifacts_test.go
+++ b/github/actions_artifacts_test.go
@@ -368,23 +368,6 @@ func TestActionsService_DownloadArtifact_StatusMovedPermanently_followRedirects(
 	}
 }
 
-func TestActionsService_DownloadArtifact_invalidLocationHeader(t *testing.T) {
-	client, mux, _, teardown := setup()
-	defer teardown()
-
-	mux.HandleFunc("/repos/o/r/actions/artifacts/1/zip", func(w http.ResponseWriter, r *http.Request) {
-		testMethod(t, r, "GET")
-		ctlChar := 0x7f
-		badURL := "https://google.com" + string(byte(ctlChar))
-		w.Header().Add("Location", badURL)
-		w.WriteHeader(http.StatusFound)
-	})
-
-	ctx := context.Background()
-	_, _, err := client.Actions.DownloadArtifact(ctx, "o", "r", 1, false)
-	testURLParseError(t, err)
-}
-
 func TestActionsService_DeleteArtifact(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()
diff --git a/github/repos_collaborators_test.go b/github/repos_collaborators_test.go
index 8bb6c15c..8953d36b 100644
--- a/github/repos_collaborators_test.go
+++ b/github/repos_collaborators_test.go
@@ -94,6 +94,46 @@ func TestRepositoriesService_ListCollaborators_withAffiliation(t *testing.T) {
 	})
 }
 
+func TestRepositoriesService_ListCollaborators_withPermission(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/collaborators", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testFormValues(t, r, values{"permission": "pull", "page": "2"})
+		fmt.Fprintf(w, `[{"id":1}, {"id":2}]`)
+	})
+
+	opt := &ListCollaboratorsOptions{
+		ListOptions: ListOptions{Page: 2},
+		Permission:  "pull",
+	}
+	ctx := context.Background()
+	users, _, err := client.Repositories.ListCollaborators(ctx, "o", "r", opt)
+	if err != nil {
+		t.Errorf("Repositories.ListCollaborators returned error: %v", err)
+	}
+
+	want := []*User{{ID: Int64(1)}, {ID: Int64(2)}}
+	if !cmp.Equal(users, want) {
+		t.Errorf("Repositories.ListCollaborators returned %+v, want %+v", users, want)
+	}
+
+	const methodName = "ListCollaborators"
+	testBadOptions(t, methodName, func() (err error) {
+		_, _, err = client.Repositories.ListCollaborators(ctx, "\n", "\n", opt)
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.ListCollaborators(ctx, "o", "r", opt)
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
+}
+
 func TestRepositoriesService_ListCollaborators_invalidOwner(t *testing.T) {
 	client, _, _, teardown := setup()
 	defer teardown()
diff --git a/github/repos_contents_test.go b/github/repos_contents_test.go
index db3efb91..6616e5af 100644
--- a/github/repos_contents_test.go
+++ b/github/repos_contents_test.go
@@ -744,23 +744,6 @@ func TestRepositoriesService_GetArchiveLink_StatusMovedPermanently_followRedirec
 	}
 }
 
-func TestRepositoriesService_GetArchiveLink_invalidLocationHeader(t *testing.T) {
-	client, mux, _, teardown := setup()
-	defer teardown()
-
-	mux.HandleFunc("/repos/o/r/tarball", func(w http.ResponseWriter, r *http.Request) {
-		testMethod(t, r, "GET")
-		ctlChar := 0x7f
-		badURL := "https://google.com" + string(byte(ctlChar))
-		w.Header().Add("Location", badURL)
-		w.WriteHeader(http.StatusFound)
-	})
-
-	ctx := context.Background()
-	_, _, err := client.Repositories.GetArchiveLink(ctx, "o", "r", Tarball, &RepositoryContentGetOptions{}, false)
-	testURLParseError(t, err)
-}
-
 func TestRepositoriesService_GetContents_NoTrailingSlashInDirectoryApiPath(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()