Skip to content

Commit

Permalink
Merge branch 'gitremote-parts' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridai Govinda Pombo committed Nov 20, 2019
2 parents 633cfd0 + 7f08dae commit 5414620
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions types/gitremote.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type GitRemote struct {
Password string
Domain string
Path string
Org string
Project string
Branch string
Type RemoteType
}
Expand All @@ -31,6 +33,14 @@ func NewGitRemote(url string) (r GitRemote) {
r.Url = url
r.Token, r.User, r.Password, r.Domain, r.Path, r.Protocol, r.Type = parseRemote(url)

// NOTE maybe too GH centric:
pathParts := strings.Split(r.Path, "/")
r.Org = pathParts[0]
if len(pathParts) > 1 {
project := pathParts[1]
r.Project = strings.Replace(project, ".git", "", -1)
}

return
}

Expand Down
24 changes: 24 additions & 0 deletions types/gitremote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ func TestGitRemoteParse(t *testing.T) {
token string
user string
password string
project string
org string
valid bool
rType RemoteType
}{
Expand All @@ -20,6 +22,8 @@ func TestGitRemoteParse(t *testing.T) {
user: "x-access-token",
password: "X86jsl",
valid: true,
project: "spankpay",
org: "SpankChain",
rType: HttpsRemote,
},
{
Expand All @@ -28,6 +32,8 @@ func TestGitRemoteParse(t *testing.T) {
user: "x-access-token",
password: "token",
valid: true,
project: "godif",
org: "beholders-eye",
rType: HttpsRemote,
},
{
Expand All @@ -36,6 +42,8 @@ func TestGitRemoteParse(t *testing.T) {
user: "x-access-token",
password: "token",
valid: true,
project: "t",
org: "something",
rType: HttpsRemote,
},
{
Expand All @@ -49,6 +57,8 @@ func TestGitRemoteParse(t *testing.T) {
user: "x-access-token",
password: "token",
valid: true,
project: "spankpay",
org: "SpankChain",
rType: HttpRemote,
},
{
Expand All @@ -74,13 +84,17 @@ func TestGitRemoteParse(t *testing.T) {
user: "git",
password: "",
valid: true,
project: "ybdocs",
org: "yourbase",
rType: SshRemote,
},
{
in: "git:[email protected]:something/where",
token: "",
user: "git",
password: "calhamba",
project: "where",
org: "something",
valid: true,
rType: SshRemote,
},
Expand All @@ -90,6 +104,8 @@ func TestGitRemoteParse(t *testing.T) {
user: "git",
password: "",
valid: true,
project: "where",
org: "something",
rType: SshRemote,
},
} {
Expand All @@ -114,5 +130,13 @@ func TestGitRemoteParse(t *testing.T) {
if l.rType != got.Type {
t.Errorf("Password: got: '%v' wanted: '%v'", got.Type, l.rType)
}

if l.project != got.Project {
t.Errorf("Project: got: '%v' wanted: '%v'", got.Project, l.project)
}

if l.org != got.Org {
t.Errorf("Org: got: '%v' wanted: '%v'", got.Org, l.org)
}
}
}

0 comments on commit 5414620

Please sign in to comment.