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	// CreateRepository creates a new repository.
15	CreateRepository(name string, private bool) (Repository, error)
16	// DeleteRepository deletes a repository.
17	DeleteRepository(name string) error
18	// RenameRepository renames a repository.
19	RenameRepository(oldName, newName string) error
20}
21
22// RepositoryMetadata is an interface for managing repository metadata.
23type RepositoryMetadata interface {
24	// Description returns the repository's description.
25	Description(repo string) string
26	// SetDescription sets the repository's description.
27	SetDescription(repo, desc string) error
28	// IsPrivate returns whether the repository is private.
29	IsPrivate(repo string) bool
30	// SetPrivate sets whether the repository is private.
31	SetPrivate(repo string, private bool) error
32}
33
34// RepositoryAccess is an interface for managing repository access.
35type RepositoryAccess interface {
36	// IsCollaborator returns true if the authorized key is a collaborator on the repository.
37	IsCollaborator(pk ssh.PublicKey, repo string) bool
38	// AddCollaborator adds the authorized key as a collaborator on the repository.
39	AddCollaborator(pk ssh.PublicKey, memo string, repo string) error
40	// RemoveCollaborator removes the authorized key as a collaborator on the repository.
41	RemoveCollaborator(pk ssh.PublicKey, repo string) error
42	// Collaborators returns a list of all collaborators on the repository.
43	Collaborators(repo string) ([]string, error)
44	// IsAdmin returns true if the authorized key is an admin.
45	IsAdmin(pk ssh.PublicKey) bool
46	// AddAdmin adds the authorized key as an admin.
47	AddAdmin(pk ssh.PublicKey, memo string) error
48	// RemoveAdmin removes the authorized key as an admin.
49	RemoveAdmin(pk ssh.PublicKey) error
50	// Admins returns a list of all admins.
51	Admins() ([]string, error)
52}
53
54// Repository is a Git repository interface.
55type Repository interface {
56	// Name returns the repository's name.
57	Name() string
58	// Description returns the repository's description.
59	Description() string
60	// IsPrivate returns whether the repository is private.
61	IsPrivate() bool
62	// Open returns the underlying git.Repository.
63	Open() (*git.Repository, error)
64}