Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ go.sum
sonar-project.properties
unit-tests.xml
coverage.out
republisher.sh
5 changes: 3 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"gitlab-sync/internal/mirroring"
"gitlab-sync/internal/utils"
"gitlab-sync/pkg/helpers"

"github.com/spf13/cobra"
"go.uber.org/zap"
Expand Down Expand Up @@ -58,14 +59,14 @@ func main() {
zap.L().Debug("Parsing mirror mapping file")
mapping, mappingErrors := utils.OpenMirrorMapping(mirrorMappingPath)
if mappingErrors != nil {
zap.L().Fatal("Error opening mirror mapping file", zap.Array("errors", utils.ErrorArray(mappingErrors)))
zap.L().Fatal("Error opening mirror mapping file", zap.Array("errors", helpers.ErrorArray(mappingErrors)))
}
zap.L().Debug("Mirror mapping file parsed successfully")
args.MirrorMapping = mapping

mirroringErrors := mirroring.MirrorGitlabs(&args)
if mirroringErrors != nil {
zap.L().Error("Error during mirroring process", zap.Array("errors", utils.ErrorArray(mirroringErrors)))
zap.L().Error("Error during mirroring process", zap.Array("errors", helpers.ErrorArray(mirroringErrors)))
}
zap.L().Info("Mirroring completed")
},
Expand Down
3 changes: 2 additions & 1 deletion internal/mirroring/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mirroring
import (
"fmt"
"gitlab-sync/internal/utils"
"gitlab-sync/pkg/helpers"
"path/filepath"
"strings"
"sync"
Expand Down Expand Up @@ -39,7 +40,7 @@ func (g *GitlabInstance) fetchAll(projectFilters map[string]struct{}, groupFilte
wg.Wait()
close(errCh)

return utils.MergeErrors(errCh)
return helpers.MergeErrors(errCh)
}

// getParentNamespaceID retrieves the parent namespace ID for a given project or group path.
Expand Down
3 changes: 2 additions & 1 deletion internal/mirroring/get_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mirroring
import (
"fmt"
"gitlab-sync/internal/utils"
"gitlab-sync/pkg/helpers"
"path/filepath"
"sync"

Expand Down Expand Up @@ -166,7 +167,7 @@ func (g *GitlabInstance) fetchAndProcessGroupsLargeInstance(groupFilters *map[st
// Wait for all goroutines to finish
wg.Wait()
close(errChan)
return utils.MergeErrors(errs)
return helpers.MergeErrors(errs)
}

// fetchAndProcessGroupRecursive fetches a group and its projects recursively
Expand Down
3 changes: 2 additions & 1 deletion internal/mirroring/get_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"

"gitlab-sync/internal/utils"
"gitlab-sync/pkg/helpers"

gitlab "gitlab.com/gitlab-org/api/client-go"
"go.uber.org/zap"
Expand Down Expand Up @@ -170,7 +171,7 @@ func (g *GitlabInstance) fetchAndProcessProjectsBigInstance(projectFilters *map[
for project := range projectsChan {
g.storeProject(project, project.PathWithNamespace, mirrorMapping)
}
return utils.MergeErrors(errCh)
return helpers.MergeErrors(errCh)
}

// fetchAndProcessGroupProjects retrieves all projects from the group and processes them to store in the instance cache.
Expand Down
3 changes: 2 additions & 1 deletion internal/mirroring/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"

"gitlab-sync/internal/utils"
"gitlab-sync/pkg/helpers"

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

close(errCh)
return utils.MergeErrors(errCh)
return helpers.MergeErrors(errCh)
}

// processFilters processes the filters for groups and projects.
Expand Down
7 changes: 4 additions & 3 deletions internal/mirroring/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"

"gitlab-sync/internal/utils"
"gitlab-sync/pkg/helpers"

gitlab "gitlab.com/gitlab-org/api/client-go"
"go.uber.org/zap"
Expand Down Expand Up @@ -33,7 +34,7 @@ func (destinationGitlab *GitlabInstance) createGroups(sourceGitlab *GitlabInstan
}
}
close(errorChan)
return utils.MergeErrors(errorChan)
return helpers.MergeErrors(errorChan)
}

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

return utils.MergeErrors(errorChan)
return helpers.MergeErrors(errorChan)
}

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

