Skip to content

Commit

Permalink
tui: make app config take server config
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Oct 13, 2021
1 parent 0db2ff2 commit 6427b1e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
29 changes: 15 additions & 14 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"os"
"path/filepath"

"github.com/charmbracelet/soft/config"
"github.com/charmbracelet/soft/internal/git"
"github.com/charmbracelet/soft/stats"
gg "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
)
Expand All @@ -24,7 +24,7 @@ type Config struct {
Users []User `yaml:"users"`
Repos []Repo `yaml:"repos"`
Source *git.RepoSource
Stats stats.Stats
Cfg *config.Config
}

type User struct {
Expand All @@ -41,19 +41,20 @@ type Repo struct {
Private bool `yaml:"private"`
}

func (cfg *Config) WithStats(s stats.Stats) *Config {
cfg.Stats = s
return cfg
}

func NewConfig(host string, port int, pk string, rs *git.RepoSource) (*Config, error) {
func NewConfig(cfg *config.Config) (*Config, error) {
var anonAccess string
var yamlUsers string
var displayHost string
cfg := &Config{}
cfg.Host = host
cfg.Port = port
cfg.Source = rs
host := cfg.Host
port := cfg.Port
pk := cfg.InitialAdminKey
rs := cfg.RepoSource
c := &Config{
Cfg: cfg,
}
c.Host = cfg.Host
c.Port = port
c.Source = rs
if pk == "" {
anonAccess = "read-write"
} else {
Expand All @@ -75,11 +76,11 @@ func NewConfig(host string, port int, pk string, rs *git.RepoSource) (*Config, e
yamlUsers = defaultUserConfig
}
yaml := fmt.Sprintf("%s%s%s", yamlConfig, yamlUsers, exampleUserConfig)
err := cfg.createDefaultConfigRepo(yaml)
err := c.createDefaultConfigRepo(yaml)
if err != nil {
return nil, err
}
return cfg, nil
return c, nil
}

func (cfg *Config) reload() error {
Expand Down
10 changes: 2 additions & 8 deletions internal/config/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@ import (
)

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)
}
if cfg.Stats != nil {
cfg.Stats.Push()
}
cfg.Cfg.Stats.Push(repo)
}

func (cfg *Config) Fetch(repo string, pk ssh.PublicKey) {
log.Printf("git fetch: %s", repo)
if cfg.Stats != nil {
cfg.Stats.Fetch()
}
cfg.Cfg.Stats.Fetch(repo)
}

func (cfg *Config) AuthRepo(repo string, pk ssh.PublicKey) gm.AccessLevel {
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/bubbles/commits/bubble.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package commits

import (
"soft-serve/server/git"
"strings"

"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/soft/internal/git"
"github.com/dustin/go-humanize"
)

Expand Down
4 changes: 1 addition & 3 deletions internal/tui/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ func SessionHandler(cfg *config.Config) func(ssh.Session) (tea.Model, []tea.Prog
}
scfg.Width = pty.Window.Width
scfg.Height = pty.Window.Height
if cfg.Stats != nil {
cfg.Stats.Tui()
}
cfg.Cfg.Stats.Tui("view")
return NewBubble(cfg, scfg), []tea.ProgramOption{tea.WithAltScreen()}
}
}

0 comments on commit 6427b1e

Please sign in to comment.