From 4db22aec0e9de2b580580b19751d87fe3272d590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Pavli=CC=81k?= Date: Sat, 6 Aug 2022 22:54:57 +0200 Subject: [PATCH] support custom SSH usernames on BitBucket, fixes #1890 --- pkg/commands/hosting_service/definitions.go | 7 +++++-- pkg/commands/hosting_service/hosting_service_test.go | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/commands/hosting_service/definitions.go b/pkg/commands/hosting_service/definitions.go index 04d496aa8..c53ee0507 100644 --- a/pkg/commands/hosting_service/definitions.go +++ b/pkg/commands/hosting_service/definitions.go @@ -24,8 +24,11 @@ var bitbucketServiceDef = ServiceDefinition{ pullRequestURLIntoDefaultBranch: "/pull-requests/new?source={{.From}}&t=1", pullRequestURLIntoTargetBranch: "/pull-requests/new?source={{.From}}&dest={{.To}}&t=1", commitURL: "/commits/{{.CommitSha}}", - regexStrings: defaultUrlRegexStrings, - repoURLTemplate: defaultRepoURLTemplate, + regexStrings: []string{ + `^(?:https?|ssh)://.*/(?P.*)/(?P.*?)(?:\.git)?$`, + `^.*@.*:(?P.*)/(?P.*?)(?:\.git)?$`, + }, + repoURLTemplate: defaultRepoURLTemplate, } var gitLabServiceDef = ServiceDefinition{ diff --git a/pkg/commands/hosting_service/hosting_service_test.go b/pkg/commands/hosting_service/hosting_service_test.go index 0c926117d..b92daa98d 100644 --- a/pkg/commands/hosting_service/hosting_service_test.go +++ b/pkg/commands/hosting_service/hosting_service_test.go @@ -115,6 +115,15 @@ func TestGetPullRequestURL(t *testing.T) { assert.Equal(t, "https://gitlab.com/peter/public/calculator/merge_requests/new?merge_request[source_branch]=feature%2Fcommit-ui&merge_request[target_branch]=epic%2Fui", url) }, }, + { + testName: "Opens a link to new pull request on bitbucket with a custom SSH username", + from: "feature/profile-page", + remoteUrl: "john@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 Azure DevOps (SSH)", from: "feature/new",