add GitHubRepository

This commit is contained in:
nate smith 2019-10-10 16:02:23 -05:00
parent 6e6b18c50a
commit 09d58b923d
5 changed files with 125 additions and 22 deletions

View file

@ -22,7 +22,7 @@ func (e *GithubHostError) Error() string {
return fmt.Sprintf("Invalid GitHub URL: %s", e.url)
}
func knownGitHubHostsInclude(host string) bool {
func KnownGitHubHostsInclude(host string) bool {
for _, hh := range knownGitHubHosts() {
if hh == host {
return true

View file

@ -47,7 +47,7 @@ func (p *Project) GitURL(name, owner string, isSSH bool) string {
}
func NewProjectFromURL(url *url.URL) (p *Project, err error) {
if !knownGitHubHostsInclude(url.Host) {
if !KnownGitHubHostsInclude(url.Host) {
err = &GithubHostError{url}
return
}

View file

@ -99,3 +99,19 @@ func newRemote(name string, urlMap map[string]string) (Remote, error) {
return r, nil
}
// GuessRemote attempts to select and return the remote a user likely wants to target when dealing with GitHub repositories.
func GuessRemote() (Remote, error) {
remotes, err := Remotes()
if err != nil {
return Remote{}, err
}
if len(remotes) == 0 {
return Remote{}, fmt.Errorf("unable to guess remote")
}
// lol
return remotes[0], nil
}