diff --git a/README.md b/README.md index 0182ba6..d3d2da8 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,15 @@ Migrates gitlab repositories with open merge requests from Gitlab to Azure DevOp ### Run Options -| Name | Type | Description | -| ------------------- | ----------------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `--gitlab-token` | string (**required**) | Gitlab API token with`api, write_repository` scope. Create access token [here](https://gitlab.com/-/profile/personal_access_tokens) | -| `--azdo-org` | string (**required**) | Azure DevOps organization URL`https://dev.azure.com/MYORG` | -| `--azdo-token` | string (**required**) | Azure DevOps Personal Access Token with`Code - Read, write, & manage` scope. Create one at `https://dev.azure.com/MYORG/_usersSettings/tokens` | -| `--azdo-endpoint` | string (**optional**) | Azure DevOps service endpoint for gitlab. If you're importing private repositories you need to setup service endpoint for gitlab authentication. See below for details | -| `--config` | string (**optional**) | Project configuration file - see projects.example.json or [below](#config-file) | -| `--recreate-repo` | bool (**optional**) | If added, script will first try to delete repository in AzDO before it creates a new one.**Use with caution as the action is irreversible** | +| Name | Type | Description | +| ------------------------- | --------------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `--gitlab-token` | string (**required**) | Gitlab API token with`api, write_repository` scope. Create access token [here](https://gitlab.com/-/profile/personal_access_tokens) | +| `--azdo-org` | string (**required**) | Azure DevOps organization URL`https://dev.azure.com/MYORG` | +| `--azdo-token` | string (**required**) | Azure DevOps Personal Access Token with`Code - Read, write, & manage` scope. Create one at `https://dev.azure.com/MYORG/_usersSettings/tokens` | +| `--azdo-endpoint` | string (**optional**) | Azure DevOps service endpoint for gitlab. If you're importing private repositories you need to setup service endpoint for gitlab authentication. See below for details | +| `--config` | string (**optional**) | Project configuration file - see projects.example.json or [below](#config-file) | +| `--custom-gitlab-api-url` | string (**optional**) | If specified, this will connect to a self-hosted GitLab instance instead of Gitlab.com. Format should be "https://gitlab.myorg.com/api/v4" | +| `--recreate-repo` | bool (**optional**) | If added, script will first try to delete repository in AzDO before it creates a new one.**Use with caution as the action is irreversible** | ### Service endpoint configuration @@ -44,7 +45,7 @@ If you're importing private repositories you need to configure [Service Endpoint 3. Password/Token Key `YOUR GITLAB API TOKEN` 4. Service connection name `AzDO migration` (or any other descriptive text) 6. Click Save -7. Click on your service endpoint and your identificator will be visible in the URL +7. Click on your service endpoint and your identificator will be visible in the URL. Only the UUID portion is needed. `https://dev.azure.com/MYORG/MYPROJECT/_settings/adminservices?resourceId=**SERVICE_ENDPOINT**` 8. You can remove the service endpoint once you're done importing your repositories. diff --git a/main.go b/main.go index bd921fc..89e6b70 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ var ( azdoToken = kingpin.Flag("azdo-token", "Azure DevOps Personal Access Token").Required().String() azdoServiceEndpoint = kingpin.Flag("azdo-endpoint", "Azure DevOps service endpoint for gitlab").Default("").String() configFile = kingpin.Flag("config", "Projects configuration file").Default("projects.json").String() + customGitlabApiUrl = kingpin.Flag("custom-gitlab-api-url", "Self-Hosted GitLab instance. If specified, this will connect to a self-hosted GitLab instance instead of GitLab.com").Default("").String() recreateRepository = kingpin.Flag("recreate-repo", "If true, repository in azdo will be deleted first and created again. Use with caution").Default("false").Bool() //SuggestionReplacer Regex to match gitlab suggestion schema so that it can be replaced to azdo schema SuggestionReplacer = regexp.MustCompile("```suggestion:.*") @@ -429,9 +430,17 @@ func initAzdo() (context.Context, git.Client) { } func initGitlab() *gitlab.Client { - gitlabClient, err := gitlab.NewClient(*gitlabToken) - if err != nil { - log.Fatal(err) + if *customGitlabApiUrl == "" { + gitlabClient, err := gitlab.NewClient(*gitlabToken) + if err != nil { + log.Fatal(err) + } + return gitlabClient } - return gitlabClient -} + + gitlabClientCustom, errCustom := gitlab.NewClient(*gitlabToken, gitlab.WithBaseURL(*customGitlabApiUrl)) + if errCustom != nil { + log.Fatal(errCustom) + } + return gitlabClientCustom +} \ No newline at end of file