github.com/abhinav/git-pr@v0.6.1-0.20171029234004-54218d68c11b/repo/guess.go (about) 1 package repo 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/abhinav/git-pr/gateway" 8 ) 9 10 var _prefixes = []string{ 11 "ssh://git@github.com/", 12 "git@github.com:", 13 "https://github.com/", 14 } 15 16 // Guess determines the Repo name based on the current Git repository's remotes. 17 func Guess(git gateway.Git) (*Repo, error) { 18 url, err := git.RemoteURL("origin") 19 if err != nil { 20 return nil, err 21 } 22 23 for _, prefix := range _prefixes { 24 if strings.HasPrefix(url, prefix) { 25 url := strings.TrimPrefix(url, prefix) 26 return Parse(strings.TrimSuffix(url, ".git")) 27 } 28 } 29 30 return nil, fmt.Errorf(`remote "origin" (%v) is not a GitHub remote`, url) 31 }