git-pr

created pr with 75.1 on 2025-08-22T03:15:03Z · by 964fa508
changed pr name to Status comments on 2025-08-22T03:15:55Z · by 964fa508
cmds
checkout latest patchset:
ssh pr.pico.sh print 75 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print 75.[rev] | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 75
+38 -1 models.go #
......@@ -2,6 +2,9 @@ package git
22
33 import (
44 "database/sql"
5+ "database/sql/driver"
6+ "encoding/json"
7+ "fmt"
58 "time"
69
710 "github.com/bluekeyes/go-gitdiff/gitdiff"
......@@ -97,6 +100,40 @@ type EventLog struct {
97100 PatchRequestID sql.NullInt64 `db:"patch_request_id"`
98101 PatchsetID sql.NullInt64 `db:"patchset_id"`
99102 Event string `db:"event"`
100- Data string `db:"data"`
101103 CreatedAt time.Time `db:"created_at"`
104+ Data EventData `db:"data"`
105+}
106+
107+type EventData struct {
108+ Name string `json:"name,omitempty"`
109+ Status Status `json:"status,omitempty"`
110+}
111+
112+func (e EventData) String() string {
113+ b, _ := json.Marshal(e)
114+ bs := string(b)
115+ if bs == "{}" {
116+ return ""
117+ }
118+ return bs
119+}
120+
121+func (e *EventData) Scan(value any) error {
122+ if value == nil {
123+ return nil
124+ }
125+ var bytes []byte
126+ switch v := value.(type) {
127+ case []byte:
128+ bytes = v
129+ case string:
130+ bytes = []byte(v)
131+ default:
132+ return fmt.Errorf("cannot scan %T into EventData", value)
133+ }
134+ return json.Unmarshal(bytes, e)
135+}
136+
137+func (e EventData) Value() (driver.Value, error) {
138+ return json.Marshal(e)
102139 }
+6 -2 pr.go #
......@@ -322,7 +322,9 @@ func (cmd PrCmd) UpdatePatchRequestStatus(prID int64, userID int64, status Statu
322322 RepoID: sql.NullInt64{Int64: pr.RepoID, Valid: true},
323323 PatchRequestID: sql.NullInt64{Int64: prID, Valid: true},
324324 Event: "pr_status_changed",
325- Data: fmt.Sprintf(`{"status":"%s"}`, status),
325+ Data: EventData{
326+ Status: status,
327+ },
326328 })
327329 if err != nil {
328330 return err
......@@ -364,7 +366,9 @@ func (cmd PrCmd) UpdatePatchRequestName(prID int64, userID int64, name string) e
364366 RepoID: sql.NullInt64{Int64: pr.RepoID, Valid: true},
365367 PatchRequestID: sql.NullInt64{Int64: prID, Valid: true},
366368 Event: "pr_name_changed",
367- Data: fmt.Sprintf(`{"name":"%s"}`, name),
369+ Data: EventData{
370+ Name: name,
371+ },
368372 })
369373 if err != nil {
370374 return err
+1 -1 tmpl/pages/pr.html #
......@@ -42,7 +42,7 @@
4242 {{end}}
4343 </span>
4444 <span>on <date>{{.Date}}</date></span>
45- {{if .Data}}<code>{{.Data}}</code>{{end}}
45+ {{if .Data.String}}<code>{{.Data}}</code>{{end}}
4646 </div>
4747 {{end}}
4848 </div>
Back to top