Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue when gitlab return only first 20 migrations (reopen) #497

Merged
merged 4 commits into from
Jan 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions source/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func init() {
source.Register("gitlab", &Gitlab{})
}

const DefaultMaxItemsPerPage = 100

var (
ErrNoUserInfo = fmt.Errorf("no username:token provided")
ErrNoAccessToken = fmt.Errorf("no access token")
Expand Down Expand Up @@ -88,6 +90,9 @@ func (g *Gitlab) Open(url string) (source.Driver, error) {
gn.listOptions = &gitlab.ListTreeOptions{
Path: &gn.path,
Ref: &u.Fragment,
ListOptions: gitlab.ListOptions{
PerPage: DefaultMaxItemsPerPage,
},
}

gn.getOptions = &gitlab.GetFileOptions{
Expand All @@ -113,13 +118,22 @@ func WithInstance(client *gitlab.Client, config *Config) (source.Driver, error)
}

func (g *Gitlab) readDirectory() error {
nodes, response, err := g.client.Repositories.ListTree(g.projectID, g.listOptions)
if err != nil {
return err
}
var nodes []*gitlab.TreeNode
for {
n, response, err := g.client.Repositories.ListTree(g.projectID, g.listOptions)
if err != nil {
return err
}

if response.StatusCode != http.StatusOK {
return ErrInvalidResponse
if response.StatusCode != http.StatusOK {
return ErrInvalidResponse
}

nodes = append(nodes, n...)
if response.CurrentPage >= response.TotalPages {
break
}
g.listOptions.ListOptions.Page = response.NextPage
}

for i := range nodes {
Expand Down