forked from forgejo/forgejo
[GITEA] Avoid conflicts of issue and PR numbers in GitLab migration (#1790)
Closes #1789. The bug was due to the fact that GitLab does not guarantee that issue numbers are created sequentially: some identifiers can be skipped. Therefore, the new pull requests numbers should not be offset by the number of issues, but by the maximum issue number. See for instance https://gitlab.com/troyengel/archbuild/-/issues/?sort=created_date&state=all&first_page_size=20, where there is only a singe issue with number "2". Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1790 Co-authored-by: Antonin Delpeuch <antonin@delpeuch.eu> Co-committed-by: Antonin Delpeuch <antonin@delpeuch.eu> (cherry picked from commit2c185c39fe
) (cherry picked from commit8f68dc4c9c
)
This commit is contained in:
parent
6cc9d06556
commit
7e932b7fca
10 changed files with 263 additions and 11 deletions
|
@ -57,17 +57,18 @@ func (f *GitlabDownloaderFactory) GitServiceType() structs.GitServiceType {
|
|||
|
||||
// GitlabDownloader implements a Downloader interface to get repository information
|
||||
// from gitlab via go-gitlab
|
||||
// - issueCount is incremented in GetIssues() to ensure PR and Issue numbers do not overlap,
|
||||
// - maxIssueNumber is the maximum issue number seen, updated in GetIssues() to ensure PR and Issue numbers do not overlap,
|
||||
// because Gitlab has individual Issue and Pull Request numbers.
|
||||
// Note that because some issue numbers may be skipped, this number may be greater than the total number of issues
|
||||
type GitlabDownloader struct {
|
||||
base.NullDownloader
|
||||
ctx context.Context
|
||||
client *gitlab.Client
|
||||
baseURL string
|
||||
repoID int
|
||||
repoName string
|
||||
issueCount int64
|
||||
maxPerPage int
|
||||
ctx context.Context
|
||||
client *gitlab.Client
|
||||
baseURL string
|
||||
repoID int
|
||||
repoName string
|
||||
maxIssueNumber int64
|
||||
maxPerPage int
|
||||
}
|
||||
|
||||
// NewGitlabDownloader creates a gitlab Downloader via gitlab API
|
||||
|
@ -450,8 +451,8 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
|
|||
Context: gitlabIssueContext{IsMergeRequest: false},
|
||||
})
|
||||
|
||||
// increment issueCount, to be used in GetPullRequests()
|
||||
g.issueCount++
|
||||
// update maxIssueNumber, to be used in GetPullRequests()
|
||||
g.maxIssueNumber = max(g.maxIssueNumber, int64(issue.IID))
|
||||
}
|
||||
|
||||
return allIssues, len(issues) < perPage, nil
|
||||
|
@ -608,7 +609,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
|
|||
}
|
||||
|
||||
// Add the PR ID to the Issue Count because PR and Issues share ID space in Gitea
|
||||
newPRNumber := g.issueCount + int64(pr.IID)
|
||||
newPRNumber := g.maxIssueNumber + int64(pr.IID)
|
||||
|
||||
allPRs = append(allPRs, &base.PullRequest{
|
||||
Title: pr.Title,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue