Skip to content
Closed
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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ require (
github.com/posthog/posthog-go v1.4.10
github.com/samber/lo v1.52.0
github.com/urfave/cli v1.22.16
github.com/whilp/git-urls v1.0.0
github.com/yuin/gopher-lua v1.1.1
gitlab.com/gitlab-org/api/client-go v0.128.0
golang.org/x/crypto v0.48.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,6 @@ github.com/vmihailenco/msgpack/v4 v4.3.13 h1:A2wsiTbvp63ilDaWmsk2wjx6xZdxQOvpiNl
github.com/vmihailenco/msgpack/v4 v4.3.13/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vbd1qPqc=
github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/whilp/git-urls v1.0.0 h1:95f6UMWN5FKW71ECsXRUd3FVYiXdrE7aX4NZKcPmIjU=
github.com/whilp/git-urls v1.0.0/go.mod h1:J16SAmobsqc3Qcy98brfl5f5+e0clUvg1krgwk/qCfE=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
Expand Down
26 changes: 17 additions & 9 deletions pkg/up/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package up

import (
"fmt"
"net/url"
"os"
"path/filepath"
"regexp"
Expand All @@ -18,7 +19,6 @@ import (
"github.com/pluralsh/plural-cli/pkg/utils/git"

"github.com/mitchellh/go-homedir"
giturls "github.com/whilp/git-urls"
)

type Context struct {
Expand Down Expand Up @@ -48,7 +48,7 @@ func (c *Context) identifier() string {
}

if strings.HasPrefix(c.RepoUrl, "http") {
parsed, err := giturls.Parse(c.RepoUrl)
parsed, err := url.Parse(c.RepoUrl)
if err == nil {
return strings.TrimSuffix(strings.TrimPrefix(parsed.Path, "/"), ".git")
}
Expand Down Expand Up @@ -274,18 +274,26 @@ var (
scpSyntax = regexp.MustCompile(`^([a-zA-Z0-9-._~]+@)?([a-zA-Z0-9._-]+):([a-zA-Z0-9./._-]+)(?:\?||$)(.*)$`)
)

func getGitUsername(url string) string {
match := scpSyntax.FindAllStringSubmatch(url, -1)
func getGitUsername(gitURL string) string {
// Try SCP-like syntax first (e.g., git@github.com:user/repo.git)
match := scpSyntax.FindAllStringSubmatch(gitURL, -1)
if len(match) > 0 {
if match[0][1] != "" {
return strings.TrimRight(match[0][1], "@")
}
}

uname := "git"
parsedUrl, err := giturls.Parse(url)
if err == nil {
uname = parsedUrl.User.Username()
// Try parsing as a standard URL (HTTP/HTTPS/SSH)
parsedURL, err := url.Parse(gitURL)
if err == nil && parsedURL.User != nil {
return parsedURL.User.Username()
}
return uname

// For ssh:// URLs without explicit user or unparseable URLs, default to "git"
if err == nil && parsedURL.Scheme == "ssh" {
return "git"
}

// For other URLs (HTTPS without user), return empty string
return ""
}
Loading