repo.go

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