|
7 | 7 |
|
8 | 8 | "gitlab-sync/internal/utils" |
9 | 9 |
|
| 10 | + gitlab "gitlab.com/gitlab-org/api/client-go" |
10 | 11 | "go.uber.org/zap" |
11 | 12 | ) |
12 | 13 |
|
@@ -70,7 +71,7 @@ func MirrorGitlabs(gitlabMirrorArgs *utils.ParserArgs) []error { |
70 | 71 |
|
71 | 72 | // In case of dry run, simply print the groups and projects that would be created or updated |
72 | 73 | if gitlabMirrorArgs.DryRun { |
73 | | - DryRun(sourceGitlabInstance, gitlabMirrorArgs) |
| 74 | + destinationGitlabInstance.DryRun(sourceGitlabInstance, gitlabMirrorArgs.MirrorMapping) |
74 | 75 | return nil |
75 | 76 | } |
76 | 77 |
|
@@ -128,28 +129,55 @@ func processFilters(filters *utils.MirrorMapping) (map[string]struct{}, map[stri |
128 | 129 | } |
129 | 130 |
|
130 | 131 | // DryRun prints the groups and projects that would be created or updated in dry run mode. |
131 | | -func DryRun(sourceGitlabInstance *GitlabInstance, gitlabMirrorArgs *utils.ParserArgs) { |
| 132 | +func (destinationGitlabInstance *GitlabInstance) DryRun(sourceGitlabInstance *GitlabInstance, mirrorMapping *utils.MirrorMapping) []error { |
132 | 133 | zap.L().Info("Dry run mode enabled, will not create groups or projects") |
133 | 134 | zap.L().Info("Groups that will be created (or updated if they already exist):") |
134 | | - for sourceGroupPath, copyOptions := range gitlabMirrorArgs.MirrorMapping.Groups { |
| 135 | + for sourceGroupPath, copyOptions := range mirrorMapping.Groups { |
135 | 136 | if sourceGroup, ok := sourceGitlabInstance.Groups[sourceGroupPath]; ok { |
136 | 137 | fmt.Printf(" - %s (source gitlab) -> %s (destination gitlab)\n", sourceGroup.WebURL, copyOptions.DestinationPath) |
137 | 138 | } |
138 | 139 | } |
139 | 140 | zap.L().Info("Projects that will be created (or updated if they already exist):") |
140 | | - for sourceProjectPath, copyOptions := range gitlabMirrorArgs.MirrorMapping.Projects { |
| 141 | + for sourceProjectPath, copyOptions := range mirrorMapping.Projects { |
141 | 142 | if sourceProject, ok := sourceGitlabInstance.Projects[sourceProjectPath]; ok { |
142 | 143 | fmt.Printf(" - %s (source gitlab) -> %s (destination gitlab)\n", sourceProject.WebURL, copyOptions.DestinationPath) |
| 144 | + |
| 145 | + if copyOptions.MirrorReleases { |
| 146 | + if err := destinationGitlabInstance.DryRunReleases(sourceGitlabInstance, sourceProject, copyOptions); err != nil { |
| 147 | + zap.L().Error("Failed to dry run releases", zap.Error(err)) |
| 148 | + return []error{err} |
| 149 | + } |
| 150 | + } |
143 | 151 | } |
| 152 | + |
| 153 | + } |
| 154 | + zap.L().Info("Dry run completed") |
| 155 | + return nil |
| 156 | +} |
| 157 | + |
| 158 | +// DryRunReleases prints the releases that would be created in dry run mode. |
| 159 | +// It fetches the releases from the source project and prints them. |
| 160 | +// It does not create any releases in the destination project. |
| 161 | +func (destinationGitlabInstance *GitlabInstance) DryRunReleases(sourceGitlabInstance *GitlabInstance, sourceProject *gitlab.Project, copyOptions *utils.MirroringOptions) error { |
| 162 | + // Fetch releases from the source project |
| 163 | + sourceReleases, _, err := sourceGitlabInstance.Gitlab.Releases.ListReleases(sourceProject.ID, &gitlab.ListReleasesOptions{}) |
| 164 | + if err != nil { |
| 165 | + return fmt.Errorf("failed to fetch releases for source project %s: %s", sourceProject.HTTPURLToRepo, err) |
144 | 166 | } |
| 167 | + // Print the releases that will be created in the destination project |
| 168 | + for _, release := range sourceReleases { |
| 169 | + fmt.Printf(" - Release %s will be created in %s (if it does not already exist)\n", release.Name, destinationGitlabInstance.Gitlab.BaseURL().String()+copyOptions.DestinationPath) |
| 170 | + } |
| 171 | + return nil |
145 | 172 | } |
146 | 173 |
|
147 | | -func (destinationGitlab *GitlabInstance) CheckDestinationInstance() error { |
| 174 | +// CheckDestinationInstance checks the destination GitLab instance for version and license compatibility. |
| 175 | +func (g *GitlabInstance) CheckDestinationInstance() error { |
148 | 176 | zap.L().Info("Checking destination GitLab instance") |
149 | | - if err := destinationGitlab.CheckVersion(); err != nil { |
| 177 | + if err := g.CheckVersion(); err != nil { |
150 | 178 | return fmt.Errorf("destination GitLab instance version check failed: %w", err) |
151 | 179 | } |
152 | | - if err := destinationGitlab.CheckVersion(); err != nil { |
| 180 | + if err := g.CheckLicense(); err != nil { |
153 | 181 | return fmt.Errorf("destination GitLab instance version check failed: %w", err) |
154 | 182 | } |
155 | 183 | return nil |
|
0 commit comments