6427b1e64a146047ced3c829a3b877b8d191f642

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

tui: make app config take server config

Diff

  1diff --git a/internal/config/config.go b/internal/config/config.go
  2index cd71ee9f35a6fb761655ebea18aea1eba1fd8fde..741c7a625463939b78e28449680328d4b519e3f5 100644
  3--- a/internal/config/config.go
  4+++ b/internal/config/config.go
  5@@ -9,8 +9,8 @@ import (
  6 	"os"
  7 	"path/filepath"
  8 
  9+	"github.com/charmbracelet/soft/config"
 10 	"github.com/charmbracelet/soft/internal/git"
 11-	"github.com/charmbracelet/soft/stats"
 12 	gg "github.com/go-git/go-git/v5"
 13 	"github.com/go-git/go-git/v5/plumbing/object"
 14 )
 15@@ -24,7 +24,7 @@ type Config struct {
 16 	Users        []User `yaml:"users"`
 17 	Repos        []Repo `yaml:"repos"`
 18 	Source       *git.RepoSource
 19-	Stats        stats.Stats
 20+	Cfg          *config.Config
 21 }
 22 
 23 type User struct {
 24@@ -41,19 +41,20 @@ type Repo struct {
 25 	Private bool   `yaml:"private"`
 26 }
 27 
 28-func (cfg *Config) WithStats(s stats.Stats) *Config {
 29-	cfg.Stats = s
 30-	return cfg
 31-}
 32-
 33-func NewConfig(host string, port int, pk string, rs *git.RepoSource) (*Config, error) {
 34+func NewConfig(cfg *config.Config) (*Config, error) {
 35 	var anonAccess string
 36 	var yamlUsers string
 37 	var displayHost string
 38-	cfg := &Config{}
 39-	cfg.Host = host
 40-	cfg.Port = port
 41-	cfg.Source = rs
 42+	host := cfg.Host
 43+	port := cfg.Port
 44+	pk := cfg.InitialAdminKey
 45+	rs := cfg.RepoSource
 46+	c := &Config{
 47+		Cfg: cfg,
 48+	}
 49+	c.Host = cfg.Host
 50+	c.Port = port
 51+	c.Source = rs
 52 	if pk == "" {
 53 		anonAccess = "read-write"
 54 	} else {
 55@@ -75,11 +76,11 @@ func NewConfig(host string, port int, pk string, rs *git.RepoSource) (*Config, e
 56 		yamlUsers = defaultUserConfig
 57 	}
 58 	yaml := fmt.Sprintf("%s%s%s", yamlConfig, yamlUsers, exampleUserConfig)
 59-	err := cfg.createDefaultConfigRepo(yaml)
 60+	err := c.createDefaultConfigRepo(yaml)
 61 	if err != nil {
 62 		return nil, err
 63 	}
 64-	return cfg, nil
 65+	return c, nil
 66 }
 67 
 68 func (cfg *Config) reload() error {
 69diff --git a/internal/config/git.go b/internal/config/git.go
 70index 40ded971a90e5920b14e522dafc0fcf80931d4ae..845c2fb8ac724e89c4e018b8b59dfb493e069f4f 100644
 71--- a/internal/config/git.go
 72+++ b/internal/config/git.go
 73@@ -9,21 +9,15 @@ import (
 74 )
 75 
 76 func (cfg *Config) Push(repo string, pk ssh.PublicKey) {
 77-	log.Printf("git push: %s", repo)
 78 	err := cfg.reload()
 79 	if err != nil {
 80 		log.Printf("error reloading after push: %s", err)
 81 	}
 82-	if cfg.Stats != nil {
 83-		cfg.Stats.Push()
 84-	}
 85+	cfg.Cfg.Stats.Push(repo)
 86 }
 87 
 88 func (cfg *Config) Fetch(repo string, pk ssh.PublicKey) {
 89-	log.Printf("git fetch: %s", repo)
 90-	if cfg.Stats != nil {
 91-		cfg.Stats.Fetch()
 92-	}
 93+	cfg.Cfg.Stats.Fetch(repo)
 94 }
 95 
 96 func (cfg *Config) AuthRepo(repo string, pk ssh.PublicKey) gm.AccessLevel {
 97diff --git a/internal/tui/bubbles/commits/bubble.go b/internal/tui/bubbles/commits/bubble.go
 98index 662304a117acbd52503139274e01848e65938921..205daa701d116d77ea01a7bc98e0866f27c3f6dc 100644
 99--- a/internal/tui/bubbles/commits/bubble.go
100+++ b/internal/tui/bubbles/commits/bubble.go
101@@ -1,11 +1,11 @@
102 package commits
103 
104 import (
105-	"soft-serve/server/git"
106 	"strings"
107 
108 	"github.com/charmbracelet/bubbles/viewport"
109 	tea "github.com/charmbracelet/bubbletea"
110+	"github.com/charmbracelet/soft/internal/git"
111 	"github.com/dustin/go-humanize"
112 )
113 
114diff --git a/internal/tui/session.go b/internal/tui/session.go
115index 8bdd5c5d5b56ac7f409f9d4f897848c626914346..9f3cb3951a50858c77effd85fc2f9d4049e18a92 100644
116--- a/internal/tui/session.go
117+++ b/internal/tui/session.go
118@@ -27,9 +27,7 @@ func SessionHandler(cfg *config.Config) func(ssh.Session) (tea.Model, []tea.Prog
119 		}
120 		scfg.Width = pty.Window.Width
121 		scfg.Height = pty.Window.Height
122-		if cfg.Stats != nil {
123-			cfg.Stats.Tui()
124-		}
125+		cfg.Cfg.Stats.Tui("view")
126 		return NewBubble(cfg, scfg), []tea.ProgramOption{tea.WithAltScreen()}
127 	}
128 }