zap.L().Info("Releases mirroring completed", zap.String(ROLE_SOURCE, sourceProject.HTTPURLToRepo), zap.String(ROLE_DESTINATION, destinationProject.HTTPURLToRepo))
return utils.MergeErrors(errorChan)
return helpers.MergeErrors(errorChan)
}

// ============================================================ //
Expand Down
5 changes: 3 additions & 2 deletions internal/mirroring/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"gitlab-sync/internal/utils"
"gitlab-sync/pkg/helpers"

gitlab "gitlab.com/gitlab-org/api/client-go"
"go.uber.org/zap"
Expand Down Expand Up @@ -112,7 +113,7 @@ func (destinationGitlabInstance *GitlabInstance) syncProjectAttributes(sourcePro
}

if missmatched {
destinationProject, _, err := destinationGitlabInstance.Gitlab.Projects.EditProject(destinationProject.ID, gitlabEditOptions)
_, _, err := destinationGitlabInstance.Gitlab.Projects.EditProject(destinationProject.ID, gitlabEditOptions)
if err != nil {
return fmt.Errorf("failed to edit project %s: %s", destinationProject.HTTPURLToRepo, err)
}
Expand Down Expand Up @@ -193,7 +194,7 @@ func (destinationGitlabInstance *GitlabInstance) updateGroupFromSource(sourceGit
wg.Wait()
close(errorChan)

return utils.MergeErrors(errorChan)
return helpers.MergeErrors(errorChan)
}

// copyGroupAvatar copies the avatar from the source group to the destination group.
Expand Down
3 changes: 2 additions & 1 deletion internal/utils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"gitlab-sync/pkg/helpers"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -139,7 +140,7 @@ func (m *MirrorMapping) check() []error {
m.checkGroups(errChan)

close(errChan)
return MergeErrors(errChan)
return helpers.MergeErrors(errChan)
}

// checkProjects checks if the projects are valid
Expand Down
3 changes: 2 additions & 1 deletion internal/utils/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"fmt"
"gitlab-sync/pkg/helpers"
"os"
"reflect"
"testing"
Expand Down Expand Up @@ -245,7 +246,7 @@ func TestCheck(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
errs := tt.mapping.check() // now returns []error
got := toStrings(errs)
got := helpers.ToStrings(errs)
if !reflect.DeepEqual(got, tt.wantMsgs) {
t.Errorf("check() = %v, want %v", got, tt.wantMsgs)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package helpers

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package helpers

import (
"errors"
Expand All @@ -15,18 +15,6 @@ const (
EXPECT_NIL_GOT_MESSAGE = "Expected nil, Got: %q"
)

// toStrings converts a []error into a []string for easy comparison
func toStrings(errs []error) []string {
if errs == nil {
return nil
}
out := make([]string, len(errs))
for i, e := range errs {
out[i] = e.Error()
}
return out
}

func TestMergeErrors(t *testing.T) {
type args struct {
// factory builds the argument to pass into MergeErrors
Expand Down Expand Up @@ -171,7 +159,7 @@ func TestMergeErrors(t *testing.T) {
}
return
}
got := toStrings(gotErrs)
got := ToStrings(gotErrs)
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("got %v, want %v", got, tc.want)
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/helpers/formats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package helpers

// toStrings converts a []error into a []string for easy comparison
func ToStrings(errs []error) []string {
if errs == nil {
return nil
}
out := make([]string, len(errs))
for i, e := range errs {
out[i] = e.Error()
}
return out
}
Loading