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

Commit

Permalink
fix projectPathFromArgs
Browse files Browse the repository at this point in the history
This ensures supoport for

- ssh urls
- urls with .git prefix
- respect hostname in url provided
  • Loading branch information
profclems committed May 11, 2021
1 parent 4e9ff3a commit 84844a7
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions commands/project/create/project_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/profclems/glab/pkg/prompt"

"github.com/profclems/glab/api"
"github.com/profclems/glab/internal/glinstance"
"github.com/profclems/glab/internal/glrepo"

"github.com/MakeNowJust/heredoc"
Expand Down Expand Up @@ -86,7 +85,12 @@ func runCreateProject(cmd *cobra.Command, args []string, f *cmdutils.Factory) er
var host string
host, namespace, projectPath = projectPathFromArgs(args)
if host != "" {
glinstance.OverrideDefault(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 {
Expand Down Expand Up @@ -262,21 +266,12 @@ func initialiseRepo(projectPath, remoteURL string) error {
}

func projectPathFromArgs(args []string) (host, namespace, project string) {
pathURL, err := url.Parse(args[0])
if err == nil {
host = pathURL.Host
pp := strings.Split(pathURL.Path, "/")
if len(pp) >= 3 {
project = pp[len(pp)-1]
namespace = strings.Join(pp[1:len(pp)-1], "/")
}
return
}
project = args[0]
if strings.Contains(project, "/") {
pp := strings.Split(project, "/")
project = pp[1]
namespace = pp[0]
pp, _ := glrepo.FromFullName(project)
host = pp.RepoHost()
project = pp.RepoName()
namespace = pp.RepoNamespace()
}
return
}

0 comments on commit 84844a7

Please sign in to comment.