Skip to content

Commit c61ad6f

Browse files
committed
style: separate utils between pkg and internal
1 parent a4b57c4 commit c61ad6f

File tree

13 files changed

+38
-27
lines changed

13 files changed

+38
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ go.sum
5959
sonar-project.properties
6060
unit-tests.xml
6161
coverage.out
62+
republisher.sh

cmd/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"gitlab-sync/internal/mirroring"
1010
"gitlab-sync/internal/utils"
11+
"gitlab-sync/pkg/helpers"
1112

1213
"github.com/spf13/cobra"
1314
"go.uber.org/zap"
@@ -58,14 +59,14 @@ func main() {
5859
zap.L().Debug("Parsing mirror mapping file")
5960
mapping, mappingErrors := utils.OpenMirrorMapping(mirrorMappingPath)
6061
if mappingErrors != nil {
61-
zap.L().Fatal("Error opening mirror mapping file", zap.Array("errors", utils.ErrorArray(mappingErrors)))
62+
zap.L().Fatal("Error opening mirror mapping file", zap.Array("errors", helpers.ErrorArray(mappingErrors)))
6263
}
6364
zap.L().Debug("Mirror mapping file parsed successfully")
6465
args.MirrorMapping = mapping
6566

6667
mirroringErrors := mirroring.MirrorGitlabs(&args)
6768
if mirroringErrors != nil {
68-
zap.L().Error("Error during mirroring process", zap.Array("errors", utils.ErrorArray(mirroringErrors)))
69+
zap.L().Error("Error during mirroring process", zap.Array("errors", helpers.ErrorArray(mirroringErrors)))
6970
}
7071
zap.L().Info("Mirroring completed")
7172
},

