Release (#415)
fix: parse dates without timezone offset (#404) fix: enable replying if tree is in a different tab (#407) fix: wrong get url (#413) fix: Restore cursor when updating from outside of tree (#406) --------- Co-authored-by: Jakub F. Bortlík <jakub.bortlik@proton.me> Co-authored-by: Oscar <oscar.creator13@gmail.com>
This commit is contained in:
committed by
GitHub
parent
341d56a1cb
commit
30daecfb60
@@ -36,7 +36,7 @@ Extracts information about the current repository and returns
|
||||
it to the client for initialization. The current directory must be a valid
|
||||
Gitlab project and the branch must be a feature branch
|
||||
*/
|
||||
func NewGitData(remote string, g GitManager) (GitData, error) {
|
||||
func NewGitData(remote string, gitlabUrl string, g GitManager) (GitData, error) {
|
||||
err := g.RefreshProjectInfo(remote)
|
||||
if err != nil {
|
||||
return GitData{}, fmt.Errorf("could not get latest information from remote: %v", err)
|
||||
@@ -65,7 +65,14 @@ func NewGitData(remote string, g GitManager) (GitData, error) {
|
||||
return GitData{}, fmt.Errorf("invalid git URL format: %s", url)
|
||||
}
|
||||
|
||||
namespace := matches[1]
|
||||
// remove part of the hostname from the parsed namespace
|
||||
url_re := regexp.MustCompile(`[^\/]\/([^\/].*)$`)
|
||||
url_matches := url_re.FindStringSubmatch(gitlabUrl)
|
||||
var namespace string = matches[1]
|
||||
if len(url_matches) == 2 {
|
||||
namespace = strings.TrimLeft(strings.TrimPrefix(namespace, url_matches[1]), "/")
|
||||
}
|
||||
|
||||
projectName := matches[2]
|
||||
|
||||
branchName, err := g.GetCurrentBranchNameFromNativeGitCmd()
|
||||
|
||||
@@ -30,6 +30,7 @@ func (f FakeGitManager) GetProjectUrlFromNativeGitCmd(string) (url string, err e
|
||||
|
||||
type TestCase struct {
|
||||
desc string
|
||||
url string
|
||||
branch string
|
||||
projectName string
|
||||
namespace string
|
||||
@@ -40,6 +41,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
testCases := []TestCase{
|
||||
{
|
||||
desc: "Project configured in SSH under a single folder",
|
||||
url: "git@custom-gitlab.com",
|
||||
remote: "git@custom-gitlab.com:namespace-1/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -47,6 +49,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in SSH under a single folder without .git extension",
|
||||
url: "git@custom-gitlab.com",
|
||||
remote: "git@custom-gitlab.com:namespace-1/project-name",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -54,6 +57,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in SSH under one nested folder",
|
||||
url: "git@custom-gitlab.com",
|
||||
remote: "git@custom-gitlab.com:namespace-1/namespace-2/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -61,6 +65,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in SSH under two nested folders",
|
||||
url: "git@custom-gitlab.com",
|
||||
remote: "git@custom-gitlab.com:namespace-1/namespace-2/namespace-3/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -68,6 +73,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in SSH:// under a single folder",
|
||||
url: "ssh://custom-gitlab.com",
|
||||
remote: "ssh://custom-gitlab.com/namespace-1/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -75,6 +81,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in SSH:// under a single folder without .git extension",
|
||||
url: "ssh://custom-gitlab.com",
|
||||
remote: "ssh://custom-gitlab.com/namespace-1/project-name",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -82,6 +89,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in SSH:// under two nested folders",
|
||||
url: "ssh://custom-gitlab.com",
|
||||
remote: "ssh://custom-gitlab.com/namespace-1/namespace-2/namespace-3/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -89,13 +97,23 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in SSH:// and have a custom port",
|
||||
url: "ssh://custom-gitlab.com",
|
||||
remote: "ssh://custom-gitlab.com:2222/namespace-1/project-name",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
namespace: "namespace-1",
|
||||
},
|
||||
{
|
||||
desc: "Project configured in SSH:// and have a custom port (with gitlab url namespace)",
|
||||
url: "ssh://custom-gitlab.com/a",
|
||||
remote: "ssh://custom-gitlab.com:2222/a/namespace-1/project-name",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
namespace: "namespace-1",
|
||||
},
|
||||
{
|
||||
desc: "Project configured in HTTP and under a single folder without .git extension",
|
||||
url: "http://custom-gitlab.com",
|
||||
remote: "http://custom-gitlab.com/namespace-1/project-name",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -103,6 +121,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in HTTP and under a single folder without .git extension (with embedded credentials)",
|
||||
url: "http://custom-gitlab.com",
|
||||
remote: "http://username:password@custom-gitlab.com/namespace-1/project-name",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -110,6 +129,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in HTTPS and under a single folder",
|
||||
url: "https://custom-gitlab.com",
|
||||
remote: "https://custom-gitlab.com/namespace-1/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -117,6 +137,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in HTTPS and under a single folder (with embedded credentials)",
|
||||
url: "https://custom-gitlab.com",
|
||||
remote: "https://username:password@custom-gitlab.com/namespace-1/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -124,6 +145,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in HTTPS and under a nested folder",
|
||||
url: "https://custom-gitlab.com",
|
||||
remote: "https://custom-gitlab.com/namespace-1/namespace-2/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -131,6 +153,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in HTTPS and under a nested folder (with embedded credentials)",
|
||||
url: "https://custom-gitlab.com",
|
||||
remote: "https://username:password@custom-gitlab.com/namespace-1/namespace-2/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -138,6 +161,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in HTTPS and under two nested folders",
|
||||
url: "https://custom-gitlab.com",
|
||||
remote: "https://custom-gitlab.com/namespace-1/namespace-2/namespace-3/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
@@ -145,11 +169,28 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Project configured in HTTPS and under two nested folders (with embedded credentials)",
|
||||
url: "https://custom-gitlab.com",
|
||||
remote: "https://username:password@custom-gitlab.com/namespace-1/namespace-2/namespace-3/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
namespace: "namespace-1/namespace-2/namespace-3",
|
||||
},
|
||||
{
|
||||
desc: "Project configured in HTTPS and under one nested folders (with gitlab url namespace)",
|
||||
url: "https://custom-gitlab.com/gitlab",
|
||||
remote: "https://username:password@custom-gitlab.com/gitlab/namespace-2/namespace-3/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
namespace: "namespace-2/namespace-3",
|
||||
},
|
||||
{
|
||||
desc: "Project configured in HTTPS and under one nested folders (with gitlab url namespace + extra slash)",
|
||||
url: "https://custom-gitlab.com/gitlab/",
|
||||
remote: "https://username:password@custom-gitlab.com/gitlab/namespace-2/namespace-3/project-name.git",
|
||||
branch: "feature/abc",
|
||||
projectName: "project-name",
|
||||
namespace: "namespace-2/namespace-3",
|
||||
},
|
||||
}
|
||||
for _, tC := range testCases {
|
||||
t.Run(tC.desc, func(t *testing.T) {
|
||||
@@ -159,7 +200,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
|
||||
BranchName: tC.branch,
|
||||
RemoteUrl: tC.remote,
|
||||
}
|
||||
data, err := NewGitData(tC.remote, g)
|
||||
data, err := NewGitData(tC.remote, tC.url, g)
|
||||
if err != nil {
|
||||
t.Errorf("No error was expected, got %s", err)
|
||||
}
|
||||
@@ -204,7 +245,7 @@ func TestExtractGitInfo_FailToGetProjectRemoteUrl(t *testing.T) {
|
||||
g := failingUrlManager{
|
||||
errMsg: tC.errMsg,
|
||||
}
|
||||
_, err := NewGitData("", g)
|
||||
_, err := NewGitData("", "", g)
|
||||
if err == nil {
|
||||
t.Errorf("Expected an error, got none")
|
||||
}
|
||||
@@ -236,7 +277,7 @@ func TestExtractGitInfo_FailToGetCurrentBranchName(t *testing.T) {
|
||||
},
|
||||
errMsg: tC.errMsg,
|
||||
}
|
||||
_, err := NewGitData("", g)
|
||||
_, err := NewGitData("", "", g)
|
||||
if err == nil {
|
||||
t.Errorf("Expected an error, got none")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user