Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Phase 2, first slice: issues as files on a branch

37c01e5aa9b98bbea8567e741cd3af508ae1ba7d · Keenan Nemetz · 18d ago · parent 197ecaa2

Phase 2, first slice: issues as files on a branch

Push-based issues, per the decision to keep the web read-only. The format is the
contract; nothing here requires a Vole binary on a contributor's machine.

  issues/<ulid>/meta.json
  issues/<ulid>/description.md
  issues/<ulid>/comments/<ulid>.md      on refs/heads/issues

Design points worth recording:

- IDs are ULIDs generated by the writer, so there is no server-assigned counter,
  no contention, and no ID allocation in the write path at all.
- Issues live on a branch rather than a custom ref, so a plain `git clone` carries
  them. That is the same lesson that moved the user roster off refs/vole/users:
  `git clone` only mirrors refs/heads/*.
- File-per-comment means two people replying to the same issue never touch the
  same file, so the only merge conflict is two edits to one comment.
- Validation happens in pre-receive, so a malformed tree never reaches the web.
  Every problem is reported at once with the offending path, and a rejected push
  leaves the branch unmoved.

The index gained issue rows, refreshed when the issues ref moves rather than by a
hook, plus coverage in the full rebuild. The list page reads the index; the
detail page reads git, so bodies and comments are never stale.

Markdown is rendered with goldmark and sanitised with bluemonday. Issue bodies
arrive by push, which makes them untrusted input on a public page; a test asserts
that <script> and javascript: URLs do not survive.

Verified by hand with a user who has an editor and a key: filed an issue, added a
comment, saw both rendered, then pushed an issue with no title and got back
"issues/01M5.../meta.json: title is required" with the branch unmoved.

internal/web/issues.go +106

@@ -0,0 +1,106 @@
1 package web
2
3 import (
4 "bytes"
5 "html/template"
6 "net/http"
7 "sort"
8 "strings"
9
10 "github.com/microcosm-cc/bluemonday"
11 "github.com/yuin/goldmark"
12 "github.com/yuin/goldmark/extension"
13
14 "github.com/rodent-software/vole/internal/index"
15 "github.com/rodent-software/vole/internal/issues"
16 )
17
18 var (
19 markdown = goldmark.New(goldmark.WithExtensions(extension.GFM, extension.Typographer))
20 sanitizer = bluemonday.UGCPolicy()
21 )
22
23 // renderMarkdown converts untrusted commit content into HTML that is safe to put
24 // in a page. Issues are authored by pushes, so this is the boundary where a
25 // <script> tag stops being text.
26 func renderMarkdown(src string) template.HTML {
27 var buf bytes.Buffer
28 if err := markdown.Convert([]byte(src), &buf); err != nil {
29 return template.HTML(template.HTMLEscapeString(src))
30 }
31 return template.HTML(sanitizer.SanitizeBytes(buf.Bytes()))
32 }
33
34 // Issues lists a repo's issues from the index, refreshing it if the issues branch
35 // moved since it was last read.
36 func (w *Web) Issues(rw http.ResponseWriter, r *http.Request) {
37 m, ok := w.open(rw, r)
38 if !ok {
39 return
40 }
41 if err := w.Index.EnsureIssues(m); err != nil {
42 http.Error(rw, "issue index unavailable: "+err.Error(), http.StatusInternalServerError)
43 return
44 }
45 rows, err := w.Index.Issues(m.ID)
46 if err != nil {
47 http.Error(rw, err.Error(), http.StatusInternalServerError)
48 return
49 }
50 // Open first, then newest first within each state.
51 sort.SliceStable(rows, func(i, j int) bool {
52 if (rows[i].State == "open") != (rows[j].State == "open") {
53 return rows[i].State == "open"
54 }
55 return rows[i].ID > rows[j].ID
56 })
57 openCount := 0
58 for _, row := range rows {
59 if row.State == "open" {
60 openCount++
61 }
62 }
63 w.render(rw, "issues", struct {
64 Page
65 Name string
66 Issues []index.IssueRow
67 OpenCount int
68 Total int
69 }{w.base(m.Name + " · issues"), m.Name, rows, openCount, len(rows)}, 0)
70 }
71
72 // IssueView renders one issue and its thread. The issue is read from git rather
73 // than the index, so bodies are never stale relative to the branch.
74 func (w *Web) IssueView(rw http.ResponseWriter, r *http.Request) {
75 m, ok := w.open(rw, r)
76 if !ok {
77 return
78 }
79 id := r.PathValue("id")
80 if !issues.ValidULID(id) {
81 http.NotFound(rw, r)
82 return
83 }
84 iss, err := index.LoadIssue(m, id)
85 if err != nil {
86 http.NotFound(rw, r)
87 return
88 }
89 type rendered struct {
90 issues.Comment
91 Body template.HTML
92 }
93 comments := make([]rendered, 0, len(iss.Comments))
94 for _, c := range iss.Comments {
95 comments = append(comments, rendered{Comment: c, Body: renderMarkdown(c.Body)})
96 }
97 w.render(rw, "issue", struct {
98 Page
99 Name string
100 Issue *issues.Issue
101 Description template.HTML
102 Comments []rendered
103 Labels string
104 }{w.base(m.Name + " · " + iss.Title), m.Name, iss, renderMarkdown(iss.Description), comments,
105 strings.Join(iss.Labels, ", ")}, 0)
106 }