github.com/Benchkram/bob@v0.0.0-20220321080157-7c8f3876e225/bob/repo.go (about)

     1  package bob
     2  
     3  import (
     4  	"net/url"
     5  	"path"
     6  	"strings"
     7  
     8  	"github.com/Benchkram/errz"
     9  )
    10  
    11  type Repo struct {
    12  	Name string
    13  
    14  	SSHUrl   string
    15  	HTTPSUrl string
    16  	LocalUrl string
    17  }
    18  
    19  // func newRepo() *Repo {
    20  // 	r := &Repo{}
    21  // 	return r
    22  // }
    23  
    24  func (b *B) RepositoryNames() (names []string, err error) {
    25  	defer errz.Recover(&err)
    26  
    27  	names = []string{}
    28  	for _, repo := range b.Repositories {
    29  		names = append(names, repo.Name)
    30  	}
    31  
    32  	return names, nil
    33  }
    34  
    35  // func (b *B) repos() (urls []*url.URL, err error) {
    36  // 	defer errz.Recover(&err)
    37  
    38  // 	urls = []*url.URL{}
    39  // 	for _, repo := range c.Repositories {
    40  // 		url, err := giturls.Parse(repo)
    41  // 		errz.Fatal(err)
    42  // 		urls = append(urls, url)
    43  // 	}
    44  
    45  // 	return urls, nil
    46  // }
    47  
    48  // RepoName returns the base part of the repo
    49  // as the name. Suffix excluded.
    50  func RepoName(repoURL *url.URL) (name string) {
    51  
    52  	base := path.Base(repoURL.String())
    53  	ext := path.Ext(repoURL.String())
    54  
    55  	name = base
    56  	if ext == ".git" {
    57  		name = strings.TrimSuffix(base, ext)
    58  	}
    59  
    60  	return name
    61  }