From 93efe559b684518fc4370c93aba7c06d672a0184 Mon Sep 17 00:00:00 2001 From: Ravi Teja Date: Wed, 1 Feb 2023 13:52:26 +0530 Subject: [PATCH 1/3] add struct field --- github/repos_collaborators.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/github/repos_collaborators.go b/github/repos_collaborators.go index abc4161c3b..0c4a5a97b9 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 } From 0224b50400ccf4a0ab68ca9689902f627748db70 Mon Sep 17 00:00:00 2001 From: Sairaviteja27 <44663543+Sairaviteja27@users.noreply.github.com> Date: Thu, 2 Feb 2023 16:11:35 +0530 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/repos_collaborators.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/repos_collaborators.go b/github/repos_collaborators.go index 0c4a5a97b9..c2396872f2 100644 --- a/github/repos_collaborators.go +++ b/github/repos_collaborators.go @@ -25,9 +25,9 @@ type ListCollaboratorsOptions struct { // Permission specifies how collaborators should be filtered by the permissions they have on the repository. // Possible values are: - // pull, triage, push, maintain, admin + // "pull", "triage", "push", "maintain", "admin" // - // If not specified, all collaborators will be returned + // If not specified, all collaborators will be returned. Permission string `url:"permission,omitempty"` ListOptions From f4de40c4023d87b174313aa52562d83e55674e31 Mon Sep 17 00:00:00 2001 From: Ravi Teja Date: Thu, 2 Feb 2023 16:49:07 +0530 Subject: [PATCH 3/3] add test --- github/repos_collaborators_test.go | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/github/repos_collaborators_test.go b/github/repos_collaborators_test.go index 8bb6c15cf1..8953d36bcc 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()