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
57package main
import (
"context"
"fmt"
"github.com/google/go-github/v71/github"
)
type GitHubClient struct {
*github.Client
}
func NewGitHubClient(client *github.Client) *GitHubClient {
return &GitHubClient{
Client: client,
}
}
func (c *GitHubClient) GetAllGitHubRepoByUsername(username string) ([]*github.Repository, error) {
repos := make([]*github.Repository, 0)
listOption := &github.ListOptions{
PerPage: 50,
Page: 1,
}
for {
sourcesRepo, resp, err := c.Repositories.ListByAuthenticatedUser(context.Background(), &github.RepositoryListByAuthenticatedUserOptions{
Type: "all",
Sort: "full_name",
ListOptions: *listOption,
})
if err != nil {
return nil, err
}
if len(sourcesRepo) == 0 {
break
}
fmt.Println("Page:", listOption.Page)
repos = append(repos, sourcesRepo...)
if resp.LastPage == listOption.Page {
break
}
listOption.Page++
}
fmt.Println("Total repositories:", len(repos))
return repos, nil
}