From d7b611aa058962ed5dee0213a99a45f0207cefda Mon Sep 17 00:00:00 2001 From: Raido Oras Date: Tue, 8 Aug 2023 05:13:52 +0300 Subject: [PATCH] Allow port in webDomain for services config values --- .../hosting_service/hosting_service.go | 9 ++++--- .../hosting_service/hosting_service_test.go | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/pkg/commands/hosting_service/hosting_service.go b/pkg/commands/hosting_service/hosting_service.go index e6f9bef79..5744680ab 100644 --- a/pkg/commands/hosting_service/hosting_service.go +++ b/pkg/commands/hosting_service/hosting_service.go @@ -101,15 +101,14 @@ func (self *HostingServiceMgr) getCandidateServiceDomains() []ServiceDomain { if len(self.configServiceDomains) > 0 { for gitDomain, typeAndDomain := range self.configServiceDomains { - splitData := strings.Split(typeAndDomain, ":") - if len(splitData) != 2 { + provider, webDomain, success := strings.Cut(typeAndDomain, ":") + + // we allow for one ':' for specifying the TCP port + if !success || strings.Count(webDomain, ":") > 1 { self.log.Errorf("Unexpected format for git service: '%s'. Expected something like 'github.com:github.com'", typeAndDomain) continue } - provider := splitData[0] - webDomain := splitData[1] - serviceDefinition, ok := serviceDefinitionByProvider[provider] if !ok { providerNames := lo.Map(serviceDefinitions, func(serviceDefinition ServiceDefinition, _ int) string { diff --git a/pkg/commands/hosting_service/hosting_service_test.go b/pkg/commands/hosting_service/hosting_service_test.go index 83d707a43..c5968c4cd 100644 --- a/pkg/commands/hosting_service/hosting_service_test.go +++ b/pkg/commands/hosting_service/hosting_service_test.go @@ -340,6 +340,30 @@ func TestGetPullRequestURL(t *testing.T) { }, expectedLoggedErrors: nil, }, + { + testName: "Does not log error when config service webDomain contains a port", + from: "feature/profile-page", + remoteUrl: "git@my.domain.test:johndoe/social_network.git", + configServiceDomains: map[string]string{ + "my.domain.test": "gitlab:my.domain.test:1111", + }, + test: func(url string, err error) { + assert.NoError(t, err) + assert.Equal(t, "https://my.domain.test:1111/johndoe/social_network/-/merge_requests/new?merge_request[source_branch]=feature%2Fprofile-page", url) + }, + }, + { + testName: "Logs error when webDomain contains more than one colon", + from: "feature/profile-page", + remoteUrl: "git@my.domain.test:johndoe/social_network.git", + configServiceDomains: map[string]string{ + "my.domain.test": "gitlab:my.domain.test:1111:2222", + }, + test: func(url string, err error) { + assert.Error(t, err) + }, + expectedLoggedErrors: []string{"Unexpected format for git service: 'gitlab:my.domain.test:1111:2222'. Expected something like 'github.com:github.com'"}, + }, { testName: "Logs error when config service domain is malformed", from: "feature/profile-page",