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
14 changes: 8 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: lint-test

on:
workflow_dispatch:
push:
pull_request:

permissions:
Expand All @@ -17,12 +16,13 @@ jobs:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: "1.24.2"
go-version: "1.24.4"
- run: go mod tidy
- name: golangci-lint
uses: golangci/golangci-lint-action@v7
uses: golangci/golangci-lint-action@v8
with:
version: v2.0
version: latest
args: --tests=false
continue-on-error: true

gosec:
Expand All @@ -35,7 +35,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: "1.24.2"
go-version: "1.24.4"
- run: go mod tidy
- name: Run Gosec Security Scanner
uses: securego/gosec@master
Expand All @@ -47,9 +47,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: "1.24.2"
go-version: "1.24.4"
- run: go mod tidy
- run: go install gotest.tools/gotestsum@latest
- run: gotestsum --junitfile unit-tests.xml -- -coverprofile=coverage.out -covermode=atomic ./...
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ sonar-project.properties
unit-tests.xml
coverage.out
.scannerwork/
*-report*
.sonarlint/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ It is designed to be used in a CI/CD pipeline to automate the process of keeping
## Features

- Synchronize projects / groups between two GitLab instances
- Enable Pull Mirroring for projects (requires GitLab Premium)
- Recreates your git repository content in another location:
- Enable Pull Mirroring for projects (requires GitLab Premium)
- Clone the repository content from the source GitLab instance to the destination GitLab instance (on GitLab Free)
- Can add projects to CI/CD catalog
- Full copy of the project (description, icon, topics,...). Can also copy issues

