-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepositories.go
72 lines (60 loc) · 1.49 KB
/
repositories.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"fmt"
"github.com/google/go-github/v24/github"
)
type OrganizationRepository struct {
name string
page int
perPage int
}
func (o OrganizationRepository) Total(ctx context.Context, client *github.Client) int {
org, _, err := client.Organizations.Get(ctx, o.name)
if err != nil {
fmt.Println(err)
return 0
}
return org.GetPublicRepos() + org.GetTotalPrivateRepos()
}
func (o OrganizationRepository) Next() Lister {
res := o
res.page++
return res
}
func (o OrganizationRepository) List(ctx context.Context, client *github.Client) ([]*github.Repository, *github.Response, error) {
return client.Repositories.ListByOrg(ctx, o.name, &github.RepositoryListByOrgOptions{
Type: "all",
ListOptions: github.ListOptions{
Page: o.page,
PerPage: o.perPage,
},
})
}
type UserRepository struct {
name string
page int
perPage int
}
func (u UserRepository) Total(ctx context.Context, client *github.Client) int {
user, _, err := client.Users.Get(ctx, u.name)
if err != nil {
fmt.Println(err)
return 0
}
return user.GetPublicRepos() + user.GetTotalPrivateRepos()
}
func (u UserRepository) Next() Lister {
res := u
res.page++
return res
}
func (u UserRepository) List(ctx context.Context, client *github.Client) ([]*github.Repository, *github.Response, error) {
return client.Repositories.List(ctx, u.name, &github.RepositoryListOptions{
Type: "all",
ListOptions: github.ListOptions{
Page: u.page,
PerPage: u.perPage,
},
})
}