Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/commands/hosting_service/definitions.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package hosting_service

// if you want to make a custom regex for a given service feel free to test it out
// at regoio.herokuapp.com
// at https://regex101.com using the flavor Golang
var defaultUrlRegexStrings = []string{
`^(?:https?|ssh)://[^/]+/(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
`^.*?@.*:(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
`^.*?@.*:/*(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
}
var defaultRepoURLTemplate = "https://{{.webDomain}}/{{.owner}}/{{.repo}}"

Expand All @@ -26,7 +26,7 @@ var bitbucketServiceDef = ServiceDefinition{
commitURL: "/commits/{{.CommitHash}}",
regexStrings: []string{
`^(?:https?|ssh)://.*/(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
`^.*@.*:(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
`^.*@.*:/*(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
},
repoURLTemplate: defaultRepoURLTemplate,
}
Expand Down
72 changes: 72 additions & 0 deletions pkg/commands/hosting_service/hosting_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
},
{
testName: "Opens a link to new pull request on bitbucket with extra slash removed",
from: "feature/profile-page",
remoteUrl: "[email protected]:/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",
from: "feature/events",
Expand All @@ -47,6 +56,15 @@ func TestGetPullRequestURL(t *testing.T) {
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: "[email protected]:/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",
from: "feature/sum-operation",
Expand Down Expand Up @@ -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)
},
},
{
testName: "Opens a link to new pull request on gitlab with extra slash removed",
from: "feature/ui",
remoteUrl: "[email protected]:/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",
from: "feature/ui",
Expand All @@ -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)
},
},
{
testName: "Opens a link to new pull request on gitlab in nested groups and extra slash removed",
from: "feature/ui",
remoteUrl: "[email protected]:/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",
from: "feature/ui",
Expand Down Expand Up @@ -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)
},
},
{
testName: "Opens a link to new pull request on Azure DevOps (SSH) with extra slash removed",
from: "feature/new",
remoteUrl: "[email protected]:/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",
from: "feature/new",
Expand Down Expand Up @@ -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)
},
},
{
testName: "Opens a link to new pull request on Bitbucket Server (SSH) with extra slash removed",
from: "feature/new",
remoteUrl: "ssh://[email protected]:/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",
from: "feature/new",
Expand Down Expand Up @@ -365,6 +423,20 @@ func TestGetPullRequestURL(t *testing.T) {
},
expectedLoggedErrors: nil,
},
{
testName: "Does not log error when config service domains are valid with extra slash",
from: "feature/profile-page",
remoteUrl: "[email protected]:/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",
from: "feature/profile-page",
Expand Down
Loading