Skip to content

Commit

Permalink
Recognize clone addr to service type
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Dec 27, 2020
1 parent ceefd98 commit 695d23e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
26 changes: 23 additions & 3 deletions cmd/dump_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ package cmd

import (
"context"
"errors"
"strings"

"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/log"
"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"
)
Expand All @@ -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",
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/usage/command-line.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 695d23e

Please sign in to comment.