Skip to content

Commit

Permalink
Implement GitHooks, fix collab repos
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Padilla committed Oct 4, 2021
1 parent e198dc4 commit 61d135d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 1 addition & 11 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package config

import (
"log"

"gopkg.in/yaml.v2"

"fmt"
"os"
"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"
)
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions config/auth.go → config/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
)
Expand Down

0 comments on commit 61d135d

Please sign in to comment.