@@ -173,33 +173,19 @@ type BranchListOptions struct {
173
173
// RepositoryListOptions specifies the optional parameters to the
174
174
// RepositoriesService.List method.
175
175
type RepositoryListOptions struct {
176
- // Visibility of repositories to list. Can be one of all, public, or private.
177
- // Default: all
176
+ // See RepositoryListByAuthenticatedUserOptions.Visibility
178
177
Visibility string `url:"visibility,omitempty"`
179
178
180
- // List repos of given affiliation[s].
181
- // Comma-separated list of values. Can include:
182
- // * owner: Repositories that are owned by the authenticated user.
183
- // * collaborator: Repositories that the user has been added to as a
184
- // collaborator.
185
- // * organization_member: Repositories that the user has access to through
186
- // being a member of an organization. This includes every repository on
187
- // every team that the user is on.
188
- // Default: owner,collaborator,organization_member
179
+ // See RepositoryListByAuthenticatedUserOptions.Affiliation
189
180
Affiliation string `url:"affiliation,omitempty"`
190
181
191
- // Type of repositories to list.
192
- // Can be one of all, owner, public, private, member. Default: all
193
- // Will cause a 422 error if used in the same request as visibility or
194
- // affiliation.
182
+ // See RepositoryListByUserOptions.Type or RepositoryListByAuthenticatedUserOptions.Type
195
183
Type string `url:"type,omitempty"`
196
184
197
- // How to sort the repository list. Can be one of created, updated, pushed,
198
- // full_name. Default: full_name
185
+ // See RepositoryListByUserOptions.Sort or RepositoryListByAuthenticatedUserOptions.Sort
199
186
Sort string `url:"sort,omitempty"`
200
187
201
- // Direction in which to sort repositories. Can be one of asc or desc.
202
- // Default: when using full_name: asc; otherwise desc
188
+ // See RepositoryListByUserOptions.Direction or RepositoryListByAuthenticatedUserOptions.Direction
203
189
Direction string `url:"direction,omitempty"`
204
190
205
191
ListOptions
@@ -262,21 +248,66 @@ func (d DependabotSecurityUpdates) String() string {
262
248
return Stringify (d )
263
249
}
264
250
265
- // List the repositories for a user. Passing the empty string will list
266
- // repositories for the authenticated user.
251
+ // List calls either RepositoriesService.ListByUser or RepositoriesService.ListByAuthenticatedUser
252
+ // depending on whether user is empty.
253
+ //
254
+ // Deprecated: Use RepositoriesService.ListByUser or RepositoriesService.ListByAuthenticatedUser instead.
267
255
//
268
256
// GitHub API docs: https://docs.github.com/rest/repos/repos#list-repositories-for-a-user
269
257
// GitHub API docs: https://docs.github.com/rest/repos/repos#list-repositories-for-the-authenticated-user
270
258
//
271
259
//meta:operation GET /user/repos
272
260
//meta:operation GET /users/{username}/repos
273
261
func (s * RepositoriesService ) List (ctx context.Context , user string , opts * RepositoryListOptions ) ([]* Repository , * Response , error ) {
274
- var u string
275
- if user != "" {
276
- u = fmt .Sprintf ("users/%v/repos" , user )
277
- } else {
278
- u = "user/repos"
262
+ if opts == nil {
263
+ opts = & RepositoryListOptions {}
279
264
}
265
+ if user != "" {
266
+ return s .ListByUser (ctx , user , & RepositoryListByUserOptions {
267
+ Type : opts .Type ,
268
+ Sort : opts .Sort ,
269
+ Direction : opts .Direction ,
270
+ ListOptions : opts .ListOptions ,
271
+ })
272
+ }
273
+ return s .ListByAuthenticatedUser (ctx , & RepositoryListByAuthenticatedUserOptions {
274
+ Visibility : opts .Visibility ,
275
+ Affiliation : opts .Affiliation ,
276
+ Type : opts .Type ,
277
+ Sort : opts .Sort ,
278
+ Direction : opts .Direction ,
279
+ ListOptions : opts .ListOptions ,
280
+ })
281
+ }
282
+
283
+ // RepositoryListByUserOptions specifies the optional parameters to the
284
+ // RepositoriesService.ListByUser method.
285
+ type RepositoryListByUserOptions struct {
286
+ // Limit results to repositories of the specified type.
287
+ // Default: owner
288
+ // Can be one of: all, owner, member
289
+ Type string `url:"type,omitempty"`
290
+
291
+ // The property to sort the results by.
292
+ // Default: full_name
293
+ // Can be one of: created, updated, pushed, full_name
294
+ Sort string `url:"sort,omitempty"`
295
+
296
+ // The order to sort by.
297
+ // Default: asc when using full_name, otherwise desc.
298
+ // Can be one of: asc, desc
299
+ Direction string `url:"direction,omitempty"`
300
+
301
+ ListOptions
302
+ }
303
+
304
+ // ListByUser lists public repositories for the specified user.
305
+ //
306
+ // GitHub API docs: https://docs.github.com/rest/repos/repos#list-repositories-for-a-user
307
+ //
308
+ //meta:operation GET /users/{username}/repos
309
+ func (s * RepositoriesService ) ListByUser (ctx context.Context , user string , opts * RepositoryListByUserOptions ) ([]* Repository , * Response , error ) {
310
+ u := fmt .Sprintf ("users/%v/repos" , user )
280
311
u , err := addOptions (u , opts )
281
312
if err != nil {
282
313
return nil , nil , err
@@ -287,9 +318,68 @@ func (s *RepositoriesService) List(ctx context.Context, user string, opts *Repos
287
318
return nil , nil , err
288
319
}
289
320
290
- // TODO: remove custom Accept headers when APIs fully launch.
291
- acceptHeaders := []string {mediaTypeTopicsPreview , mediaTypeRepositoryVisibilityPreview }
292
- req .Header .Set ("Accept" , strings .Join (acceptHeaders , ", " ))
321
+ var repos []* Repository
322
+ resp , err := s .client .Do (ctx , req , & repos )
323
+ if err != nil {
324
+ return nil , resp , err
325
+ }
326
+
327
+ return repos , resp , nil
328
+ }
329
+
330
+ // RepositoryListByAuthenticatedUserOptions specifies the optional parameters to the
331
+ // RepositoriesService.ListByAuthenticatedUser method.
332
+ type RepositoryListByAuthenticatedUserOptions struct {
333
+ // Limit results to repositories with the specified visibility.
334
+ // Default: all
335
+ // Can be one of: all, public, private
336
+ Visibility string `url:"visibility,omitempty"`
337
+
338
+ // List repos of given affiliation[s].
339
+ // Comma-separated list of values. Can include:
340
+ // * owner: Repositories that are owned by the authenticated user.
341
+ // * collaborator: Repositories that the user has been added to as a
342
+ // collaborator.
343
+ // * organization_member: Repositories that the user has access to through
344
+ // being a member of an organization. This includes every repository on
345
+ // every team that the user is on.
346
+ // Default: owner,collaborator,organization_member
347
+ Affiliation string `url:"affiliation,omitempty"`
348
+
349
+ // Limit results to repositories of the specified type. Will cause a 422 error if
350
+ // used in the same request as visibility or affiliation.
351
+ // Default: all
352
+ // Can be one of: all, owner, public, private, member
353
+ Type string `url:"type,omitempty"`
354
+
355
+ // The property to sort the results by.
356
+ // Default: full_name
357
+ // Can be one of: created, updated, pushed, full_name
358
+ Sort string `url:"sort,omitempty"`
359
+
360
+ // Direction in which to sort repositories. Can be one of asc or desc.
361
+ // Default: when using full_name: asc; otherwise desc
362
+ Direction string `url:"direction,omitempty"`
363
+
364
+ ListOptions
365
+ }
366
+
367
+ // ListByAuthenticatedUser lists repositories for the authenticated user.
368
+ //
369
+ // GitHub API docs: https://docs.github.com/rest/repos/repos#list-repositories-for-the-authenticated-user
370
+ //
371
+ //meta:operation GET /user/repos
372
+ func (s * RepositoriesService ) ListByAuthenticatedUser (ctx context.Context , opts * RepositoryListByAuthenticatedUserOptions ) ([]* Repository , * Response , error ) {
373
+ u := "user/repos"
374
+ u , err := addOptions (u , opts )
375
+ if err != nil {
376
+ return nil , nil , err
377
+ }
378
+
379
+ req , err := s .client .NewRequest ("GET" , u , nil )
380
+ if err != nil {
381
+ return nil , nil , err
382
+ }
293
383
294
384
var repos []* Repository
295
385
resp , err := s .client .Do (ctx , req , & repos )
0 commit comments