Temporary registers, SSH Port, Bug Fixes (#251)

- allows SSH Gitlab connection to have custom port
- introduces temporary registers
- fixes issue w/ quitting the popup on MR creation

This is a #MINOR release
This commit is contained in:
Harrison (Harry) Cramer
2024-04-09 12:24:07 -04:00
committed by GitHub
parent 36f512cd6d
commit 7c3ee0530b
15 changed files with 404 additions and 290 deletions

View File

@@ -14,6 +14,8 @@ type CreateMrRequest struct {
Title string `json:"title"`
Description string `json:"description"`
TargetBranch string `json:"target_branch"`
DeleteBranch bool `json:"delete_branch"`
Squash bool `json:"squash"`
}
/* createMr creates a merge request */
@@ -49,10 +51,12 @@ func (a *api) createMr(w http.ResponseWriter, r *http.Request) {
}
opts := gitlab.CreateMergeRequestOptions{
Title: &createMrRequest.Title,
Description: &createMrRequest.Description,
TargetBranch: &createMrRequest.TargetBranch,
SourceBranch: &a.gitInfo.BranchName,
Title: &createMrRequest.Title,
Description: &createMrRequest.Description,
TargetBranch: &createMrRequest.TargetBranch,
SourceBranch: &a.gitInfo.BranchName,
RemoveSourceBranch: &createMrRequest.DeleteBranch,
Squash: &createMrRequest.Squash,
}
_, res, err := a.client.CreateMergeRequest(a.projectInfo.ProjectId, &opts)

View File

@@ -27,6 +27,8 @@ func TestCreateMr(t *testing.T) {
Title: "Some title",
Description: "Some description",
TargetBranch: "main",
DeleteBranch: false,
Squash: false,
}
request := makeRequest(t, http.MethodPost, "/create_mr", body)
@@ -48,6 +50,8 @@ func TestCreateMr(t *testing.T) {
Title: "Some title",
Description: "Some description",
TargetBranch: "main",
DeleteBranch: false,
Squash: false,
}
request := makeRequest(t, http.MethodPost, "/create_mr", body)
server, _ := createRouterAndApi(fakeClient{createMrFn: createMrFnErr})
@@ -60,6 +64,8 @@ func TestCreateMr(t *testing.T) {
Title: "Some title",
Description: "Some description",
TargetBranch: "main",
DeleteBranch: false,
Squash: false,
}
request := makeRequest(t, http.MethodPost, "/create_mr", body)
server, _ := createRouterAndApi(fakeClient{createMrFn: createMrFnNon200})
@@ -72,6 +78,8 @@ func TestCreateMr(t *testing.T) {
Title: "",
Description: "Some description",
TargetBranch: "main",
DeleteBranch: false,
Squash: false,
}
request := makeRequest(t, http.MethodPost, "/create_mr", body)
server, _ := createRouterAndApi(fakeClient{createMrFn: createMrFn})
@@ -86,6 +94,8 @@ func TestCreateMr(t *testing.T) {
Title: "Some title",
Description: "Some description",
TargetBranch: "",
DeleteBranch: false,
Squash: false,
}
request := makeRequest(t, http.MethodPost, "/create_mr", body)
server, _ := createRouterAndApi(fakeClient{createMrFn: createMrFn})

View File

@@ -28,14 +28,12 @@ it to the client for initialization. The current directory must be a valid
Gitlab project and the branch must be a feature branch
*/
func extractGitInfo(refreshGitInfo func() error, getProjectRemoteUrl func() (string, error), getCurrentBranchName func() (string, error)) (GitProjectInfo, error) {
err := refreshGitInfo()
if err != nil {
return GitProjectInfo{}, fmt.Errorf("Could not get latest information from remote: %v", err)
}
url, err := getProjectRemoteUrl()
if err != nil {
return GitProjectInfo{}, fmt.Errorf("Could not get project Url: %v", err)
}
@@ -52,7 +50,7 @@ func extractGitInfo(refreshGitInfo func() error, getProjectRemoteUrl func() (str
https://git@gitlab.com/namespace/subnamespace/dummy-test-repo.git
git@git@gitlab.com:namespace/subnamespace/dummy-test-repo.git
*/
re := regexp.MustCompile(`(?:^https?:\/\/|^ssh:\/\/|^git@)(?:[^\/:]+)[\/:](.*)\/([^\/]+?)(?:\.git)?$`)
re := regexp.MustCompile(`(?:^https?:\/\/|^ssh:\/\/|^git@)(?:[^\/:]+)(?::\d+)?[\/:](.*)\/([^\/]+?)(?:\.git)?$`)
matches := re.FindStringSubmatch(url)
if len(matches) != 3 {
return GitProjectInfo{}, fmt.Errorf("Invalid Git URL format: %s", url)

View File

@@ -102,6 +102,18 @@ func TestExtractGitInfo_Success(t *testing.T) {
Namespace: "namespace-1/namespace-2/namespace-3",
},
},
{
desc: "Project configured in SSH:// and have a custom port",
getProjectRemoteUrl: func() (string, error) {
return "ssh://custom-gitlab.com:2222/namespace-1/project-name", nil
},
expected: GitProjectInfo{
RemoteUrl: "ssh://custom-gitlab.com:2222/namespace-1/project-name",
BranchName: "feature/abc",
ProjectName: "project-name",
Namespace: "namespace-1",
},
},
{
desc: "Project configured in HTTP and under a single folder without .git extension",
getProjectRemoteUrl: func() (string, error) {