git.go

 1package git
 2
 3import (
 4	"errors"
 5	"fmt"
 6
 7	"github.com/charmbracelet/soft-serve/proto"
 8)
 9
10// ErrMissingRepo indicates that the requested repository could not be found.
11var ErrMissingRepo = errors.New("missing repo")
12
13// Repository is a Git repository with its metadata.
14type Repository struct {
15	Repo proto.Repository
16	Info proto.Metadata
17}
18
19// Readme returns the repository's README.
20func (r *Repository) Readme() (readme string, path string) {
21	readme, path, _ = r.LatestFile("README*")
22	return
23}
24
25// LatestFile returns the contents of the latest file at the specified path in
26// the repository and its file path.
27func (r *Repository) LatestFile(pattern string) (string, string, error) {
28	return proto.LatestFile(r.Repo, pattern)
29}
30
31// RepoURL returns the URL of the repository.
32func RepoURL(host string, port int, name string) string {
33	p := ""
34	if port != 22 {
35		p += fmt.Sprintf(":%d", port)
36	}
37	return fmt.Sprintf("git clone ssh://%s/%s", host+p, name)
38}