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	Commit(string) (*git.Commit, error)
21	CommitsByPage(*git.Reference, int, int) (git.Commits, error)
22	CountCommits(*git.Reference) (int64, error)
23	Diff(*git.Commit) (*git.Diff, error)
24	References() ([]*git.Reference, error)
25	Tree(*git.Reference, string) (*git.Tree, error)
26	IsPrivate() bool
27}
28
29// GitRepoSource is an interface for Git repository factory.
30type GitRepoSource interface {
31	GetRepo(string) (GitRepo, error)
32	AllRepos() []GitRepo
33}
34
35// RepoURL returns the URL of the repository.
36func RepoURL(host string, port int, name string) string {
37	p := ""
38	if port != 22 {
39		p += fmt.Sprintf(":%d", port)
40	}
41	return fmt.Sprintf("git clone ssh://%s/%s", host+p, name)
42}