dashboard / erock/pico / feat: private obj store service #13 rss

closed · opened on 2024-08-18T15:28:14Z by erock
Help
checkout latest patchset:
ssh pr.pico.sh print pr-13 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print ps-X | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 13
add review to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add --review 13
accept PR:
ssh pr.pico.sh pr accept 13
close PR:
ssh pr.pico.sh pr close 13

Logs

jolheiser created pr with ps-21 on 2024-07-22T18:12:32Z
erock added ps-24 on 2024-07-22T18:36:17Z
erock changed status on 2024-07-22T18:36:17Z {"status":"accepted"}

Patchsets

ps-21 by jolheiser on 2024-07-22T18:12:32Z
Range Diff ↕ rd-24
-: ------- > 1: 605c47b nice!
1: be8edcf = 2: 605c47b contrib: add dev script
ps-24 by erock on 2024-07-22T18:36:17Z

Patchset ps-24

REVIEW nice!

Eric Bower
2024-07-22T18:33:12Z

contrib: add dev script

jolheiser
2024-07-22T18:05:39Z
Back to top

nice!

Since you mentioned automated testing, I wonder if we could incorporate this into CI?

jolheiser (1):
  contrib: add dev script

 contrib/dev/README.md |  12 +++
 contrib/dev/main.go   | 203 ++++++++++++++++++++++++++++++++++++++++++
 fixtures/fixtures.go  |   6 ++
 3 files changed, 221 insertions(+)
 create mode 100644 contrib/dev/README.md
 create mode 100644 contrib/dev/main.go
 create mode 100644 fixtures/fixtures.go

base-commit: 31fcd4a1f446368c4f1db8427282ee0222962f1f
--
2.45.2

contrib: add dev script

This patch adds a fairly contained dev script that almost doubles as an integration test if you squint hard enough.
It runs an isolated instance that we can add more things to, it at least seems handy to me for quickly testing how changes affect e.g. the web UI, RSS feed, etc.

