Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions github/repos_collaborators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
40 changes: 40 additions & 0 deletions github/repos_collaborators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down