55
66package github
77
8- import (
9- "fmt"
10- "net/url"
11- "strconv"
12- )
8+ import "fmt"
139
1410// RepositoriesService handles communication with the repository related
1511// methods of the GitHub API.
@@ -59,18 +55,17 @@ func (r Repository) String() string {
5955type RepositoryListOptions struct {
6056 // Type of repositories to list. Possible values are: all, owner, public,
6157 // private, member. Default is "all".
62- Type string
58+ Type string `url:"type,omitempty"`
6359
6460 // How to sort the repository list. Possible values are: created, updated,
6561 // pushed, full_name. Default is "full_name".
66- Sort string
62+ Sort string `url:"sort,omitempty"`
6763
6864 // Direction in which to sort repositories. Possible values are: asc, desc.
6965 // Default is "asc" when sort is "full_name", otherwise default is "desc".
70- Direction string
66+ Direction string `url:"direction,omitempty"`
7167
72- // For paginated result sets, page of results to retrieve.
73- Page int
68+ ListOptions
7469}
7570
7671// List the repositories for a user. Passing the empty string will list
@@ -84,14 +79,9 @@ func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]R
8479 } else {
8580 u = "user/repos"
8681 }
87- if opt != nil {
88- params := url.Values {
89- "type" : []string {opt .Type },
90- "sort" : []string {opt .Sort },
91- "direction" : []string {opt .Direction },
92- "page" : []string {strconv .Itoa (opt .Page )},
93- }
94- u += "?" + params .Encode ()
82+ u , err := addOptions (u , opt )
83+ if err != nil {
84+ return nil , nil , err
9585 }
9686
9787 req , err := s .client .NewRequest ("GET" , u , nil )
@@ -109,23 +99,19 @@ func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]R
10999type RepositoryListByOrgOptions struct {
110100 // Type of repositories to list. Possible values are: all, public, private,
111101 // forks, sources, member. Default is "all".
112- Type string
102+ Type string `url:"type,omitempty"`
113103
114- // For paginated result sets, page of results to retrieve.
115- Page int
104+ ListOptions
116105}
117106
118107// ListByOrg lists the repositories for an organization.
119108//
120109// GitHub API docs: http://developer.github.com/v3/repos/#list-organization-repositories
121110func (s * RepositoriesService ) ListByOrg (org string , opt * RepositoryListByOrgOptions ) ([]Repository , * Response , error ) {
122111 u := fmt .Sprintf ("orgs/%v/repos" , org )
123- if opt != nil {
124- params := url.Values {
125- "type" : []string {opt .Type },
126- "page" : []string {strconv .Itoa (opt .Page )},
127- }
128- u += "?" + params .Encode ()
112+ u , err := addOptions (u , opt )
113+ if err != nil {
114+ return nil , nil , err
129115 }
130116
131117 req , err := s .client .NewRequest ("GET" , u , nil )
@@ -142,19 +128,18 @@ func (s *RepositoriesService) ListByOrg(org string, opt *RepositoryListByOrgOpti
142128// RepositoriesService.ListAll method.
143129type RepositoryListAllOptions struct {
144130 // ID of the last repository seen
145- Since int
131+ Since int `url:"since,omitempty"`
132+
133+ ListOptions
146134}
147135
148136// ListAll lists all GitHub repositories in the order that they were created.
149137//
150- // GitHub API docs: http://developer.github.com/v3/repos/#list-all-repositories
138+ // GitHub API docs: http://developer.github.com/v3/repos/#list-all-public- repositories
151139func (s * RepositoriesService ) ListAll (opt * RepositoryListAllOptions ) ([]Repository , * Response , error ) {
152- u := "repositories"
153- if opt != nil {
154- params := url.Values {
155- "since" : []string {strconv .Itoa (opt .Since )},
156- }
157- u += "?" + params .Encode ()
140+ u , err := addOptions ("repositories" , opt )
141+ if err != nil {
142+ return nil , nil , err
158143 }
159144
160145 req , err := s .client .NewRequest ("GET" , u , nil )
0 commit comments