@@ -29,6 +29,15 @@ func TestGetPullRequestURL(t *testing.T) {
2929 assert .Equal (t , "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature%2Fprofile-page&t=1" , url )
3030 },
3131 },
32+ {
33+ testName : "Opens a link to new pull request on bitbucket with extra slash removed" ,
34+ from : "feature/profile-page" ,
35+ remoteUrl : "git@bitbucket.org:/johndoe/social_network.git" ,
36+ test : func (url string , err error ) {
37+ assert .NoError (t , err )
38+ assert .Equal (t , "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature%2Fprofile-page&t=1" , url )
39+ },
40+ },
3241 {
3342 testName : "Opens a link to new pull request on bitbucket with http remote url" ,
3443 from : "feature/events" ,
@@ -47,6 +56,15 @@ func TestGetPullRequestURL(t *testing.T) {
4756 assert .Equal (t , "https://github.com/peter/calculator/compare/feature%2Fsum-operation?expand=1" , url )
4857 },
4958 },
59+ {
60+ testName : "Opens a link to new pull request on github with extra slash removed" ,
61+ from : "feature/sum-operation" ,
62+ remoteUrl : "git@github.com:/peter/calculator.git" ,
63+ test : func (url string , err error ) {
64+ assert .NoError (t , err )
65+ assert .Equal (t , "https://github.com/peter/calculator/compare/feature%2Fsum-operation?expand=1" , url )
66+ },
67+ },
5068 {
5169 testName : "Opens a link to new pull request on github with https remote url" ,
5270 from : "feature/sum-operation" ,
@@ -115,6 +133,15 @@ func TestGetPullRequestURL(t *testing.T) {
115133 assert .Equal (t , "https://gitlab.com/peter/calculator/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Fui" , url )
116134 },
117135 },
136+ {
137+ testName : "Opens a link to new pull request on gitlab with extra slash removed" ,
138+ from : "feature/ui" ,
139+ remoteUrl : "git@gitlab.com:/peter/calculator.git" ,
140+ test : func (url string , err error ) {
141+ assert .NoError (t , err )
142+ assert .Equal (t , "https://gitlab.com/peter/calculator/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Fui" , url )
143+ },
144+ },
118145 {
119146 testName : "Opens a link to new pull request on gitlab in nested groups" ,
120147 from : "feature/ui" ,
@@ -124,6 +151,15 @@ func TestGetPullRequestURL(t *testing.T) {
124151 assert .Equal (t , "https://gitlab.com/peter/public/calculator/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Fui" , url )
125152 },
126153 },
154+ {
155+ testName : "Opens a link to new pull request on gitlab in nested groups and extra slash removed" ,
156+ from : "feature/ui" ,
157+ remoteUrl : "git@gitlab.com:/peter/public/calculator.git" ,
158+ test : func (url string , err error ) {
159+ assert .NoError (t , err )
160+ assert .Equal (t , "https://gitlab.com/peter/public/calculator/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Fui" , url )
161+ },
162+ },
127163 {
128164 testName : "Opens a link to new pull request on gitlab with https remote url in nested groups" ,
129165 from : "feature/ui" ,
@@ -181,6 +217,15 @@ func TestGetPullRequestURL(t *testing.T) {
181217 assert .Equal (t , "https://dev.azure.com/myorg/myproject/_git/myrepo/pullrequestcreate?sourceRef=feature%2Fnew" , url )
182218 },
183219 },
220+ {
221+ testName : "Opens a link to new pull request on Azure DevOps (SSH) with extra slash removed" ,
222+ from : "feature/new" ,
223+ remoteUrl : "git@ssh.dev.azure.com:/v3/myorg/myproject/myrepo" ,
224+ test : func (url string , err error ) {
225+ assert .NoError (t , err )
226+ assert .Equal (t , "https://dev.azure.com/myorg/myproject/_git/myrepo/pullrequestcreate?sourceRef=feature%2Fnew" , url )
227+ },
228+ },
184229 {
185230 testName : "Opens a link to new pull request on Azure DevOps (SSH) with specific target" ,
186231 from : "feature/new" ,
@@ -248,6 +293,19 @@ func TestGetPullRequestURL(t *testing.T) {
248293 assert .Equal (t , "https://mycompany.bitbucket.com/projects/myproject/repos/myrepo/pull-requests?create&sourceBranch=feature%2Fnew" , url )
249294 },
250295 },
296+ {
297+ testName : "Opens a link to new pull request on Bitbucket Server (SSH) with extra slash removed" ,
298+ from : "feature/new" ,
299+ remoteUrl : "ssh://git@mycompany.bitbucket.com:/myproject/myrepo.git" ,
300+ configServiceDomains : map [string ]string {
301+ // valid configuration for a bitbucket server URL
302+ "mycompany.bitbucket.com" : "bitbucketServer:mycompany.bitbucket.com" ,
303+ },
304+ test : func (url string , err error ) {
305+ assert .NoError (t , err )
306+ assert .Equal (t , "https://mycompany.bitbucket.com/projects/myproject/repos/myrepo/pull-requests?create&sourceBranch=feature%2Fnew" , url )
307+ },
308+ },
251309 {
252310 testName : "Opens a link to new pull request on Bitbucket Server (SSH) with specific target" ,
253311 from : "feature/new" ,
@@ -365,6 +423,20 @@ func TestGetPullRequestURL(t *testing.T) {
365423 },
366424 expectedLoggedErrors : nil ,
367425 },
426+ {
427+ testName : "Does not log error when config service domains are valid with extra slash" ,
428+ from : "feature/profile-page" ,
429+ remoteUrl : "git@bitbucket.org:/johndoe/social_network.git" ,
430+ configServiceDomains : map [string ]string {
431+ // valid configuration for a custom service URL
432+ "git.work.com" : "gitlab:code.work.com" ,
433+ },
434+ test : func (url string , err error ) {
435+ assert .NoError (t , err )
436+ assert .Equal (t , "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature%2Fprofile-page&t=1" , url )
437+ },
438+ expectedLoggedErrors : nil ,
439+ },
368440 {
369441 testName : "Does not log error when config service webDomain contains a port" ,
370442 from : "feature/profile-page" ,
0 commit comments