mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-23 21:51:07 +02:00
Remove doubled string formatting in pull request URL generation
This commit is contained in:
parent
0a63f701e5
commit
d5ec0fdcd1
pkg/commands
@ -38,11 +38,9 @@ func NewService(typeName string, repositoryDomain string, siteDomain string) *Se
|
||||
Name: repositoryDomain,
|
||||
PullRequestURL: func(owner string, repository string, from string, to string) string {
|
||||
if to == "" {
|
||||
urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/compare/%s?expand=1")
|
||||
return fmt.Sprintf(urlFormat, owner, repository, from)
|
||||
return fmt.Sprintf("https://%s/%s/%s/compare/%s?expand=1",siteDomain, owner, repository, from)
|
||||
} else {
|
||||
urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/compare/%s...%s?expand=1")
|
||||
return fmt.Sprintf(urlFormat, owner, repository, to, from)
|
||||
return fmt.Sprintf("https://%s/%s/%s/compare/%s...%s?expand=1", siteDomain, owner, repository, to, from)
|
||||
}
|
||||
},
|
||||
}
|
||||
@ -51,11 +49,9 @@ func NewService(typeName string, repositoryDomain string, siteDomain string) *Se
|
||||
Name: repositoryDomain,
|
||||
PullRequestURL: func(owner string, repository string, from string, to string) string {
|
||||
if to == "" {
|
||||
urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/pull-requests/new?source=%s&t=1")
|
||||
return fmt.Sprintf(urlFormat, owner, repository, from)
|
||||
return fmt.Sprintf("https://%s/%s/%s/pull-requests/new?source=%s&t=1", siteDomain, owner, repository, from)
|
||||
} else {
|
||||
urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/pull-requests/new?source=%s&dest=%s&t=1")
|
||||
return fmt.Sprintf(urlFormat, owner, repository, from, to)
|
||||
return fmt.Sprintf("https://%s/%s/%s/pull-requests/new?source=%s&dest=%s&t=1", siteDomain, owner, repository, from, to)
|
||||
}
|
||||
},
|
||||
}
|
||||
@ -64,11 +60,9 @@ func NewService(typeName string, repositoryDomain string, siteDomain string) *Se
|
||||
Name: repositoryDomain,
|
||||
PullRequestURL: func(owner string, repository string, from string, to string) string {
|
||||
if to == "" {
|
||||
urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/merge_requests/new?merge_request[source_branch]=%s")
|
||||
return fmt.Sprintf(urlFormat, owner, repository, from)
|
||||
return fmt.Sprintf("https://%s/%s/%s/merge_requests/new?merge_request[source_branch]=%s", siteDomain, owner, repository, from)
|
||||
} else {
|
||||
urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/merge_requests/new?merge_request[source_branch]=%s&merge_request[target_branch]=%s")
|
||||
return fmt.Sprintf(urlFormat, owner, repository, from, to)
|
||||
return fmt.Sprintf("https://%s/%s/%s/merge_requests/new?merge_request[source_branch]=%s&merge_request[target_branch]=%s", siteDomain, owner, repository, from, to)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -212,6 +212,27 @@ func TestCreatePullRequest(t *testing.T) {
|
||||
assert.Equal(t, "https://gitlab.com/peter/calculator/merge_requests/new?merge_request[source_branch]=feature/ui", url)
|
||||
},
|
||||
},
|
||||
{
|
||||
testName: "Opens a link to new pull request on gitlab in nested groups",
|
||||
from: &models.Branch{
|
||||
Name: "feature/ui",
|
||||
},
|
||||
remoteUrl: "git@gitlab.com:peter/public/calculator.git",
|
||||
command: func(cmd string, args ...string) *exec.Cmd {
|
||||
// Handle git remote url call
|
||||
if strings.HasPrefix(cmd, "git") {
|
||||
return secureexec.Command("echo", "git@gitlab.com:peter/calculator.git")
|
||||
}
|
||||
|
||||
assert.Equal(t, cmd, "open")
|
||||
assert.Equal(t, args, []string{"https://gitlab.com/peter/public/calculator/merge_requests/new?merge_request[source_branch]=feature/ui"})
|
||||
return secureexec.Command("echo")
|
||||
},
|
||||
test: func(url string, err error) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "https://gitlab.com/peter/public/calculator/merge_requests/new?merge_request[source_branch]=feature/ui", url)
|
||||
},
|
||||
},
|
||||
{
|
||||
testName: "Opens a link to new pull request on gitlab with specific target branch",
|
||||
from: &models.Branch{
|
||||
@ -236,6 +257,30 @@ func TestCreatePullRequest(t *testing.T) {
|
||||
assert.Equal(t, "https://gitlab.com/peter/calculator/merge_requests/new?merge_request[source_branch]=feature/commit-ui&merge_request[target_branch]=epic/ui", url)
|
||||
},
|
||||
},
|
||||
{
|
||||
testName: "Opens a link to new pull request on gitlab with specific target branch in nested groups",
|
||||
from: &models.Branch{
|
||||
Name: "feature/commit-ui",
|
||||
},
|
||||
to: &models.Branch{
|
||||
Name: "epic/ui",
|
||||
},
|
||||
remoteUrl: "git@gitlab.com:peter/public/calculator.git",
|
||||
command: func(cmd string, args ...string) *exec.Cmd {
|
||||
// Handle git remote url call
|
||||
if strings.HasPrefix(cmd, "git") {
|
||||
return secureexec.Command("echo", "git@gitlab.com:peter/calculator.git")
|
||||
}
|
||||
|
||||
assert.Equal(t, cmd, "open")
|
||||
assert.Equal(t, args, []string{"https://gitlab.com/peter/public/calculator/merge_requests/new?merge_request[source_branch]=feature/commit-ui&merge_request[target_branch]=epic/ui"})
|
||||
return secureexec.Command("echo")
|
||||
},
|
||||
test: func(url string, err error) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "https://gitlab.com/peter/public/calculator/merge_requests/new?merge_request[source_branch]=feature/commit-ui&merge_request[target_branch]=epic/ui", url)
|
||||
},
|
||||
},
|
||||
{
|
||||
testName: "Throws an error if git service is unsupported",
|
||||
from: &models.Branch{
|
||||
|
Loading…
x
Reference in New Issue
Block a user