mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-23 16:22:24 +03:00
Open pull requests in browser with extra leading slashes removed
This allows for having extra slashes in git urls, for example to avoid warnings with older bitbake fetcher implementations in yocto. Which warns about a missing / in git urls
This commit is contained in:
@@ -4,7 +4,7 @@ package hosting_service
|
|||||||
// at regoio.herokuapp.com
|
// at regoio.herokuapp.com
|
||||||
var defaultUrlRegexStrings = []string{
|
var defaultUrlRegexStrings = []string{
|
||||||
`^(?:https?|ssh)://[^/]+/(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
|
`^(?:https?|ssh)://[^/]+/(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
|
||||||
`^.*?@.*:(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
|
`^.*?@.*:/*(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
|
||||||
}
|
}
|
||||||
var defaultRepoURLTemplate = "https://{{.webDomain}}/{{.owner}}/{{.repo}}"
|
var defaultRepoURLTemplate = "https://{{.webDomain}}/{{.owner}}/{{.repo}}"
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ var bitbucketServiceDef = ServiceDefinition{
|
|||||||
commitURL: "/commits/{{.CommitHash}}",
|
commitURL: "/commits/{{.CommitHash}}",
|
||||||
regexStrings: []string{
|
regexStrings: []string{
|
||||||
`^(?:https?|ssh)://.*/(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
|
`^(?:https?|ssh)://.*/(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
|
||||||
`^.*@.*:(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
|
`^.*@.*:/*(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
|
||||||
},
|
},
|
||||||
repoURLTemplate: defaultRepoURLTemplate,
|
repoURLTemplate: defaultRepoURLTemplate,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,15 @@ func TestGetPullRequestURL(t *testing.T) {
|
|||||||
assert.Equal(t, "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature%2Fprofile-page&t=1", url)
|
assert.Equal(t, "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature%2Fprofile-page&t=1", url)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on bitbucket with extra slash removed",
|
||||||
|
from: "feature/profile-page",
|
||||||
|
remoteUrl: "git@bitbucket.org:/johndoe/social_network.git",
|
||||||
|
test: func(url string, err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature%2Fprofile-page&t=1", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
testName: "Opens a link to new pull request on bitbucket with http remote url",
|
testName: "Opens a link to new pull request on bitbucket with http remote url",
|
||||||
from: "feature/events",
|
from: "feature/events",
|
||||||
@@ -47,6 +56,15 @@ func TestGetPullRequestURL(t *testing.T) {
|
|||||||
assert.Equal(t, "https://github.com/peter/calculator/compare/feature%2Fsum-operation?expand=1", url)
|
assert.Equal(t, "https://github.com/peter/calculator/compare/feature%2Fsum-operation?expand=1", url)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on github with extra slash removed",
|
||||||
|
from: "feature/sum-operation",
|
||||||
|
remoteUrl: "git@github.com:/peter/calculator.git",
|
||||||
|
test: func(url string, err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://github.com/peter/calculator/compare/feature%2Fsum-operation?expand=1", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
testName: "Opens a link to new pull request on github with https remote url",
|
testName: "Opens a link to new pull request on github with https remote url",
|
||||||
from: "feature/sum-operation",
|
from: "feature/sum-operation",
|
||||||
@@ -115,6 +133,15 @@ func TestGetPullRequestURL(t *testing.T) {
|
|||||||
assert.Equal(t, "https://gitlab.com/peter/calculator/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Fui", url)
|
assert.Equal(t, "https://gitlab.com/peter/calculator/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Fui", url)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on gitlab with extra slash removed",
|
||||||
|
from: "feature/ui",
|
||||||
|
remoteUrl: "git@gitlab.com:/peter/calculator.git",
|
||||||
|
test: func(url string, err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://gitlab.com/peter/calculator/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Fui", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
testName: "Opens a link to new pull request on gitlab in nested groups",
|
testName: "Opens a link to new pull request on gitlab in nested groups",
|
||||||
from: "feature/ui",
|
from: "feature/ui",
|
||||||
@@ -124,6 +151,15 @@ func TestGetPullRequestURL(t *testing.T) {
|
|||||||
assert.Equal(t, "https://gitlab.com/peter/public/calculator/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Fui", url)
|
assert.Equal(t, "https://gitlab.com/peter/public/calculator/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Fui", url)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on gitlab in nested groups and extra slash removed",
|
||||||
|
from: "feature/ui",
|
||||||
|
remoteUrl: "git@gitlab.com:/peter/public/calculator.git",
|
||||||
|
test: func(url string, err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://gitlab.com/peter/public/calculator/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Fui", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
testName: "Opens a link to new pull request on gitlab with https remote url in nested groups",
|
testName: "Opens a link to new pull request on gitlab with https remote url in nested groups",
|
||||||
from: "feature/ui",
|
from: "feature/ui",
|
||||||
@@ -181,6 +217,15 @@ func TestGetPullRequestURL(t *testing.T) {
|
|||||||
assert.Equal(t, "https://dev.azure.com/myorg/myproject/_git/myrepo/pullrequestcreate?sourceRef=feature%2Fnew", url)
|
assert.Equal(t, "https://dev.azure.com/myorg/myproject/_git/myrepo/pullrequestcreate?sourceRef=feature%2Fnew", url)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on Azure DevOps (SSH) with extra slash removed",
|
||||||
|
from: "feature/new",
|
||||||
|
remoteUrl: "git@ssh.dev.azure.com:/v3/myorg/myproject/myrepo",
|
||||||
|
test: func(url string, err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://dev.azure.com/myorg/myproject/_git/myrepo/pullrequestcreate?sourceRef=feature%2Fnew", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
testName: "Opens a link to new pull request on Azure DevOps (SSH) with specific target",
|
testName: "Opens a link to new pull request on Azure DevOps (SSH) with specific target",
|
||||||
from: "feature/new",
|
from: "feature/new",
|
||||||
@@ -248,6 +293,19 @@ func TestGetPullRequestURL(t *testing.T) {
|
|||||||
assert.Equal(t, "https://mycompany.bitbucket.com/projects/myproject/repos/myrepo/pull-requests?create&sourceBranch=feature%2Fnew", url)
|
assert.Equal(t, "https://mycompany.bitbucket.com/projects/myproject/repos/myrepo/pull-requests?create&sourceBranch=feature%2Fnew", url)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on Bitbucket Server (SSH) with extra slash removed",
|
||||||
|
from: "feature/new",
|
||||||
|
remoteUrl: "ssh://git@mycompany.bitbucket.com:/myproject/myrepo.git",
|
||||||
|
configServiceDomains: map[string]string{
|
||||||
|
// valid configuration for a bitbucket server URL
|
||||||
|
"mycompany.bitbucket.com": "bitbucketServer:mycompany.bitbucket.com",
|
||||||
|
},
|
||||||
|
test: func(url string, err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://mycompany.bitbucket.com/projects/myproject/repos/myrepo/pull-requests?create&sourceBranch=feature%2Fnew", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
testName: "Opens a link to new pull request on Bitbucket Server (SSH) with specific target",
|
testName: "Opens a link to new pull request on Bitbucket Server (SSH) with specific target",
|
||||||
from: "feature/new",
|
from: "feature/new",
|
||||||
@@ -365,6 +423,20 @@ func TestGetPullRequestURL(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedLoggedErrors: nil,
|
expectedLoggedErrors: nil,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "Does not log error when config service domains are valid with extra slash",
|
||||||
|
from: "feature/profile-page",
|
||||||
|
remoteUrl: "git@bitbucket.org:/johndoe/social_network.git",
|
||||||
|
configServiceDomains: map[string]string{
|
||||||
|
// valid configuration for a custom service URL
|
||||||
|
"git.work.com": "gitlab:code.work.com",
|
||||||
|
},
|
||||||
|
test: func(url string, err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature%2Fprofile-page&t=1", url)
|
||||||
|
},
|
||||||
|
expectedLoggedErrors: nil,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
testName: "Does not log error when config service webDomain contains a port",
|
testName: "Does not log error when config service webDomain contains a port",
|
||||||
from: "feature/profile-page",
|
from: "feature/profile-page",
|
||||||
|
|||||||
Reference in New Issue
Block a user