internal/mirroring/get.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package mirroring
33
import (
44
"fmt"
55
"gitlab-sync/internal/utils"
6+
"gitlab-sync/pkg/helpers"
67
"path/filepath"
78
"strings"
89
"sync"
@@ -39,7 +40,7 @@ func (g *GitlabInstance) fetchAll(projectFilters map[string]struct{}, groupFilte
3940
wg.Wait()
4041
close(errCh)
4142

42-
return utils.MergeErrors(errCh)
43+
return helpers.MergeErrors(errCh)
4344
}
4445

4546
// getParentNamespaceID retrieves the parent namespace ID for a given project or group path.

internal/mirroring/get_group.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package mirroring
33
import (
44
"fmt"
55
"gitlab-sync/internal/utils"
6+
"gitlab-sync/pkg/helpers"
67
"path/filepath"
78
"sync"
89

@@ -166,7 +167,7 @@ func (g *GitlabInstance) fetchAndProcessGroupsLargeInstance(groupFilters *map[st
166167
// Wait for all goroutines to finish
167168
wg.Wait()
168169
close(errChan)
169-
return utils.MergeErrors(errs)
170+
return helpers.MergeErrors(errs)
170171
}
171172

172173
// fetchAndProcessGroupRecursive fetches a group and its projects recursively

internal/mirroring/get_project.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sync"
77

88
"gitlab-sync/internal/utils"
9+
"gitlab-sync/pkg/helpers"
910

1011
gitlab "gitlab.com/gitlab-org/api/client-go"
1112
"go.uber.org/zap"
@@ -170,7 +171,7 @@ func (g *GitlabInstance) fetchAndProcessProjectsBigInstance(projectFilters *map[
170171
for project := range projectsChan {
171172
g.storeProject(project, project.PathWithNamespace, mirrorMapping)
172173
}
173-
return utils.MergeErrors(errCh)
174+
return helpers.MergeErrors(errCh)
174175
}
175176

176177
// fetchAndProcessGroupProjects retrieves all projects from the group and processes them to store in the instance cache.

internal/mirroring/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sync"
77

88
"gitlab-sync/internal/utils"
9+
"gitlab-sync/pkg/helpers"
910

1011
gitlab "gitlab.com/gitlab-org/api/client-go"
1112
"go.uber.org/zap"
@@ -80,7 +81,7 @@ func MirrorGitlabs(gitlabMirrorArgs *utils.ParserArgs) []error {
8081
errCh <- destinationGitlabInstance.createProjects(sourceGitlabInstance, gitlabMirrorArgs.MirrorMapping)
8182

8283
close(errCh)
83-
return utils.MergeErrors(errCh)
84+
return helpers.MergeErrors(errCh)
8485
}
8586

8687
// processFilters processes the filters for groups and projects.

internal/mirroring/post.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sync"
77

88
"gitlab-sync/internal/utils"
9+
"gitlab-sync/pkg/helpers"
910

1011
gitlab "gitlab.com/gitlab-org/api/client-go"
1112
"go.uber.org/zap"
@@ -33,7 +34,7 @@ func (destinationGitlab *GitlabInstance) createGroups(sourceGitlab *GitlabInstan
3334
}
3435
}
3536
close(errorChan)
36-
return utils.MergeErrors(errorChan)
37+
return helpers.MergeErrors(errorChan)
3738
}
3839

3940
// createGroup creates a GitLab group in the destination GitLab instance based on the source group and mirror mapping.
@@ -147,7 +148,7 @@ func (destinationGitlab *GitlabInstance) createProjects(sourceGitlab *GitlabInst
147148
wg.Wait()
148149
close(errorChan)
149150

150-
return utils.MergeErrors(errorChan)
151+
return helpers.MergeErrors(errorChan)
151152
}
152153

153154
// createProject creates a GitLab project in the destination GitLab instance based on the source project and mirror mapping.
@@ -285,7 +286,7 @@ func (destinationGitlab *GitlabInstance) mirrorReleases(sourceGitlab *GitlabInst
285286
close(errorChan)
286287

287288
zap.L().Info("Releases mirroring completed", zap.String(ROLE_SOURCE, sourceProject.HTTPURLToRepo), zap.String(ROLE_DESTINATION, destinationProject.HTTPURLToRepo))
288-
return utils.MergeErrors(errorChan)
289+
return helpers.MergeErrors(errorChan)
289290
}
290291

291292
// ============================================================ //

internal/mirroring/put.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"gitlab-sync/internal/utils"
9+
"gitlab-sync/pkg/helpers"
910

1011
gitlab "gitlab.com/gitlab-org/api/client-go"
1112
"go.uber.org/zap"
@@ -193,7 +194,7 @@ func (destinationGitlabInstance *GitlabInstance) updateGroupFromSource(sourceGit
193194
wg.Wait()
194195
close(errorChan)
195196

196-
return utils.MergeErrors(errorChan)
197+
return helpers.MergeErrors(errorChan)
197198
}
198199

199200
// copyGroupAvatar copies the avatar from the source group to the destination group.

internal/utils/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/json"
88
"errors"
99
"fmt"
10+
"gitlab-sync/pkg/helpers"
1011
"os"
1112
"path/filepath"
1213
"strings"
@@ -139,7 +140,7 @@ func (m *MirrorMapping) check() []error {
139140
m.checkGroups(errChan)
140141

141142
close(errChan)
142-
return MergeErrors(errChan)
143+
return helpers.MergeErrors(errChan)
143144
}
144145

145146
// checkProjects checks if the projects are valid

internal/utils/types_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package utils
22

33
import (
44
"fmt"
5+
"gitlab-sync/pkg/helpers"
56
"os"
67
"reflect"
78
"testing"
@@ -245,7 +246,7 @@ func TestCheck(t *testing.T) {
245246
for _, tt := range tests {
246247
t.Run(tt.name, func(t *testing.T) {
247248
errs := tt.mapping.check() // now returns []error
248-
got := toStrings(errs)
249+
got := helpers.ToStrings(errs)
249250
if !reflect.DeepEqual(got, tt.wantMsgs) {
250251
t.Errorf("check() = %v, want %v", got, tt.wantMsgs)
251252
}

0 commit comments

Comments
 (0)