Remove unused functionality from 'project'

This commit is contained in:
Mislav Marohnić 2019-10-07 16:34:52 +02:00
parent 01162c953e
commit ce0e1d7e35

View file

@ -3,11 +3,8 @@ package github
import (
"fmt"
"net/url"
"os"
"path/filepath"
"strings"
"github.com/github/gh-cli/git"
"github.com/github/gh-cli/utils"
)
@ -37,23 +34,6 @@ func (p *Project) WebURL(name, owner, path string) string {
}
ownerWithName := fmt.Sprintf("%s/%s", owner, name)
if strings.Contains(ownerWithName, ".wiki") {
ownerWithName = strings.TrimSuffix(ownerWithName, ".wiki")
if path != "wiki" {
if strings.HasPrefix(path, "commits") {
path = "_history"
} else if path != "" {
path = fmt.Sprintf("_%s", path)
}
if path != "" {
path = utils.ConcatPaths("wiki", path)
} else {
path = "wiki"
}
}
}
url := fmt.Sprintf("%s://%s", p.Protocol, utils.ConcatPaths(p.Host, ownerWithName))
if path != "" {
url = utils.ConcatPaths(url, path)
@ -62,45 +42,8 @@ func (p *Project) WebURL(name, owner, path string) string {
return url
}
func (p *Project) GitURL(name, owner string, isSSH bool) (url string) {
if name == "" {
name = p.Name
}
if owner == "" {
owner = p.Owner
}
host := rawHost(p.Host)
if preferredProtocol() == "https" {
url = fmt.Sprintf("https://%s/%s/%s.git", host, owner, name)
} else if isSSH || preferredProtocol() == "ssh" {
url = fmt.Sprintf("git@%s:%s/%s.git", host, owner, name)
} else {
url = fmt.Sprintf("git://%s/%s/%s.git", host, owner, name)
}
return url
}
// Remove the scheme from host when the host url is absolute.
func rawHost(host string) string {
u, err := url.Parse(host)
utils.Check(err)
if u.IsAbs() {
return u.Host
} else {
return u.Path
}
}
func preferredProtocol() string {
userProtocol := os.Getenv("HUB_PROTOCOL")
if userProtocol == "" {
userProtocol, _ = git.Config("hub.protocol")
}
return userProtocol
func (p *Project) GitURL(name, owner string, isSSH bool) string {
return p.WebURL(name, owner, "") + ".git"
}
func NewProjectFromURL(url *url.URL) (p *Project, err error) {
@ -174,8 +117,3 @@ func newProject(owner, name, host, protocol string) *Project {
Protocol: protocol,
}
}
func SanitizeProjectName(name string) string {
name = filepath.Base(name)
return strings.Replace(name, " ", "-", -1)
}