@@ -55,19 +55,36 @@ func (f *GitlabDownloaderFactory) GitServiceType() structs.GitServiceType {
5555 return structs .GitlabService
5656}
5757
58+ type gitlabIIDResolver struct {
59+ maxIssueIID int64
60+ frozen bool
61+ }
62+
63+ func (r * gitlabIIDResolver ) recordIssueIID (issueIID int ) {
64+ if r .frozen {
65+ panic ("cannot record issue IID after pull request IID generation has started" )
66+ }
67+ r .maxIssueIID = max (r .maxIssueIID , int64 (issueIID ))
68+ }
69+
70+ func (r * gitlabIIDResolver ) generatePullRequestNumber (mrIID int ) int64 {
71+ r .frozen = true
72+ return r .maxIssueIID + int64 (mrIID )
73+ }
74+
5875// GitlabDownloader implements a Downloader interface to get repository information
5976// from gitlab via go-gitlab
6077// - issueCount is incremented in GetIssues() to ensure PR and Issue numbers do not overlap,
6178// because Gitlab has individual Issue and Pull Request numbers.
6279type GitlabDownloader struct {
6380 base.NullDownloader
64- ctx context.Context
65- client * gitlab.Client
66- baseURL string
67- repoID int
68- repoName string
69- issueCount int64
70- maxPerPage int
81+ ctx context.Context
82+ client * gitlab.Client
83+ baseURL string
84+ repoID int
85+ repoName string
86+ iidResolver gitlabIIDResolver
87+ maxPerPage int
7188}
7289
7390// NewGitlabDownloader creates a gitlab Downloader via gitlab API
@@ -450,8 +467,8 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
450467 Context : gitlabIssueContext {IsMergeRequest : false },
451468 })
452469
453- // increment issueCount , to be used in GetPullRequests()
454- g .issueCount ++
470+ // record the issue IID , to be used in GetPullRequests()
471+ g .iidResolver . recordIssueIID ( issue . IID )
455472 }
456473
457474 return allIssues , len (issues ) < perPage , nil
@@ -594,8 +611,8 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
594611 awardPage ++
595612 }
596613
597- // Add the PR ID to the Issue Count because PR and Issues share ID space in Gitea
598- newPRNumber := g .issueCount + int64 (pr .IID )
614+ // Generate new PR Numbers by the known Issue Numbers, because they share the same number space in Gitea, but they are independent in Gitlab
615+ newPRNumber := g .iidResolver . generatePullRequestNumber (pr .IID )
599616
600617 allPRs = append (allPRs , & base.PullRequest {
601618 Title : pr .Title ,
0 commit comments