1package backend
 2
 3import (
 4	"github.com/charmbracelet/soft-serve/git"
 5	"golang.org/x/crypto/ssh"
 6)
 7
 8// RepositoryStore is an interface for managing repositories.
 9type RepositoryStore interface {
10	// Repository finds the given repository.
11	Repository(repo string) (Repository, error)
12	// Repositories returns a list of all repositories.
13	Repositories() ([]Repository, error)
14	// RepositoryStorePath returns the path to the repository store.
15	RepositoryStorePath() string
16	// CreateRepository creates a new repository.
17	CreateRepository(name string, private bool) (Repository, error)
18	// DeleteRepository deletes a repository.
19	DeleteRepository(name string) error
20	// RenameRepository renames a repository.
21	RenameRepository(oldName, newName string) error
22}
23
24// RepositoryMetadata is an interface for managing repository metadata.
25type RepositoryMetadata interface {
26	// Description returns the repository's description.
27	Description(repo string) string
28	// SetDescription sets the repository's description.
29	SetDescription(repo, desc string) error
30	// IsPrivate returns whether the repository is private.
31	IsPrivate(repo string) bool
32	// SetPrivate sets whether the repository is private.
33	SetPrivate(repo string, private bool) error
34}
35
36// RepositoryAccess is an interface for managing repository access.
37type RepositoryAccess interface {
38	// IsCollaborator returns true if the authorized key is a collaborator on the repository.
39	IsCollaborator(pk ssh.PublicKey, repo string) bool
40	// AddCollaborator adds the authorized key as a collaborator on the repository.
41	AddCollaborator(pk ssh.PublicKey, memo string, repo string) error
42	// RemoveCollaborator removes the authorized key as a collaborator on the repository.
43	RemoveCollaborator(pk ssh.PublicKey, repo string) error
44	// Collaborators returns a list of all collaborators on the repository.
45	Collaborators(repo string) ([]string, error)
46	// IsAdmin returns true if the authorized key is an admin.
47	IsAdmin(pk ssh.PublicKey) bool
48	// AddAdmin adds the authorized key as an admin.
49	AddAdmin(pk ssh.PublicKey, memo string) error
50	// RemoveAdmin removes the authorized key as an admin.
51	RemoveAdmin(pk ssh.PublicKey) error
52	// Admins returns a list of all admins.
53	Admins() ([]string, error)
54}
55
56// Repository is a Git repository interface.
57type Repository interface {
58	// Name returns the repository's name.
59	Name() string
60	// Description returns the repository's description.
61	Description() string
62	// IsPrivate returns whether the repository is private.
63	IsPrivate() bool
64	// Open returns the underlying git.Repository.
65	Open() (*git.Repository, error)
66}