diff --git a/types/gitremote.go b/types/gitremote.go index 224b2aa7..70d6c14d 100644 --- a/types/gitremote.go +++ b/types/gitremote.go @@ -23,6 +23,8 @@ type GitRemote struct { Password string Domain string Path string + Org string + Project string Branch string Type RemoteType } @@ -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 } diff --git a/types/gitremote_test.go b/types/gitremote_test.go index 7c750b03..395c7a34 100644 --- a/types/gitremote_test.go +++ b/types/gitremote_test.go @@ -11,6 +11,8 @@ func TestGitRemoteParse(t *testing.T) { token string user string password string + project string + org string valid bool rType RemoteType }{ @@ -20,6 +22,8 @@ func TestGitRemoteParse(t *testing.T) { user: "x-access-token", password: "X86jsl", valid: true, + project: "spankpay", + org: "SpankChain", rType: HttpsRemote, }, { @@ -28,6 +32,8 @@ func TestGitRemoteParse(t *testing.T) { user: "x-access-token", password: "token", valid: true, + project: "godif", + org: "beholders-eye", rType: HttpsRemote, }, { @@ -36,6 +42,8 @@ func TestGitRemoteParse(t *testing.T) { user: "x-access-token", password: "token", valid: true, + project: "t", + org: "something", rType: HttpsRemote, }, { @@ -49,6 +57,8 @@ func TestGitRemoteParse(t *testing.T) { user: "x-access-token", password: "token", valid: true, + project: "spankpay", + org: "SpankChain", rType: HttpRemote, }, { @@ -74,6 +84,8 @@ func TestGitRemoteParse(t *testing.T) { user: "git", password: "", valid: true, + project: "ybdocs", + org: "yourbase", rType: SshRemote, }, { @@ -81,6 +93,8 @@ func TestGitRemoteParse(t *testing.T) { token: "", user: "git", password: "calhamba", + project: "where", + org: "something", valid: true, rType: SshRemote, }, @@ -90,6 +104,8 @@ func TestGitRemoteParse(t *testing.T) { user: "git", password: "", valid: true, + project: "where", + org: "something", rType: SshRemote, }, } { @@ -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) + } } }