repos / git-pr

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

commit
5703a1f
parent
dcef9ea
author
Eric Bower
date
2024-12-21 14:23:34 -0500 EST
fix: highlight review patches

This was a regression from a previous refactor.  Now we show added
patches from a reviewer.
2 files changed,  +35, -4
M web.go
M tmpl/patchset.html
+1, -1
1@@ -7,7 +7,7 @@
2       </h2>
3 
4       {{range $patch := .Patches}}
5-        <div class="box group">
6+      <div class="box{{if $patch.Review}}-review{{end}} group">
7           <div>
8             <h3 class="text-lg text-transform-none m-0 p-0 mb mono">
9               {{if $patch.Review}}<code class="pill-review">REVIEW</code>{{end}}
M web.go
+34, -3
 1@@ -587,6 +587,30 @@ func createPrDetail(page string) http.HandlerFunc {
 2 				return
 3 			}
 4 
 5+			// TODO: a little hacky
 6+			reviewIDs := []int64{}
 7+			for _, data := range patchsetsData {
 8+				if psID != data.ID {
 9+					continue
10+				}
11+				if !data.Patchset.Review {
12+					continue
13+				}
14+
15+				for _, rdiff := range data.RangeDiff {
16+					if rdiff.Type == "add" {
17+						for _, patch := range patches {
18+							commSha := truncateSha(patch.CommitSha)
19+							if strings.Contains(rdiff.Header, commSha) {
20+								reviewIDs = append(reviewIDs, patch.ID)
21+								break
22+							}
23+						}
24+					}
25+				}
26+				break
27+			}
28+
29 			for _, patch := range patches {
30 				diffFiles, preamble, err := ParsePatch(patch.RawText)
31 				if err != nil {
32@@ -601,6 +625,15 @@ func createPrDetail(page string) http.HandlerFunc {
33 					return
34 				}
35 
36+				// highlight review
37+				isReview := false
38+				for _, pID := range reviewIDs {
39+					if pID == patch.ID {
40+						isReview = true
41+						break
42+					}
43+				}
44+
45 				patchFiles := []*PatchFile{}
46 				for _, file := range diffFiles {
47 					var adds int64 = 0
48@@ -625,9 +658,6 @@ func createPrDetail(page string) http.HandlerFunc {
49 					})
50 				}
51 
52-				// highlight review
53-				isReview := false
54-
55 				timestamp := patch.AuthorDate.Format(web.Backend.Cfg.TimeFormat)
56 				patchesData = append(patchesData, PatchData{
57 					Patch:               patch,
58@@ -979,6 +1009,7 @@ func StartWebServer(cfg *GitCfg) {
59 	formatter := formatterHtml.New(
60 		formatterHtml.WithLineNumbers(true),
61 		formatterHtml.WithClasses(true),
62+		formatterHtml.WithLinkableLineNumbers(true, "gitpr"),
63 	)
64 	web := &WebCtx{
65 		Pr:        prCmd,