1package git
 2
 3import (
 4	"errors"
 5	"fmt"
 6
 7	"github.com/charmbracelet/soft-serve/git"
 8)
 9
10// ErrMissingRepo indicates that the requested repository could not be found.
11var ErrMissingRepo = errors.New("missing repo")
12
13// GitRepo is an interface for Git repositories.
14type GitRepo interface {
15	Repo() string
16	Name() string
17	Description() string
18	Readme() (string, string)
19	HEAD() (*git.Reference, error)
20	CommitsByPage(*git.Reference, int, int) (git.Commits, error)
21	CountCommits(*git.Reference) (int64, error)
22	Diff(*git.Commit) (*git.Diff, error)
23	References() ([]*git.Reference, error)
24	Tree(*git.Reference, string) (*git.Tree, error)
25	IsPrivate() bool
26}
27
28// GitRepoSource is an interface for Git repository factory.
29type GitRepoSource interface {
30	GetRepo(string) (GitRepo, error)
31	AllRepos() []GitRepo
32}
33
34// RepoURL returns the URL of the repository.
35func RepoURL(host string, port int, name string) string {
36	p := ""
37	if port != 22 {
38		p += fmt.Sprintf(":%d", port)
39	}
40	return fmt.Sprintf("git clone ssh://%s/%s", host+p, name)
41}