@@ -55,19 +55,36 @@ func (f *GitlabDownloaderFactory) GitServiceType() structs.GitServiceType {
55
55
return structs .GitlabService
56
56
}
57
57
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
+
58
75
// GitlabDownloader implements a Downloader interface to get repository information
59
76
// from gitlab via go-gitlab
60
77
// - issueCount is incremented in GetIssues() to ensure PR and Issue numbers do not overlap,
61
78
// because Gitlab has individual Issue and Pull Request numbers.
62
79
type GitlabDownloader struct {
63
80
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
71
88
}
72
89
73
90
// NewGitlabDownloader creates a gitlab Downloader via gitlab API
@@ -450,8 +467,8 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
450
467
Context : gitlabIssueContext {IsMergeRequest : false },
451
468
})
452
469
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 )
455
472
}
456
473
457
474
return allIssues , len (issues ) < perPage , nil
@@ -594,8 +611,8 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
594
611
awardPage ++
595
612
}
596
613
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 )
599
616
600
617
allPRs = append (allPRs , & base.PullRequest {
601
618
Title : pr .Title ,
0 commit comments