Implement GitHooks, fix collab repos

Toby Padilla created

Change summary

config/config.go | 12 +-----------
config/git.go    | 12 ++++++++++++
main.go          |  2 +-
3 files changed, 14 insertions(+), 12 deletions(-)

Detailed changes

config/config.go 🔗

@@ -1,8 +1,6 @@
 package config
 
 import (
-	"log"
-
 	"gopkg.in/yaml.v2"
 
 	"fmt"
@@ -10,7 +8,6 @@ import (
 	"path/filepath"
 	"soft-serve/git"
 
-	"github.com/gliderlabs/ssh"
 	gg "github.com/go-git/go-git/v5"
 	"github.com/go-git/go-git/v5/plumbing/object"
 )
@@ -30,7 +27,7 @@ type User struct {
 	Name        string   `yaml:"name"`
 	Admin       bool     `yaml:"admin"`
 	PublicKey   string   `yaml:"public-key"`
-	CollabRepos []string `yaml:"collab_repos"`
+	CollabRepos []string `yaml:"collab-repos"`
 }
 
 type Repo struct {
@@ -71,13 +68,6 @@ func NewConfig(host string, port int, pk string, rs *git.RepoSource) (*Config, e
 	return cfg, nil
 }
 
-func (cfg *Config) Pushed(repo string, pk ssh.PublicKey) {
-	err := cfg.reload()
-	if err != nil {
-		log.Printf("error reloading after push: %s", err)
-	}
-}
-
 func (cfg *Config) reload() error {
 	err := cfg.Source.LoadRepos()
 	if err != nil {

config/auth.go → config/git.go 🔗

@@ -7,6 +7,18 @@ import (
 	"github.com/gliderlabs/ssh"
 )
 
+func (cfg *Config) Push(repo string, pk ssh.PublicKey) {
+	log.Printf("git push: %s", repo)
+	err := cfg.reload()
+	if err != nil {
+		log.Printf("error reloading after push: %s", err)
+	}
+}
+
+func (cfg *Config) Fetch(repo string, pk ssh.PublicKey) {
+	log.Printf("git fetch: %s", repo)
+}
+
 func (cfg *Config) AuthRepo(repo string, pk ssh.PublicKey) gm.AccessLevel {
 	return cfg.accessForKey(repo, pk)
 }

main.go 🔗

@@ -44,7 +44,7 @@ func main() {
 		wish.WithHostKeyPath(scfg.KeyPath),
 		wish.WithMiddlewares(
 			bm.Middleware(tui.SessionHandler(cfg)),
-			gm.MiddlewareWithPushCallback(scfg.RepoPath, cfg, cfg.Pushed),
+			gm.Middleware(scfg.RepoPath, cfg),
 			lm.Middleware(),
 		),
 	)