repos / git-pr

a self-hosted git collaboration server
git clone https://github.com/picosh/git-pr.git

commit
961b2fb
parent
200f134
author
Eric Bower
date
2024-07-10 14:07:59 -0400 EDT
refactor: data -> data_dir
6 files changed,  +48, -11
M cfg.go
M ssh.go
M web.go
M README.md
+39, -2
 1@@ -145,15 +145,52 @@ then remove them in subsequent patches. This is the forcing function to address
 2 all comments: the patch won't be merged if there are comment unaddressed in
 3 code; they cannot be ignored or else they will be upstreamed erroneously.
 4 
 5+# installation and setup
 6+
 7+Copy or create a `git-pr.toml` file inside `./data` directory:
 8+
 9+```bash
10+mkdir data
11+vim ./data/git-pr.toml
12+# configure file
13+```
14+
15+Run the ssh app image:
16+
17+```bash
18+docker run -d -v ./data:/app/data \
19+  --name git-pr-ssh \
20+  ghcr.io/picosh/pico/git-ssh:latest
21+```
22+
23+Run the web app image:
24+
25+```bash
26+docker run -d -v ./data:/app/data \
27+  --name git-pr-web \
28+  ghcr.io/picosh/pico/git-web:latest
29+```
30+
31+Access the ssh app:
32+
33+```bash
34+ssh -p 2222 localhost help
35+```
36+
37+Access the web app:
38+
39+```bash
40+curl localhost:3000
41+```
42+
43 # roadmap
44 
45 > [!IMPORTANT]\
46 > This project is being actively developed and we have not reached alpha status
47 > yet.
48 
49-1. Support user providing a config file
50-1. PR should be displayed as an event log
51 1. Guide for self-hosting `git-pr`
52+1. PR should be displayed as an event log
53 1. **Alpha status**
54 1. Git remote for repos
55 1. PR build steps (e.g. check that a patch can be cleanly applied)
M backend.go
+1, -1
1@@ -18,7 +18,7 @@ type Backend struct {
2 }
3 
4 func (be *Backend) ReposDir() string {
5-	return filepath.Join(be.Cfg.DataPath, "repos")
6+	return filepath.Join(be.Cfg.DataDir, "repos")
7 }
8 
9 func (be *Backend) RepoName(id string) string {
M cfg.go
+4, -4
 1@@ -22,7 +22,7 @@ type Repo struct {
 2 var k = koanf.New(".")
 3 
 4 type GitCfg struct {
 5-	DataPath  string          `koanf:"data"`
 6+	DataDir   string          `koanf:"data_dir"`
 7 	Repos     []*Repo         `koanf:"repo"`
 8 	Url       string          `koanf:"url"`
 9 	Host      string          `koanf:"host"`
10@@ -66,8 +66,8 @@ func NewGitCfg(fpath string, logger *slog.Logger) *GitCfg {
11 		logger.Info("no admin specified in config so no one can submit a review!")
12 	}
13 
14-	if out.DataPath == "" {
15-		out.DataPath = "data"
16+	if out.DataDir == "" {
17+		out.DataDir = "data"
18 	}
19 
20 	if out.Host == "" {
21@@ -89,7 +89,7 @@ func NewGitCfg(fpath string, logger *slog.Logger) *GitCfg {
22 	logger.Info(
23 		"config",
24 		"url", out.Url,
25-		"data", out.DataPath,
26+		"data_dir", out.DataDir,
27 		"host", out.Host,
28 		"ssh_port", out.SshPort,
29 		"web_port", out.WebPort,
M git-pr.toml
+1, -1
1@@ -1,5 +1,5 @@
2 url = "pr.pico.sh"
3-data = "data"
4+data_dir = "./data"
5 admins = [
6   "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHM2RPNgcyt+Tpb77uj0oQYZWLadfB8x8mqJFy0C7Y8P",
7   "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINlr0pScstAuTqs9Qr1KaMspHuFGO7cQMuvMMdJjbWG3"
M ssh.go
+2, -2
 1@@ -32,7 +32,7 @@ func authHandler(pr *PrCmd) func(ctx ssh.Context, key ssh.PublicKey) bool {
 2 }
 3 
 4 func GitSshServer(cfg *GitCfg) {
 5-	dbh, err := Open(filepath.Join(cfg.DataPath, "pr.db"), cfg.Logger)
 6+	dbh, err := Open(filepath.Join(cfg.DataDir, "pr.db"), cfg.Logger)
 7 	if err != nil {
 8 		panic(err)
 9 	}
10@@ -51,7 +51,7 @@ func GitSshServer(cfg *GitCfg) {
11 			fmt.Sprintf("%s:%s", cfg.Host, cfg.SshPort),
12 		),
13 		wish.WithHostKeyPath(
14-			filepath.Join(cfg.DataPath, "term_info_ed25519"),
15+			filepath.Join(cfg.DataDir, "term_info_ed25519"),
16 		),
17 		wish.WithPublicKeyAuth(authHandler(prCmd)),
18 		wish.WithMiddleware(
M web.go
+1, -1
1@@ -485,7 +485,7 @@ func chromaStyleHandler(w http.ResponseWriter, r *http.Request) {
2 func StartWebServer(cfg *GitCfg) {
3 	addr := fmt.Sprintf("%s:%s", cfg.Host, cfg.WebPort)
4 
5-	dbh, err := Open(filepath.Join(cfg.DataPath, "pr.db"), cfg.Logger)
6+	dbh, err := Open(filepath.Join(cfg.DataDir, "pr.db"), cfg.Logger)
7 	if err != nil {
8 		cfg.Logger.Error("could not open db", "err", err)
9 		return