Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #709 from zemzale/feat-create-project-from-url
Browse files Browse the repository at this point in the history
feat(repo): Create project from URL
  • Loading branch information
profclems authored May 11, 2021
2 parents a17c562 + 84844a7 commit 33450b8
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions commands/project/create/project_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,28 @@ func runCreateProject(cmd *cobra.Command, args []string, f *cmdutils.Factory) er
if err != nil {
return err
}
apiClient, err := f.HttpClient()
if err != nil {
return err
}

if len(args) == 1 {
projectPath = args[0]
if strings.Contains(projectPath, "/") {
pp := strings.Split(projectPath, "/")
projectPath = pp[1]
namespace = pp[0]
var host string
host, namespace, projectPath = projectPathFromArgs(args)
if host != "" {
cfg, _ := f.Config()
client, err := api.NewClientWithCfg(host, cfg, false)
if err != nil {
return err
}
apiClient = client.Lab()
}
user, err := api.CurrentUser(apiClient)
if err != nil {
return err
}
if user.Username == namespace {
namespace = ""
}
} else {
projectPath, err = git.ToplevelDir()
Expand All @@ -93,11 +108,6 @@ func runCreateProject(cmd *cobra.Command, args []string, f *cmdutils.Factory) er
isPath = true
}

apiClient, err := f.HttpClient()
if err != nil {
return err
}

group, err := cmd.Flags().GetString("group")
if err != nil {
return fmt.Errorf("could not parse group flag: %v", err)
Expand Down Expand Up @@ -254,3 +264,14 @@ func initialiseRepo(projectPath, remoteURL string) error {
}
return nil
}

func projectPathFromArgs(args []string) (host, namespace, project string) {
project = args[0]
if strings.Contains(project, "/") {
pp, _ := glrepo.FromFullName(project)
host = pp.RepoHost()
project = pp.RepoName()
namespace = pp.RepoNamespace()
}
return
}

0 comments on commit 33450b8

Please sign in to comment.