From b4a85e3d4196b41fefdcf2e377444edc937dc1f6 Mon Sep 17 00:00:00 2001 From: Zak Siddiqui Date: Thu, 25 Apr 2024 19:44:01 +1000 Subject: [PATCH 1/4] Added documentation for --custom-gitlab-api-url --- README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index 0182ba6..b59e51c 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,7 @@ 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** | +| `--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" | ### Service endpoint configuration From bf5fb971e7083e2e7db6218c38d2d185eb4fddc2 Mon Sep 17 00:00:00 2001 From: Zak Siddiqui Date: Thu, 25 Apr 2024 19:44:21 +1000 Subject: [PATCH 2/4] Clean up markdown table --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index b59e51c..7ce9596 100644 --- a/README.md +++ b/README.md @@ -21,7 +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) | | `--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 From e513d4b930484d93f37fee1430f0797306485698 Mon Sep 17 00:00:00 2001 From: Zak Siddiqui Date: Thu, 25 Apr 2024 19:44:48 +1000 Subject: [PATCH 3/4] Add clarity in README.md for the service endpoint --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ce9596..d3d2da8 100644 --- a/README.md +++ b/README.md @@ -45,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. From 0783985c2209e4ae77ca423bc92c352c7c62f805 Mon Sep 17 00:00:00 2001 From: Zak Siddiqui Date: Thu, 25 Apr 2024 19:44:56 +1000 Subject: [PATCH 4/4] Enable customGitlabApiUrl --- main.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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