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