5
5
6
6
package github
7
7
8
- import (
9
- "fmt"
10
- "net/url"
11
- "strconv"
12
- )
8
+ import "fmt"
13
9
14
10
// RepositoriesService handles communication with the repository related
15
11
// methods of the GitHub API.
@@ -59,18 +55,17 @@ func (r Repository) String() string {
59
55
type RepositoryListOptions struct {
60
56
// Type of repositories to list. Possible values are: all, owner, public,
61
57
// private, member. Default is "all".
62
- Type string
58
+ Type string `url:"type,omitempty"`
63
59
64
60
// How to sort the repository list. Possible values are: created, updated,
65
61
// pushed, full_name. Default is "full_name".
66
- Sort string
62
+ Sort string `url:"sort,omitempty"`
67
63
68
64
// Direction in which to sort repositories. Possible values are: asc, desc.
69
65
// Default is "asc" when sort is "full_name", otherwise default is "desc".
70
- Direction string
66
+ Direction string `url:"direction,omitempty"`
71
67
72
- // For paginated result sets, page of results to retrieve.
73
- Page int
68
+ ListOptions
74
69
}
75
70
76
71
// 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
84
79
} else {
85
80
u = "user/repos"
86
81
}
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
95
85
}
96
86
97
87
req , err := s .client .NewRequest ("GET" , u , nil )
@@ -109,23 +99,19 @@ func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]R
109
99
type RepositoryListByOrgOptions struct {
110
100
// Type of repositories to list. Possible values are: all, public, private,
111
101
// forks, sources, member. Default is "all".
112
- Type string
102
+ Type string `url:"type,omitempty"`
113
103
114
- // For paginated result sets, page of results to retrieve.
115
- Page int
104
+ ListOptions
116
105
}
117
106
118
107
// ListByOrg lists the repositories for an organization.
119
108
//
120
109
// GitHub API docs: http://developer.github.com/v3/repos/#list-organization-repositories
121
110
func (s * RepositoriesService ) ListByOrg (org string , opt * RepositoryListByOrgOptions ) ([]Repository , * Response , error ) {
122
111
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
129
115
}
130
116
131
117
req , err := s .client .NewRequest ("GET" , u , nil )
@@ -142,19 +128,18 @@ func (s *RepositoriesService) ListByOrg(org string, opt *RepositoryListByOrgOpti
142
128
// RepositoriesService.ListAll method.
143
129
type RepositoryListAllOptions struct {
144
130
// ID of the last repository seen
145
- Since int
131
+ Since int `url:"since,omitempty"`
132
+
133
+ ListOptions
146
134
}
147
135
148
136
// ListAll lists all GitHub repositories in the order that they were created.
149
137
//
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
151
139
func (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
158
143
}
159
144
160
145
req , err := s .client .NewRequest ("GET" , u , nil )
0 commit comments