Browse Source

Add support for affiliation and visibility in RepositoryListOptions.

Also updates comments in RepositoryListOptions to match the Github API docs
(https://developer.github.com/v3/repos/#list-your-repositories).

Fixes #231
Billy Lynch 10 years ago
parent
commit
45cbf2313c
2 changed files with 62 additions and 11 deletions
  1. +23
    -6
      github/repos.go
  2. +39
    -5
      github/repos_test.go

+ 23
- 6
github/repos.go View File

@ -110,16 +110,33 @@ func (r Repository) String() string {
// RepositoryListOptions specifies the optional parameters to the
// RepositoriesService.List method.
type RepositoryListOptions struct {
// Type of repositories to list. Possible values are: all, owner, public,
// private, member. Default is "all".
// Visibility of repositories to list. Can be one of all, public, or private.
// Default: all
Visibility string `url:"visibility,omitempty"`
// List repos of given affiliation[s].
// Comma-separated list of values. Can include:
// * owner: Repositories that are owned by the authenticated user.
// * collaborator: Repositories that the user has been added to as a
// collaborator.
// * organization_member: Repositories that the user has access to through
// being a member of an organization. This includes every repository on
// every team that the user is on.
// Default: owner,collaborator,organization_member
Affiliation string `url:"affiliation,omitempty"`
// Type of repositories to list.
// Can be one of all, owner, public, private, member. Default: all
// Will cause a 422 error if used in the same request as visibility or
// affiliation.
Type string `url:"type,omitempty"`
// How to sort the repository list. Possible values are: created, updated,
// pushed, full_name. Default is "full_name".
// How to sort the repository list. Can be one of created, updated, pushed,
// full_name. Default: full_name
Sort string `url:"sort,omitempty"`
// Direction in which to sort repositories. Possible values are: asc, desc.
// Default is "asc" when sort is "full_name", otherwise default is "desc".
// Direction in which to sort repositories. Can be one of asc or desc.
// Default: when using full_name: asc; otherwise desc
Direction string `url:"direction,omitempty"`
ListOptions


+ 39
- 5
github/repos_test.go View File

@ -42,15 +42,49 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeLicensesPreview)
testFormValues(t, r, values{
"type": "owner",
"sort": "created",
"direction": "asc",
"page": "2",
"visibility": "public",
"affiliation": "owner,collaborator",
"sort": "created",
"direction": "asc",
"page": "2",
})
fmt.Fprint(w, `[{"id":1}]`)
})
opt := &RepositoryListOptions{"owner", "created", "asc", ListOptions{Page: 2}}
opt := &RepositoryListOptions{
Visibility: "public",
Affiliation: "owner,collaborator",
Sort: "created",
Direction: "asc",
ListOptions: ListOptions{Page: 2},
}
repos, _, err := client.Repositories.List("u", opt)
if err != nil {
t.Errorf("Repositories.List returned error: %v", err)
}
want := []*Repository{{ID: Int(1)}}
if !reflect.DeepEqual(repos, want) {
t.Errorf("Repositories.List returned %+v, want %+v", repos, want)
}
}
func TestRepositoriesService_List_specifiedUser_type(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/users/u/repos", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeLicensesPreview)
testFormValues(t, r, values{
"type": "owner",
})
fmt.Fprint(w, `[{"id":1}]`)
})
opt := &RepositoryListOptions{
Type: "owner",
}
repos, _, err := client.Repositories.List("u", opt)
if err != nil {
t.Errorf("Repositories.List returned error: %v", err)


Loading…
Cancel
Save