3b51af4708317a060a77b59cbeb1ec132e6a0538

Author
Christian Rocha <christian@rocha.is>
Committer
Christian Rocha <christian@rocha.is>
Date

Message

Add some missing godocs

Diff

  1diff --git a/cmd/soft/main.go b/cmd/soft/main.go
  2index a25e5618add65e0ce2e04d9b64719dbfa2933a63..f7ea656fe02c4e946e9a4f6a7943c78af9273726 100644
  3--- a/cmd/soft/main.go
  4+++ b/cmd/soft/main.go
  5@@ -11,7 +11,12 @@ import (
  6 )
  7 
  8 var (
  9-	Version   = ""
 10+	// Version contains the application version number. It's set via ldflags
 11+	// when building.
 12+	Version = ""
 13+
 14+	// CommitSHA contains the SHA of the commit that this application was built
 15+	// against. It's set via lgflags when building.
 16 	CommitSHA = ""
 17 
 18 	version = flag.Bool("version", false, "display version")
 19diff --git a/config/config.go b/config/config.go
 20index 897bd014d532823ee9f431f21a806aaec53b3320..0a28e783f2bbfc5d7f23edc3f4f00b02464426f1 100644
 21--- a/config/config.go
 22+++ b/config/config.go
 23@@ -13,7 +13,7 @@ type Callbacks interface {
 24 	Fetch(repo string)
 25 }
 26 
 27-// Config is the configuration for the soft-serve.
 28+// Config is the configuration for Soft Serve.
 29 type Config struct {
 30 	Host            string `env:"SOFT_SERVE_HOST" default:""`
 31 	Port            int    `env:"SOFT_SERVE_PORT" default:"23231"`
 32@@ -34,6 +34,7 @@ func DefaultConfig() *Config {
 33 	return scfg.WithCallbacks(nil)
 34 }
 35 
 36+// WithCallbacks applies the given Callbacks to the configuration.
 37 func (cfg *Config) WithCallbacks(c Callbacks) *Config {
 38 	cfg.Callbacks = c
 39 	return cfg
 40diff --git a/internal/config/config.go b/internal/config/config.go
 41index 21a22b33d4589a24eaf3dc2c1d1fc04e385e8ab4..c43e0a424d78eba2fdee060b062aa1d61fd6eb74 100644
 42--- a/internal/config/config.go
 43+++ b/internal/config/config.go
 44@@ -16,6 +16,7 @@ import (
 45 	"github.com/go-git/go-git/v5/plumbing/object"
 46 )
 47 
 48+// Config is the Soft Serve configuration.
 49 type Config struct {
 50 	Name         string `yaml:"name"`
 51 	Host         string `yaml:"host"`
 52@@ -28,6 +29,7 @@ type Config struct {
 53 	Cfg          *config.Config
 54 }
 55 
 56+// User contains user-level configuration for a repository.
 57 type User struct {
 58 	Name        string   `yaml:"name"`
 59 	Admin       bool     `yaml:"admin"`
 60@@ -35,6 +37,7 @@ type User struct {
 61 	CollabRepos []string `yaml:"collab-repos"`
 62 }
 63 
 64+// Repo contains repository configuration information.
 65 type Repo struct {
 66 	Name    string `yaml:"name"`
 67 	Repo    string `yaml:"repo"`
 68@@ -42,6 +45,7 @@ type Repo struct {
 69 	Private bool   `yaml:"private"`
 70 }
 71 
 72+// NewConfig creates a new internal Config struct.
 73 func NewConfig(cfg *config.Config) (*Config, error) {
 74 	var anonAccess string
 75 	var yamlUsers string
 76@@ -84,6 +88,7 @@ func NewConfig(cfg *config.Config) (*Config, error) {
 77 	return c, nil
 78 }
 79 
 80+// Reload reloads the configuration.
 81 func (cfg *Config) Reload() error {
 82 	err := cfg.Source.LoadRepos()
 83 	if err != nil {
 84diff --git a/internal/config/git.go b/internal/config/git.go
 85index b1a46e17307a4c0a4fb85342c02e0a7e8672dd7c..063a098d3cbfbb842783c80fcffe8318c426dad6 100644
 86--- a/internal/config/git.go
 87+++ b/internal/config/git.go
 88@@ -8,6 +8,7 @@ import (
 89 	"github.com/gliderlabs/ssh"
 90 )
 91 
 92+// Push registers Git push functionality for the given repo and key.
 93 func (cfg *Config) Push(repo string, pk ssh.PublicKey) {
 94 	err := cfg.Reload()
 95 	if err != nil {
 96@@ -18,20 +19,25 @@ func (cfg *Config) Push(repo string, pk ssh.PublicKey) {
 97 	}
 98 }
 99 
100+// Fetch registers Git fetch functionality for the given repo and key.
101 func (cfg *Config) Fetch(repo string, pk ssh.PublicKey) {
102 	if cfg.Cfg.Callbacks != nil {
103 		cfg.Cfg.Callbacks.Fetch(repo)
104 	}
105 }
106 
107+// AuthRepo grants repo authorization to the given key.
108 func (cfg *Config) AuthRepo(repo string, pk ssh.PublicKey) gm.AccessLevel {
109 	return cfg.accessForKey(repo, pk)
110 }
111 
112+// PasswordHandler returns whether or not password access is allowed.
113 func (cfg *Config) PasswordHandler(ctx ssh.Context, password string) bool {
114 	return (cfg.AnonAccess != "no-access") && cfg.AllowKeyless
115 }
116 
117+// PublicKeyHandler returns whether or not the given public key may access the
118+// repo.
119 func (cfg *Config) PublicKeyHandler(ctx ssh.Context, pk ssh.PublicKey) bool {
120 	return cfg.accessForKey("", pk) != gm.NoAccess
121 }
122diff --git a/internal/git/git.go b/internal/git/git.go
123index 66a7c7bcca49ac7130eb2a7279c2f93f3b891251..936cf080cac33e780cf487639679b0b7fc1b2f5e 100644
124--- a/internal/git/git.go
125+++ b/internal/git/git.go
126@@ -16,8 +16,10 @@ import (
127 	"github.com/go-git/go-git/v5/storage/memory"
128 )
129 
130+// ErrMissingRepo indicates that the requested repository could not be found.
131 var ErrMissingRepo = errors.New("missing repo")
132 
133+// Repo represents a Git repository.
134 type Repo struct {
135 	Name        string
136 	Repository  *git.Repository
137@@ -25,11 +27,13 @@ type Repo struct {
138 	LastUpdated *time.Time
139 }
140 
141+// RepoCommit contains metadata for a Git commit.
142 type RepoCommit struct {
143 	Name   string
144 	Commit *object.Commit
145 }
146 
147+// CommitLog is a series of Git commits.
148 type CommitLog []RepoCommit
149 
150 func (cl CommitLog) Len() int      { return len(cl) }
151@@ -38,6 +42,7 @@ func (cl CommitLog) Less(i, j int) bool {
152 	return cl[i].Commit.Author.When.After(cl[j].Commit.Author.When)
153 }
154 
155+// RepoSource is a reference to an on-disk repositories.
156 type RepoSource struct {
157 	Path    string
158 	mtx     sync.Mutex
159@@ -45,6 +50,7 @@ type RepoSource struct {
160 	commits CommitLog
161 }
162 
163+// NewRepoSource creates a new RepoSource.
164 func NewRepoSource(repoPath string) *RepoSource {
165 	err := os.MkdirAll(repoPath, os.ModeDir|os.FileMode(0700))
166 	if err != nil {
167@@ -54,12 +60,14 @@ func NewRepoSource(repoPath string) *RepoSource {
168 	return rs
169 }
170 
171+// AllRepos returns all repositories for the given RepoSource.
172 func (rs *RepoSource) AllRepos() []*Repo {
173 	rs.mtx.Lock()
174 	defer rs.mtx.Unlock()
175 	return rs.repos
176 }
177 
178+// GetRepo returns a repository by name.
179 func (rs *RepoSource) GetRepo(name string) (*Repo, error) {
180 	rs.mtx.Lock()
181 	defer rs.mtx.Unlock()
182@@ -71,6 +79,7 @@ func (rs *RepoSource) GetRepo(name string) (*Repo, error) {
183 	return nil, ErrMissingRepo
184 }
185 
186+// InitRepo initializes a new Git repository.
187 func (rs *RepoSource) InitRepo(name string, bare bool) (*Repo, error) {
188 	rs.mtx.Lock()
189 	defer rs.mtx.Unlock()
190@@ -97,6 +106,7 @@ func (rs *RepoSource) InitRepo(name string, bare bool) (*Repo, error) {
191 	return r, nil
192 }
193 
194+// GetCommits returns commits for the repository.
195 func (rs *RepoSource) GetCommits(limit int) []RepoCommit {
196 	rs.mtx.Lock()
197 	defer rs.mtx.Unlock()
198@@ -106,6 +116,7 @@ func (rs *RepoSource) GetCommits(limit int) []RepoCommit {
199 	return rs.commits[:limit]
200 }
201 
202+// LoadRepos opens Git repositories.
203 func (rs *RepoSource) LoadRepos() error {
204 	rs.mtx.Lock()
205 	defer rs.mtx.Unlock()
206@@ -158,6 +169,7 @@ func (rs *RepoSource) loadRepo(name string, rg *git.Repository) (*Repo, error) {
207 	return r, nil
208 }
209 
210+// LatestFile returns the latest file at the specified path in the repository.
211 func (r *Repo) LatestFile(path string) (string, error) {
212 	lg, err := r.Repository.Log(&git.LogOptions{})
213 	if err != nil {
214diff --git a/internal/tui/style/style.go b/internal/tui/style/style.go
215index 9377fb0e3b78256023147b396ab9adbfd20c9f69..ec09bd832dbd1cba88d8abdb3f69666e0c57ba75 100644
216--- a/internal/tui/style/style.go
217+++ b/internal/tui/style/style.go
218@@ -7,6 +7,7 @@ import (
219 // XXX: For now, this is in its own package so that it can be shared between
220 // different packages without incurring an illegal import cycle.
221 
222+// Styles defines styles for the TUI.
223 type Styles struct {
224 	ActiveBorderColor   lipgloss.Color
225 	InactiveBorderColor lipgloss.Color
226@@ -39,6 +40,7 @@ type Styles struct {
227 	ErrorBody  lipgloss.Style
228 }
229 
230+// DefaultStyles returns default styles for the TUI.
231 func DefaultStyles() *Styles {
232 	s := new(Styles)
233 
234diff --git a/server/server.go b/server/server.go
235index 684a6048fa280d3b40abd674bddfbfa65d870634..e7ab0cf23e23fd31119af8569ecc473df9c1960a 100644
236--- a/server/server.go
237+++ b/server/server.go
238@@ -15,6 +15,7 @@ import (
239 	"github.com/gliderlabs/ssh"
240 )
241 
242+// Server is the Soft Serve server.
243 type Server struct {
244 	SSHServer *ssh.Server
245 	Config    *config.Config
246@@ -53,10 +54,12 @@ func NewServer(cfg *config.Config) *Server {
247 	}
248 }
249 
250+// Reload reloads the server configuration.
251 func (srv *Server) Reload() error {
252 	return srv.config.Reload()
253 }
254 
255+// Start starts the SSH server.
256 func (srv *Server) Start() error {
257 	return srv.SSHServer.ListenAndServe()
258 }