Signed-off-by: jolheiser <git@jolheiser.com>
contrib/dev/README.md link
+12 -0
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
diff --git a/contrib/dev/README.md b/contrib/dev/README.md
new file mode 100644
index 0000000..9ad8950
--- /dev/null
+++ b/contrib/dev/README.md
@@ -0,0 +1,12 @@
+# dev script
+
+`go run ./contrib/dev/`
+
+If you want to instead use this to bootstrap:
+
+1. `go run ./contrib/dev/ --cleanup=false`
+2. Note the tmp dir printed out
+3. Stop the program `Ctrl+C`
+4. Modify as needed within the tmp dir
+5. Run `git-dir` and point at the config contained within the tmp dir
+6. Remember to clean up the tmp dir yourself when finished
contrib/dev/main.go link
+203 -0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
diff --git a/contrib/dev/main.go b/contrib/dev/main.go
new file mode 100644
index 0000000..088e8cf
--- /dev/null
+++ b/contrib/dev/main.go
@@ -0,0 +1,203 @@
+package main
+
+import (
+	"crypto/ed25519"
+	"crypto/rand"
+	"flag"
+	"fmt"
+	"log/slog"
+	"os"
+	"os/signal"
+	"path/filepath"
+	"time"
+
+	"github.com/picosh/git-pr"
+	"github.com/picosh/git-pr/fixtures"
+	"golang.org/x/crypto/ssh"
+)
+
+func main() {
+	cleanupFlag := flag.Bool("cleanup", true, "Clean up tmp dir after quitting (default: true)")
+	flag.Parse()
+
+	tmp, err := os.MkdirTemp(os.TempDir(), "git-pr*")
+	if err != nil {
+		panic(err)
+	}
+	defer func() {
+		if *cleanupFlag {
+			os.RemoveAll(tmp)
+		}
+	}()
+	fmt.Println(tmp)
+
+	adminKey, userKey := generateKeys()
+
+	cfgPath := filepath.Join(tmp, "git-pr.toml")
+	cfgFi, err := os.Create(cfgPath)
+	if err != nil {
+		panic(err)
+	}
+	cfgFi.WriteString(fmt.Sprintf(cfgTmpl, tmp, adminKey.public()))
+	cfgFi.Close()
+
+	opts := &slog.HandlerOptions{
+		AddSource: true,
+	}
+	logger := slog.New(
+		slog.NewTextHandler(os.Stdout, opts),
+	)
+	cfg := git.NewGitCfg(cfgPath, logger)
+	go git.GitSshServer(cfg)
+	time.Sleep(time.Second)
+	go git.StartWebServer(cfg)
+
+	// Hack to wait for startup
+	time.Sleep(time.Second)
+
+	patch, err := fixtures.Fixtures.ReadFile("single.patch")
+	if err != nil {
+		panic(err)
+	}
+	otherPatch, err := fixtures.Fixtures.ReadFile("with-cover.patch")
+	if err != nil {
+		panic(err)
+	}
+
+	// Accepted patch
+	userKey.cmd(patch, "pr create test")
+	userKey.cmd(nil, "pr edit 1 Accepted patch")
+	adminKey.cmd(nil, "pr accept 1")
+
+	// Closed patch (admin)
+	userKey.cmd(patch, "pr create test")
+	userKey.cmd(nil, "pr edit 2 Closed patch (admin)")
+	adminKey.cmd(nil, "pr close 2")
+
+	// Closed patch (contributor)
+	userKey.cmd(patch, "pr create test")
+	userKey.cmd(nil, "pr edit 3 Closed patch (contributor)")
+	userKey.cmd(nil, "pr close 3")
+
+	// Reviewed patch
+	userKey.cmd(patch, "pr create test")
+	userKey.cmd(nil, "pr edit 4 Reviewed patch")
+	adminKey.cmd(otherPatch, "pr add --review 4")
+
+	// Accepted patch with review
+	userKey.cmd(patch, "pr create test")
+	userKey.cmd(nil, "pr edit 5 Accepted patch with review")
+	adminKey.cmd(otherPatch, "pr add --accept 5")
+
+	// Closed patch with review
+	userKey.cmd(patch, "pr create test")
+	userKey.cmd(nil, "pr edit 6 Closed patch with review")
+	adminKey.cmd(otherPatch, "pr add --close 6")
+
+	fmt.Println("time to do some testing...")
+	ch := make(chan os.Signal, 1)
+	signal.Notify(ch, os.Interrupt, os.Kill)
+	<-ch
+}
+
+type sshKey struct {
+	username string
+	signer   ssh.Signer
+}
+
+func (s sshKey) public() string {
+	pubkey := s.signer.PublicKey()
+	return string(ssh.MarshalAuthorizedKey(pubkey))
+}
+
+func (s sshKey) cmd(patch []byte, cmd string) {
+	host := "localhost:2222"
+
+	config := &ssh.ClientConfig{
+		User: s.username,
+		Auth: []ssh.AuthMethod{
+			ssh.PublicKeys(s.signer),
+		},
+		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
+	}
+
+	client, err := ssh.Dial("tcp", host, config)
+	if err != nil {
+		panic(err)
+	}
+	defer client.Close()
+
+	session, err := client.NewSession()
+	if err != nil {
+		panic(err)
+	}
+	defer session.Close()
+
+	stdinPipe, err := session.StdinPipe()
+	if err != nil {
+		panic(err)
+	}
+
+	if err := session.Start(cmd); err != nil {
+		panic(err)
+	}
+
+	if patch != nil {
+		_, err = stdinPipe.Write(patch)
+		if err != nil {
+			panic(err)
+		}
+	}
+
+	stdinPipe.Close()
+
+	if err := session.Wait(); err != nil {
+		panic(err)
+	}
+}
+
+func generateKeys() (sshKey, sshKey) {
+	_, adminKey, err := ed25519.GenerateKey(rand.Reader)
+	if err != nil {
+		panic(err)
+	}
+
+	adminSigner, err := ssh.NewSignerFromKey(adminKey)
+	if err != nil {
+		panic(err)
+	}
+
+	_, userKey, err := ed25519.GenerateKey(rand.Reader)
+	if err != nil {
+		panic(err)
+	}
+
+	userSigner, err := ssh.NewSignerFromKey(userKey)
+	if err != nil {
+		panic(err)
+	}
+
+	return sshKey{
+			username: "admin",
+			signer:   adminSigner,
+		}, sshKey{
+			username: "contributor",
+			signer:   userSigner,
+		}
+}
+
+// args: tmpdir, adminKey
+var cfgTmpl = `# url is used for help commands, exclude protocol
+url = "localhost"
+# where we store the sqlite db, this toml file, git repos, and ssh host keys
+data_dir = %q
+# this gives users the ability to submit reviews and other admin permissions
+admins = [%q]
+# set datetime format for our clients
+time_format = "01/02/2006 15:04:05 07:00"
+
+# add as many repos as you want
+[[repo]]
+id = "test"
+clone_addr = "https://github.com/picosh/test.git"
+desc = "Test repo"`
fixtures/fixtures.go link
+6 -0
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
diff --git a/fixtures/fixtures.go b/fixtures/fixtures.go
new file mode 100644
index 0000000..fc24d94
--- /dev/null
+++ b/fixtures/fixtures.go
@@ -0,0 +1,6 @@
+package fixtures
+
+import "embed"
+
+//go:embed *
+var Fixtures embed.FS