1package proto
2
3import (
4 "time"
5
6 "github.com/charmbracelet/soft-serve/git"
7)
8
9// Repository is a Git repository interface.
10type Repository interface {
11 // ID returns the repository's ID.
12 ID() int64
13 // Name returns the repository's name.
14 Name() string
15 // ProjectName returns the repository's project name.
16 ProjectName() string
17 // Description returns the repository's description.
18 Description() string
19 // IsPrivate returns whether the repository is private.
20 IsPrivate() bool
21 // IsMirror returns whether the repository is a mirror.
22 IsMirror() bool
23 // IsHidden returns whether the repository is hidden.
24 IsHidden() bool
25 // UserID returns the ID of the user who owns the repository.
26 // It returns 0 if the repository is not owned by a user.
27 UserID() int64
28 // CreatedAt returns the time the repository was created.
29 CreatedAt() time.Time
30 // UpdatedAt returns the time the repository was last updated.
31 // If the repository has never been updated, it returns the time it was created.
32 UpdatedAt() time.Time
33 // Open returns the underlying git.Repository.
34 Open() (*git.Repository, error)
35}
36
37// RepositoryOptions are options for creating a new repository.
38type RepositoryOptions struct {
39 Private bool
40 Description string
41 ProjectName string
42 Mirror bool
43 Hidden bool
44 LFS bool
45 LFSEndpoint string
46}
47
48// RepositoryDefaultBranch returns the default branch of a repository.
49func RepositoryDefaultBranch(repo Repository) (string, error) {
50 r, err := repo.Open()
51 if err != nil {
52 return "", err //nolint:wrapcheck
53 }
54
55 ref, err := r.HEAD()
56 if err != nil {
57 return "", err //nolint:wrapcheck
58 }
59
60 return ref.Name().Short(), nil
61}