Expand Down
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func main() {
rootCmd.Flags().StringVar(&args.DestinationGitlabURL, "destination-url", os.Getenv("DESTINATION_GITLAB_URL"), "Destination GitLab URL")
rootCmd.Flags().StringVar(&args.DestinationGitlabToken, "destination-token", os.Getenv("DESTINATION_GITLAB_TOKEN"), "Destination GitLab Token")
rootCmd.Flags().BoolVar(&args.DestinationGitlabIsBig, "destination-big", strings.TrimSpace(os.Getenv("DESTINATION_GITLAB_BIG")) != "", "Destination GitLab is a big instance")
rootCmd.Flags().BoolVarP(&args.ForcePremium, "destination-force-premium", "p", false, "Force the destination GitLab to be treated as a premium instance")
rootCmd.Flags().BoolVarP(&args.ForceNonPremium, "destination-force-freemium", "f", false, "Force the destination GitLab to be treated as a non premium instance")
rootCmd.Flags().BoolVarP(&args.Verbose, "verbose", "v", false, "Enable verbose output")
rootCmd.Flags().BoolVarP(&args.NoPrompt, "no-prompt", "n", strings.TrimSpace(os.Getenv("NO_PROMPT")) != "", "Disable prompting for missing values")
rootCmd.Flags().StringVar(&mirrorMappingPath, "mirror-mapping", os.Getenv("MIRROR_MAPPING"), "Path to the mirror mapping file")
Expand Down
30 changes: 25 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
module gitlab-sync

go 1.24.3
go 1.24.4

require (
github.com/Masterminds/semver/v3 v3.3.1
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/Masterminds/semver/v3 v3.4.0
github.com/go-git/go-git/v5 v5.16.2
github.com/hashicorp/go-retryablehttp v0.7.8
github.com/spf13/cobra v1.9.1
gitlab.com/gitlab-org/api/client-go v0.128.0
gitlab.com/gitlab-org/api/client-go v0.134.0
go.uber.org/zap v1.27.0
)

require (
dario.cat/mergo v1.0.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.3.0 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/pjbgf/sha1cd v0.4.0 // indirect
github.com/sergi/go-diff v1.4.0 // indirect
github.com/skeema/knownhosts v1.3.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.40.0 // indirect
golang.org/x/net v0.42.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/time v0.11.0 // indirect
golang.org/x/sys v0.34.0 // indirect
golang.org/x/time v0.12.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
33 changes: 16 additions & 17 deletions internal/mirroring/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,38 @@ func checkPathMatchesFilters(resourcePath string, projectFilters *map[string]str
return "", false
}

func (g *GitlabInstance) CheckVersion() error {
// IsVersionGreaterThanThreshold checks if the GitLab instance version is below the defined threshold.
// It retrieves the metadata from the GitLab instance and compares the version
// with the INSTANCE_SEMVER_THRESHOLD.
func (g *GitlabInstance) IsVersionGreaterThanThreshold() (bool, error) {
metadata, _, err := g.Gitlab.Metadata.GetMetadata()
if err != nil {
return fmt.Errorf("failed to get GitLab version: %w", err)
return false, fmt.Errorf("failed to get GitLab version: %w", err)
}
zap.L().Debug("GitLab Instance version", zap.String(ROLE, g.Role), zap.String("version", metadata.Version))

currentVer, err := semver.NewVersion(metadata.Version)
if err != nil {
return fmt.Errorf("failed to parse GitLab version: %w", err)
return false, fmt.Errorf("failed to parse GitLab version: %w", err)
}
thresholdVer, err := semver.NewVersion(INSTANCE_SEMVER_THRESHOLD)
if err != nil {
return fmt.Errorf("failed to parse version threshold: %w", err)
return false, fmt.Errorf("failed to parse version threshold: %w", err)
}

if currentVer.LessThan(thresholdVer) {
return fmt.Errorf("GitLab version %s is below required threshold %s", currentVer, thresholdVer)
}
return nil
return currentVer.GreaterThanEqual(thresholdVer), nil
}

func (g *GitlabInstance) CheckLicense() error {
// IsLicensePremium checks if the GitLab instance has a premium license.
// It retrieves the license information and checks the plan type.
func (g *GitlabInstance) IsLicensePremium() (bool, error) {
license, _, err := g.Gitlab.License.GetLicense()
if err != nil {
return fmt.Errorf("failed to get GitLab license: %w", err)
return false, fmt.Errorf("failed to get GitLab license: %w", err)
}
if license.Plan != ULTIMATE_PLAN && license.Plan != PREMIUM_PLAN {
return fmt.Errorf("GitLab license plan %s is not supported, only %s and %s are supported", license.Plan, ULTIMATE_PLAN, PREMIUM_PLAN)
} else if license.Expired {
return fmt.Errorf("GitLab license is expired")
zap.L().Info("GitLab Instance license", zap.String(ROLE, g.Role), zap.String("plan", license.Plan))
if license.Plan != ULTIMATE_PLAN && license.Plan != PREMIUM_PLAN || license.Expired {
return false, nil
}

zap.L().Debug("GitLab Instance license", zap.String(ROLE, g.Role), zap.String("plan", license.Plan))
return nil
return true, nil
}
4 changes: 2 additions & 2 deletions internal/mirroring/get_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (g *GitlabInstance) fetchAndProcessGroupRecursive(gid any, fetchOriginPath
}
if group != nil {
g.storeGroup(group, fetchOriginPath, mirrorMapping)
if g.isSource() {
if g.isSource() || g.isBig() {
wg.Add(2)
// Fetch the projects of the group
go g.fetchAndProcessGroupProjects(group, fetchOriginPath, mirrorMapping, errChan, wg)
Expand Down Expand Up @@ -225,7 +225,7 @@ func (g *GitlabInstance) fetchAndProcessGroupSubgroups(group *gitlab.Group, fetc
}
for _, subgroup := range subgroups {
g.storeGroup(subgroup, fetchOriginPath, mirrorMapping)
if g.isSource() {
if g.isSource() || g.isBig() {
wg.Add(1)
go g.fetchAndProcessGroupRecursive(subgroup, fetchOriginPath, mirrorMapping, errChan, wg)
}
Expand Down
Loading
Loading