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	// ProjectName returns the repository's project name.
25	ProjectName(repo string) string
26	// SetProjectName sets the repository's project name.
27	SetProjectName(repo, name string) error
28	// Description returns the repository's description.
29	Description(repo string) string
30	// SetDescription sets the repository's description.
31	SetDescription(repo, desc string) error
32	// IsPrivate returns whether the repository is private.
33	IsPrivate(repo string) bool
34	// SetPrivate sets whether the repository is private.
35	SetPrivate(repo string, private bool) error
36}
37
38// RepositoryAccess is an interface for managing repository access.
39type RepositoryAccess interface {
40	// AccessLevel returns the access level for the given repository and key.
41	AccessLevel(repo string, pk ssh.PublicKey) AccessLevel
42	// IsCollaborator returns true if the authorized key is a collaborator on the repository.
43	IsCollaborator(pk ssh.PublicKey, repo string) bool
44	// AddCollaborator adds the authorized key as a collaborator on the repository.
45	AddCollaborator(pk ssh.PublicKey, memo string, repo string) error
46	// RemoveCollaborator removes the authorized key as a collaborator on the repository.
47	RemoveCollaborator(pk ssh.PublicKey, repo string) error
48	// Collaborators returns a list of all collaborators on the repository.
49	Collaborators(repo string) ([]string, error)
50	// IsAdmin returns true if the authorized key is an admin.
51	IsAdmin(pk ssh.PublicKey) bool
52	// AddAdmin adds the authorized key as an admin.
53	AddAdmin(pk ssh.PublicKey, memo string) error
54	// RemoveAdmin removes the authorized key as an admin.
55	RemoveAdmin(pk ssh.PublicKey) error
56	// Admins returns a list of all admins.
57	Admins() ([]string, error)
58}
59
60// Repository is a Git repository interface.
61type Repository interface {
62	// Name returns the repository's name.
63	Name() string
64	// ProjectName returns the repository's project name.
65	ProjectName() string
66	// Description returns the repository's description.
67	Description() string
68	// IsPrivate returns whether the repository is private.
69	IsPrivate() bool
70	// Open returns the underlying git.Repository.
71	Open() (*git.Repository, error)
72}