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}
33
34// RepositoryMetadata is an interface for managing repository metadata.
35type RepositoryMetadata interface {
36 // ProjectName returns the repository's project name.
37 ProjectName(repo string) (string, error)
38 // SetProjectName sets the repository's project name.
39 SetProjectName(repo, name string) error
40 // Description returns the repository's description.
41 Description(repo string) (string, error)
42 // SetDescription sets the repository's description.
43 SetDescription(repo, desc string) error
44 // IsPrivate returns whether the repository is private.
45 IsPrivate(repo string) (bool, error)
46 // SetPrivate sets whether the repository is private.
47 SetPrivate(repo string, private bool) error
48 // IsMirror returns whether the repository is a mirror.
49 IsMirror(repo string) (bool, error)
50 // IsHidden returns whether the repository is hidden.
51 IsHidden(repo string) (bool, error)
52 // SetHidden sets whether the repository is hidden.
53 SetHidden(repo string, hidden bool) error
54}
55
56// RepositoryAccess is an interface for managing repository access.
57type RepositoryAccess interface {
58 IsCollaborator(repo string, username string) (bool, error)
59 // AddCollaborator adds the authorized key as a collaborator on the repository.
60 AddCollaborator(repo string, username string) error
61 // RemoveCollaborator removes the authorized key as a collaborator on the repository.
62 RemoveCollaborator(repo string, username string) error
63 // Collaborators returns a list of all collaborators on the repository.
64 Collaborators(repo string) ([]string, error)
65}
66
67// Repository is a Git repository interface.
68type Repository interface {
69 // Name returns the repository's name.
70 Name() string
71 // ProjectName returns the repository's project name.
72 ProjectName() string
73 // Description returns the repository's description.
74 Description() string
75 // IsPrivate returns whether the repository is private.
76 IsPrivate() bool
77 // IsMirror returns whether the repository is a mirror.
78 IsMirror() bool
79 // IsHidden returns whether the repository is hidden.
80 IsHidden() bool
81 // UpdatedAt returns the time the repository was last updated.
82 // If the repository has never been updated, it returns the time it was created.
83 UpdatedAt() time.Time
84 // Open returns the underlying git.Repository.
85 Open() (*git.Repository, error)
86}