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 #379

Closed

Conversation

Systemnick
Copy link

When you are trying to fetch more than 20 migrations response headers look like on this picture:
image
That means that there are more than one result page.
https://gitlab.com/help/api/README.md#pagination

@coveralls
Copy link

coveralls commented Apr 21, 2020

Pull Request Test Coverage Report for Build 812

  • 0 of 71 (0.0%) changed or added relevant lines in 1 file are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.4%) to 52.863%

Changes Missing Coverage Covered Lines Changed/Added Lines %
source/gitlab/gitlab.go 0 71 0.0%
Files with Coverage Reduction New Missed Lines %
source/gitlab/gitlab.go 3 1.65%
Totals Coverage Status
Change from base Build 811: -0.4%
Covered Lines: 2640
Relevant Lines: 4994

💛 - Coveralls

Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

A few minor issues to address and we should be good to go!

source/gitlab/gitlab.go Outdated Show resolved Hide resolved
return err
}

if response.StatusCode != http.StatusOK {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, this will fail the whole readDirectory() call if a single request in the request chain fails.
To reduce the chances of that happening, it may be worth defaulting the per_page option to 100 (the max) and making that configurable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you recommend to configure that parameter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I mean how to pass that parameter from migrate.go to a particular gitlab driver. Do you think extending Gitlab.url string is a good idea? For instance, gitlab://username:token@gitlab.com/11197284/migrations?per_page=50

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're using migrate via the CLI, the only way to configure the source driver is via URL query params. We try our best to avoid conflicts with the underlying driver, but for gitlab, that doesn't seem like it'll be an issue.

If you're using migrate as a Go library, the driver can be configured via WithInstance(). It looks like gitlab isn't properly using Config

source/gitlab/gitlab.go Outdated Show resolved Hide resolved
@Systemnick Systemnick requested a review from dhui April 21, 2020 10:15
dhui
dhui previously approved these changes Apr 21, 2020
Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for you for updating your PR to address earlier feedback and sorry about the long turn around time

@@ -1,12 +1,13 @@
# gitlab

`gitlab://user:personal-access-token@gitlab_url/project_id/path#ref`
`gitlab://user:personal-access-token@gitlab_url/project_id/path#ref?per_page=20`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inaccurate. The query precedes the fragment: https://golang.org/pkg/net/url/#URL

source/gitlab/README.md Show resolved Hide resolved
listOptions *gitlab.ListTreeOptions
getOptions *gitlab.GetFileOptions
migrations *source.Migrations
}

type Config struct {
Scheme string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the scheme need to be specified? When would it not be https?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For local (in-house) Gitlab instances it's up to you to choose a scheme. Our internal network doesn't provide https access to Gitlab, only http.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you set the Scheme via URL e.g. in Open() you can't use u.Scheme since that'll be gitlab, not http or https. The scheme will need to be provided via a x-scheme URL query parameter.

@@ -120,8 +132,16 @@ func WithInstance(client *gitlab.Client, config *Config) (source.Driver, error)
func (g *Gitlab) readDirectory() error {
var nodes []*gitlab.TreeNode

g.listOptions = &gitlab.ListTreeOptions{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readDirectory() shouldn't modify the receiver e.g. g *Gitlab
Instead, the Gitlab instance should be configured upfront when it's created

@@ -153,6 +173,13 @@ func (g *Gitlab) readDirectory() error {
return nil
}

func (g *Gitlab) ensureFields() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, this should be called in Open() or WithInstance() instead of Gitlab methods that act on a Gitlab instance

if m, ok := g.migrations.Up(version); ok {
f, response, err := g.client.RepositoryFiles.GetFile(g.projectID, m.Raw, g.getOptions)
g.getOptions = &gitlab.GetFileOptions{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, don't set instance params in methods that shouldn't be modifying the instance

if m, ok := g.migrations.Down(version); ok {
f, response, err := g.client.RepositoryFiles.GetFile(g.projectID, m.Raw, g.getOptions)
g.getOptions = &gitlab.GetFileOptions{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

} else {
return v, nil
}
}

func (g *Gitlab) ReadUp(version uint) (r io.ReadCloser, identifier string, err error) {
g.ensureFields()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

}

func (g *Gitlab) ReadDown(version uint) (r io.ReadCloser, identifier string, err error) {
g.ensureFields()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

@mef13
Copy link
Contributor

mef13 commented Dec 15, 2020

Any news?

@dhui
Copy link
Member

dhui commented Jan 28, 2021

Superseded by #497

@dhui dhui closed this Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants