Skip to content

Commit 45cbf23

Browse files
committed
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 google#231
1 parent c31236d commit 45cbf23

File tree

2 files changed

+62
-11
lines changed

2 files changed

+62
-11
lines changed

github/repos.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,33 @@ func (r Repository) String() string {
110110
// RepositoryListOptions specifies the optional parameters to the
111111
// RepositoriesService.List method.
112112
type RepositoryListOptions struct {
113-
// Type of repositories to list. Possible values are: all, owner, public,
114-
// private, member. Default is "all".
113+
// Visibility of repositories to list. Can be one of all, public, or private.
114+
// Default: all
115+
Visibility string `url:"visibility,omitempty"`
116+
117+
// List repos of given affiliation[s].
118+
// Comma-separated list of values. Can include:
119+
// * owner: Repositories that are owned by the authenticated user.
120+
// * collaborator: Repositories that the user has been added to as a
121+
// collaborator.
122+
// * organization_member: Repositories that the user has access to through
123+
// being a member of an organization. This includes every repository on
124+
// every team that the user is on.
125+
// Default: owner,collaborator,organization_member
126+
Affiliation string `url:"affiliation,omitempty"`
127+
128+
// Type of repositories to list.
129+
// Can be one of all, owner, public, private, member. Default: all
130+
// Will cause a 422 error if used in the same request as visibility or
131+
// affiliation.
115132
Type string `url:"type,omitempty"`
116133

117-
// How to sort the repository list. Possible values are: created, updated,
118-
// pushed, full_name. Default is "full_name".
134+
// How to sort the repository list. Can be one of created, updated, pushed,
135+
// full_name. Default: full_name
119136
Sort string `url:"sort,omitempty"`
120137

121-
// Direction in which to sort repositories. Possible values are: asc, desc.
122-
// Default is "asc" when sort is "full_name", otherwise default is "desc".
138+
// Direction in which to sort repositories. Can be one of asc or desc.
139+
// Default: when using full_name: asc; otherwise desc
123140
Direction string `url:"direction,omitempty"`
124141

125142
ListOptions

github/repos_test.go

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,49 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) {
4242
testMethod(t, r, "GET")
4343
testHeader(t, r, "Accept", mediaTypeLicensesPreview)
4444
testFormValues(t, r, values{
45-
"type": "owner",
46-
"sort": "created",
47-
"direction": "asc",
48-
"page": "2",
45+
"visibility": "public",
46+
"affiliation": "owner,collaborator",
47+
"sort": "created",
48+
"direction": "asc",
49+
"page": "2",
4950
})
5051
fmt.Fprint(w, `[{"id":1}]`)
5152
})
5253

53-
opt := &RepositoryListOptions{"owner", "created", "asc", ListOptions{Page: 2}}
54+
opt := &RepositoryListOptions{
55+
Visibility: "public",
56+
Affiliation: "owner,collaborator",
57+
Sort: "created",
58+
Direction: "asc",
59+
ListOptions: ListOptions{Page: 2},
60+
}
61+
repos, _, err := client.Repositories.List("u", opt)
62+
if err != nil {
63+
t.Errorf("Repositories.List returned error: %v", err)
64+
}
65+
66+
want := []*Repository{{ID: Int(1)}}
67+
if !reflect.DeepEqual(repos, want) {
68+
t.Errorf("Repositories.List returned %+v, want %+v", repos, want)
69+
}
70+
}
71+
72+
func TestRepositoriesService_List_specifiedUser_type(t *testing.T) {
73+
setup()
74+
defer teardown()
75+
76+
mux.HandleFunc("/users/u/repos", func(w http.ResponseWriter, r *http.Request) {
77+
testMethod(t, r, "GET")
78+
testHeader(t, r, "Accept", mediaTypeLicensesPreview)
79+
testFormValues(t, r, values{
80+
"type": "owner",
81+
})
82+
fmt.Fprint(w, `[{"id":1}]`)
83+
})
84+
85+
opt := &RepositoryListOptions{
86+
Type: "owner",
87+
}
5488
repos, _, err := client.Repositories.List("u", opt)
5589
if err != nil {
5690
t.Errorf("Repositories.List returned error: %v", err)

0 commit comments

Comments
 (0)