diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-10-25 13:11:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-25 01:11:03 -0400 |
commit | d130cd147f24eb222a539a5b262d166f94aad5fa (patch) | |
tree | 9023851364860f8d4427909b9e2b182e49c57309 /modules/migrations/gitlab.go | |
parent | eab583714283fdcdac20bc61f000c76b87bbda35 (diff) | |
download | gitea-d130cd147f24eb222a539a5b262d166f94aad5fa.tar.gz gitea-d130cd147f24eb222a539a5b262d166f94aad5fa.zip |
Fix bug isEnd detection on getIssues/getPullRequests (#13299)
Diffstat (limited to 'modules/migrations/gitlab.go')
-rw-r--r-- | modules/migrations/gitlab.go | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/modules/migrations/gitlab.go b/modules/migrations/gitlab.go index 23cd90c747..d4b725b5be 100644 --- a/modules/migrations/gitlab.go +++ b/modules/migrations/gitlab.go @@ -68,6 +68,7 @@ type GitlabDownloader struct { repoName string issueCount int64 fetchPRcomments bool + maxPerPage int } // NewGitlabDownloader creates a gitlab Downloader via gitlab API @@ -99,10 +100,11 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, username, passw } return &GitlabDownloader{ - ctx: ctx, - client: gitlabClient, - repoID: gr.ID, - repoName: gr.Name, + ctx: ctx, + client: gitlabClient, + repoID: gr.ID, + repoName: gr.Name, + maxPerPage: 100, }, nil } @@ -159,7 +161,7 @@ func (g *GitlabDownloader) GetTopics() ([]string, error) { // GetMilestones returns milestones func (g *GitlabDownloader) GetMilestones() ([]*base.Milestone, error) { - var perPage = 100 + var perPage = g.maxPerPage var state = "all" var milestones = make([]*base.Milestone, 0, perPage) for i := 1; ; i++ { @@ -230,7 +232,7 @@ func (g *GitlabDownloader) normalizeColor(val string) string { // GetLabels returns labels func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) { - var perPage = 100 + var perPage = g.maxPerPage var labels = make([]*base.Label, 0, perPage) for i := 1; ; i++ { ls, _, err := g.client.Labels.ListLabels(g.repoID, &gitlab.ListLabelsOptions{ListOptions: gitlab.ListOptions{ @@ -281,7 +283,7 @@ func (g *GitlabDownloader) convertGitlabRelease(rel *gitlab.Release) *base.Relea // GetReleases returns releases func (g *GitlabDownloader) GetReleases() ([]*base.Release, error) { - var perPage = 100 + var perPage = g.maxPerPage var releases = make([]*base.Release, 0, perPage) for i := 1; ; i++ { ls, _, err := g.client.Releases.ListReleases(g.repoID, &gitlab.ListReleasesOptions{ @@ -330,6 +332,10 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er state := "all" sort := "asc" + if perPage > g.maxPerPage { + perPage = g.maxPerPage + } + opt := &gitlab.ListProjectIssuesOptions{ State: &state, Sort: &sort, @@ -401,7 +407,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er // GetComments returns comments according issueNumber // TODO: figure out how to transfer comment reactions func (g *GitlabDownloader) GetComments(issueNumber int64) ([]*base.Comment, error) { - var allComments = make([]*base.Comment, 0, 100) + var allComments = make([]*base.Comment, 0, g.maxPerPage) var page = 1 var realIssueNumber int64 @@ -415,14 +421,14 @@ func (g *GitlabDownloader) GetComments(issueNumber int64) ([]*base.Comment, erro realIssueNumber = issueNumber comments, resp, err = g.client.Discussions.ListIssueDiscussions(g.repoID, int(realIssueNumber), &gitlab.ListIssueDiscussionsOptions{ Page: page, - PerPage: 100, + PerPage: g.maxPerPage, }, nil, gitlab.WithContext(g.ctx)) } else { // If this is a PR, we need to figure out the Gitlab/original PR ID to be passed below realIssueNumber = issueNumber - g.issueCount comments, resp, err = g.client.Discussions.ListMergeRequestDiscussions(g.repoID, int(realIssueNumber), &gitlab.ListMergeRequestDiscussionsOptions{ Page: page, - PerPage: 100, + PerPage: g.maxPerPage, }, nil, gitlab.WithContext(g.ctx)) } @@ -465,6 +471,10 @@ func (g *GitlabDownloader) GetComments(issueNumber int64) ([]*base.Comment, erro // GetPullRequests returns pull requests according page and perPage func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullRequest, bool, error) { + if perPage > g.maxPerPage { + perPage = g.maxPerPage + } + opt := &gitlab.ListProjectMergeRequestsOptions{ ListOptions: gitlab.ListOptions{ PerPage: perPage, |