Skip to content

Commit

Permalink
Always use the standard port for browser URLs (#2730)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgo committed Dec 6, 2023
1 parent ec62fa0 commit fe2c199
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion features/propose/features/self_hosted.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Feature: self-hosted service
When I run "git-town propose"
Then "open" launches a new proposal with this url in my browser:
"""
https://git.example.com:4022/a/b
https://git.example.com/a/b
"""
2 changes: 1 addition & 1 deletion features/repo/features/self_hosted.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Feature: self hosted servie
When I run "git-town repo"
Then "open" launches a new proposal with this url in my browser:
"""
https://git.example.com:4022/a/b
https://git.example.com/a/b
"""
2 changes: 1 addition & 1 deletion src/hosting/bitbucket/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (self *Connector) NewProposalURL(branch, parentBranch domain.LocalBranchNam
}

func (self *Connector) RepositoryURL() string {
return fmt.Sprintf("https://%s/%s/%s", self.Hostname, self.Organization, self.Repository)
return fmt.Sprintf("https://%s/%s/%s", self.HostnameWithStandardPort(), self.Organization, self.Repository)
}

func (self *Connector) SquashMergeProposal(_ int, _ string) (mergeSHA domain.SHA, err error) {
Expand Down
10 changes: 10 additions & 0 deletions src/hosting/common/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package common

import "strings"

// Config contains data needed by all platform connectors.
type Config struct {
// bearer token to authenticate with the API
Expand All @@ -14,3 +16,11 @@ type Config struct {
// repo name within the organization
Repository string
}

func (self Config) HostnameWithStandardPort() string {
index := strings.IndexRune(self.Hostname, ':')
if index == -1 {
return self.Hostname
}
return self.Hostname[:index]
}
38 changes: 38 additions & 0 deletions src/hosting/common/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package common_test

import (
"testing"

"github.com/git-town/git-town/v10/src/hosting/common"
"github.com/shoenig/test/must"
)

func TestHostnameWithStandardPort(t *testing.T) {
t.Parallel()

t.Run("no port in hostname", func(t *testing.T) {
t.Parallel()
config := common.Config{
APIToken: "123456",
Hostname: "git.example.com",
Organization: "org",
Repository: "repo",
}
have := config.HostnameWithStandardPort()
want := "git.example.com"
must.EqOp(t, want, have)
})

t.Run("port in hostname", func(t *testing.T) {
t.Parallel()
config := common.Config{
APIToken: "123456",
Hostname: "git.example.com:4022",
Organization: "org",
Repository: "repo",
}
have := config.HostnameWithStandardPort()
want := "git.example.com"
must.EqOp(t, want, have)
})
}
2 changes: 1 addition & 1 deletion src/hosting/gitea/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (self *Connector) NewProposalURL(branch, parentBranch domain.LocalBranchNam
}

func (self *Connector) RepositoryURL() string {
return fmt.Sprintf("https://%s/%s/%s", self.Hostname, self.Organization, self.Repository)
return fmt.Sprintf("https://%s/%s/%s", self.HostnameWithStandardPort(), self.Organization, self.Repository)
}

func (self *Connector) SquashMergeProposal(number int, message string) (mergeSHA domain.SHA, err error) {
Expand Down
2 changes: 1 addition & 1 deletion src/hosting/github/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (self *Connector) NewProposalURL(branch, parentBranch domain.LocalBranchNam
}

func (self *Connector) RepositoryURL() string {
return fmt.Sprintf("https://%s/%s/%s", self.Hostname, self.Organization, self.Repository)
return fmt.Sprintf("https://%s/%s/%s", self.HostnameWithStandardPort(), self.Organization, self.Repository)
}

func (self *Connector) SquashMergeProposal(number int, message string) (mergeSHA domain.SHA, err error) {
Expand Down
2 changes: 1 addition & 1 deletion src/hosting/gitlab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (self *Config) RepositoryURL() string {
}

func (self *Config) baseURL() string {
return fmt.Sprintf("https://%s", self.Hostname)
return fmt.Sprintf("https://%s", self.HostnameWithStandardPort())
}

func (self *Config) projectPath() string {
Expand Down

0 comments on commit fe2c199

Please sign in to comment.