repo.go

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