repos / git-pr

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

commit
11fabd4
parent
94b4779
author
Eric Bower
date
2024-07-10 16:30:48 -0400 EDT
feat: show event log in pr detail web view
2 files changed,  +58, -2
M web.go
M tmpl/pr-detail.html
+27, -0
 1@@ -14,6 +14,33 @@
 2 <hr />
 3 
 4 <main class="group">
 5+  <div class="box group text-sm">
 6+    {{range .Logs}}
 7+    <div>
 8+      <code class='pill{{if eq .Event "pr_reviewed"}}-alert{{end}}'>{{.UserName}}</code>
 9+      <span class="font-bold">
10+        {{if eq .Event "pr_created"}}
11+        created pr
12+        {{else if eq .Event "pr_patchset_added"}}
13+        added patches
14+        {{else if eq .Event "pr_reviewed"}}
15+        reviewed pr
16+        {{else if eq .Event "pr_patchset_replaced"}}
17+        replaced all patches
18+        {{else if eq .Event "pr_status_changed"}}
19+        changed status
20+        {{else if eq .Event "pr_name_changed"}}
21+        changed pr name
22+        {{else}}
23+        {{.Event}}
24+        {{end}}
25+      </span>
26+      <span>on <date>{{.Date}}</date></span>
27+      <span>{{.Data}}</span>
28+    </div>
29+    {{end}}
30+  </div>
31+
32   <div class="group">
33     {{range $idx, $val := .Patches}}
34     <div class="box{{if $val.Review}}-alert{{end}} group" id="{{$val.Url}}">
M web.go
+31, -2
 1@@ -9,6 +9,7 @@ import (
 2 	"log/slog"
 3 	"net/http"
 4 	"path/filepath"
 5+	"slices"
 6 	"strconv"
 7 	"time"
 8 
 9@@ -267,12 +268,20 @@ type PatchData struct {
10 	DiffStr template.HTML
11 }
12 
13-type PrHeaderData struct {
14+type EventLogData struct {
15+	*EventLog
16+	UserName string
17+	Pubkey   string
18+	Date     string
19+}
20+
21+type PrDetailData struct {
22 	Page    string
23 	Repo    LinkData
24 	Pr      PrData
25 	Patches []PatchData
26 	Branch  string
27+	Logs    []EventLogData
28 }
29 
30 func prDetailHandler(w http.ResponseWriter, r *http.Request) {
31@@ -339,8 +348,27 @@ func prDetailHandler(w http.ResponseWriter, r *http.Request) {
32 		return
33 	}
34 	isAdmin := web.Backend.IsAdmin(pk)
35+	logs, err := web.Pr.GetEventLogsByPrID(int64(prID))
36+	if err != nil {
37+		w.WriteHeader(http.StatusUnprocessableEntity)
38+		return
39+	}
40+	slices.SortFunc[[]*EventLog](logs, func(a *EventLog, b *EventLog) int {
41+		return a.CreatedAt.Compare(b.CreatedAt)
42+	})
43+
44+	logData := []EventLogData{}
45+	for _, eventlog := range logs {
46+		user, _ := web.Pr.GetUserByID(eventlog.UserID)
47+		logData = append(logData, EventLogData{
48+			EventLog: eventlog,
49+			UserName: user.Name,
50+			Pubkey:   user.Pubkey,
51+			Date:     pr.CreatedAt.Format(time.RFC3339),
52+		})
53+	}
54 
55-	err = tmpl.Execute(w, PrHeaderData{
56+	err = tmpl.Execute(w, PrDetailData{
57 		Page: "pr",
58 		Repo: LinkData{
59 			Url:  template.URL("/repos/" + repo.ID),
60@@ -348,6 +376,7 @@ func prDetailHandler(w http.ResponseWriter, r *http.Request) {
61 		},
62 		Branch:  repo.DefaultBranch,
63 		Patches: patchesData,
64+		Logs:    logData,
65 		Pr: PrData{
66 			ID:       pr.ID,
67 			IsAdmin:  isAdmin,