forked from gitploy-io/gitploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.go
More file actions
49 lines (39 loc) · 1.04 KB
/
sync.go
File metadata and controls
49 lines (39 loc) · 1.04 KB
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
package github
import (
"context"
"github.com/gitploy-io/gitploy/model/ent"
"github.com/gitploy-io/gitploy/model/extent"
"github.com/gitploy-io/gitploy/pkg/e"
"github.com/google/go-github/v32/github"
)
func (g *Github) ListRemoteRepos(ctx context.Context, u *ent.User) ([]*extent.RemoteRepo, error) {
grs, err := g.listRemoteRepos(ctx, u)
if err != nil {
return nil, e.NewError(e.ErrorCodeInternalError, err)
}
remotes := make([]*extent.RemoteRepo, 0)
for _, r := range grs {
remotes = append(remotes, mapGithubRepoToRemotePerm(r))
}
return remotes, nil
}
func (g *Github) listRemoteRepos(ctx context.Context, u *ent.User) ([]*github.Repository, error) {
opt := &github.RepositoryListOptions{
ListOptions: github.ListOptions{PerPage: 100},
}
all := make([]*github.Repository, 0)
for {
remotes, res, err := g.Client(ctx, u.Token).
Repositories.
List(ctx, "", opt)
if err != nil {
return nil, err
}
all = append(all, remotes...)
if res.NextPage == 0 {
break
}
opt.Page = res.NextPage
}
return all, nil
}