Repository: jesseduffield/lazygit
File: pkg/commands/hosting_service/hosting_service.go (Go)

Code before:
func (self *HostingServiceMgr) getServiceDomain(repoURL string) (*ServiceDomain, error) {
	candidateServiceDomains := self.getCandidateServiceDomains()

	for _, serviceDomain := range candidateServiceDomains {
		if strings.Contains(repoURL, serviceDomain.gitDomain) {
			return &serviceDomain, nil
		}
	}

	return nil, errors.New(self.tr.UnsupportedGitService)
}

func (self *HostingServiceMgr) getCandidateServiceDomains() []ServiceDomain {
	serviceDefinitionByProvider := map[string]ServiceDefinition{}
	for _, serviceDefinition := range serviceDefinitions {
		serviceDefinitionByProvider[serviceDefinition.provider] = serviceDefinition
	}

	serviceDomains := slices.Clone(defaultServiceDomains)

	if len(self.configServiceDomains) > 0 {
		for gitDomain, typeAndDomain := range self.configServiceDomains {
			provider, webDomain, success := strings.Cut(typeAndDomain, ":")

			if !success || strings.Count(webDomain, ":") > 1 {
				self.log.Errorf("Unexpected format for git service: '%s'. Expected something like 'github.com:github.com'", typeAndDomain)
				continue
			}

			serviceDefinition, ok := serviceDefinitionByProvider[provider]
			if !ok {
				providerNames := lo.Map(serviceDefinitions, func(serviceDefinition ServiceDefinition, _ int) string {
					return serviceDefinition.provider
				})

				self.log.Errorf("Unknown git service type: '%s'. Expected one of %s", provider, strings.Join(providerNames, ", "))
				continue
			}

			serviceDomains = append(serviceDomains, ServiceDomain{
				gitDomain:         gitDomain,
				webDomain:         webDomain,
				serviceDefinition: serviceDefinition,
			})
		}
	}

	return serviceDomains
}

// a service domains pairs a service definition with the actual domain it's being served from.

Review comment (suggestion):
```suggestion
			// we allow for one ':' for specifying the TCP port
			if !success || strings.Count(webDomain, ":") > 1 {
```

Code after:
func (self *HostingServiceMgr) getServiceDomain(repoURL string) (*ServiceDomain, error) {
	candidateServiceDomains := self.getCandidateServiceDomains()

	for _, serviceDomain := range candidateServiceDomains {
		if strings.Contains(repoURL, serviceDomain.gitDomain) {
			return &serviceDomain, nil
		}
	}

	return nil, errors.New(self.tr.UnsupportedGitService)
}

func (self *HostingServiceMgr) getCandidateServiceDomains() []ServiceDomain {
	serviceDefinitionByProvider := map[string]ServiceDefinition{}
	for _, serviceDefinition := range serviceDefinitions {
		serviceDefinitionByProvider[serviceDefinition.provider] = serviceDefinition
	}

	serviceDomains := slices.Clone(defaultServiceDomains)

	if len(self.configServiceDomains) > 0 {
		for gitDomain, typeAndDomain := range self.configServiceDomains {
			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
			}

			serviceDefinition, ok := serviceDefinitionByProvider[provider]
			if !ok {
				providerNames := lo.Map(serviceDefinitions, func(serviceDefinition ServiceDefinition, _ int) string {
					return serviceDefinition.provider
				})

				self.log.Errorf("Unknown git service type: '%s'. Expected one of %s", provider, strings.Join(providerNames, ", "))
				continue
			}

			serviceDomains = append(serviceDomains, ServiceDomain{
				gitDomain:         gitDomain,
				webDomain:         webDomain,
				serviceDefinition: serviceDefinition,
			})
		}
	}

	return serviceDomains
}