Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable URL for self-hosted GitLab #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.

Expand Down
19 changes: 14 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:.*")
Expand Down Expand Up @@ -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
}