From 695d23e56a9626adccf3f0a369dc5472757c49c7 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 27 Dec 2020 10:15:12 +0800 Subject: [PATCH] Recognize clone addr to service type --- cmd/dump_repo.go | 26 +++++++++++++++++--- docs/content/doc/usage/command-line.en-us.md | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cmd/dump_repo.go b/cmd/dump_repo.go index ee038b6392ee8..cea640b53438d 100644 --- a/cmd/dump_repo.go +++ b/cmd/dump_repo.go @@ -6,6 +6,7 @@ package cmd import ( "context" + "errors" "strings" "code.gitea.io/gitea/modules/convert" @@ -13,6 +14,7 @@ import ( "code.gitea.io/gitea/modules/migrations" "code.gitea.io/gitea/modules/migrations/base" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/structs" "github.com/urfave/cli" ) @@ -27,7 +29,7 @@ var CmdDumpRepository = cli.Command{ cli.StringFlag{ Name: "git_service", Value: "", - Usage: "Git service, git, github, gitea, gitlab", + Usage: "Git service, git, github, gitea, gitlab. If clone_addr could be recognized, this could be ignored.", }, cli.StringFlag{ Name: "repo_dir, r", @@ -84,9 +86,27 @@ func runDumpRepository(ctx *cli.Context) error { log.Trace("Log path: %s", setting.LogRootPath) setting.InitDBConfig() + var ( + serviceType structs.GitServiceType + cloneAddr = ctx.String("clone_addr") + serviceStr = ctx.String("git_service") + ) + + if strings.HasPrefix(strings.ToLower(cloneAddr), "https://github.com/") { + serviceStr = "github" + } else if strings.HasPrefix(strings.ToLower(cloneAddr), "https://gitlab.com/") { + serviceStr = "gitlab" + } else if strings.HasPrefix(strings.ToLower(cloneAddr), "https://gitea.com/") { + serviceStr = "gitea" + } + if serviceStr == "" { + return errors.New("git_service missed or clone_addr cannot be recognized") + } + serviceType = convert.ToGitServiceType(serviceStr) + var opts = base.MigrateOptions{ - GitServiceType: convert.ToGitServiceType(ctx.String("git_service")), - CloneAddr: ctx.String("clone_addr"), + GitServiceType: serviceType, + CloneAddr: cloneAddr, AuthUsername: ctx.String("auth_username"), AuthPassword: ctx.String("auth_password"), AuthToken: ctx.String("auth_token"), diff --git a/docs/content/doc/usage/command-line.en-us.md b/docs/content/doc/usage/command-line.en-us.md index 05b8dee6e5e4c..98d047fb489e6 100644 --- a/docs/content/doc/usage/command-line.en-us.md +++ b/docs/content/doc/usage/command-line.en-us.md @@ -447,7 +447,7 @@ Manage running server operations: Dump-repo dumps repository data from git/github/gitea/gitlab: - Options: - - `--git_service service` : Git service, it could be `git`, `github`, `gitea`, `gitlab` + - `--git_service service` : Git service, it could be `git`, `github`, `gitea`, `gitlab`, If clone_addr could be recognized, this could be ignored. - `--repo_dir dir`, `-r dir`: Repository dir path to store the data - `--clone_addr addr`: The URL will be clone, currently could be a git/github/gitea/gitlab http/https URL. i.e. https://github.com/lunny/tango.git - `--auth_username lunny`: The username to visit the clone_addr