dmitri.shuralyov.com/app/changes/...

add support for change.CommitEvent

Visualize the new event type in the change timeline.

Follows https://dmitri.shuralyov.com/service/change$commit/bd27112db59ba9f1e01f6d1e36ea7715c9dde98c.
dmitshur committed 1 month ago commit 99913882f9aa457908d5a24a124159a0ef711981
component/component.go
@@ -3,10 +3,11 @@ package component
 
 import (
 	"fmt"
 	"time"
 
+	"dmitri.shuralyov.com/app/changes/common"
 	"dmitri.shuralyov.com/html/belt"
 	"dmitri.shuralyov.com/service/change"
 	"dmitri.shuralyov.com/state"
 	"github.com/dustin/go-humanize"
 	"github.com/shurcooL/htmlg"
@@ -18,10 +19,14 @@ import (
 )
 
 // Event is an event component.
 type Event struct {
 	Event change.TimelineItem
+
+	// State must have BaseURI and ChangeID fields populated.
+	// They are used while rendering change.CommitEvent events.
+	State common.State
 }
 
 func (e Event) Render() []*html.Node {
 	// TODO: Make this much nicer.
 	// <div class="list-entry event event-{{.Type}}">
@@ -59,10 +64,12 @@ func (e Event) icon() *html.Node {
 	case change.ReopenedEvent:
 		icon = octicon.PrimitiveDot()
 		color, backgroundColor = "#fff", "#6cc644"
 	case change.RenamedEvent:
 		icon = octicon.Pencil()
+	case change.CommitEvent:
+		icon = octicon.GitCommit()
 	case change.LabeledEvent, change.UnlabeledEvent:
 		icon = octicon.Tag()
 	case change.ReviewRequestedEvent:
 		icon = octicon.Eye()
 	case change.ReviewRequestRemovedEvent:
@@ -125,10 +132,22 @@ func (e Event) text() []*html.Node {
 			Attr:       []html.Attribute{{Key: atom.Style.String(), Val: "font-weight: bold;"}},
 			FirstChild: htmlg.Text(p.From),
 		}
 		to := htmlg.Strong(p.To)
 		return []*html.Node{htmlg.Text("changed the title "), from, htmlg.Text(" "), to}
+	case change.CommitEvent:
+		return []*html.Node{
+			htmlg.Text("uploaded "),
+			{
+				Type: html.ElementNode, Data: atom.A.String(),
+				Attr: []html.Attribute{
+					{Key: atom.Class.String(), Val: "black"},
+					{Key: atom.Href.String(), Val: fmt.Sprintf("%s/%d/files/%s", e.State.BaseURI, e.State.ChangeID, p.SHA)},
+				},
+				FirstChild: htmlg.Text(p.Subject),
+			},
+		}
 	case change.LabeledEvent:
 		var ns []*html.Node
 		ns = append(ns, htmlg.Text("added the "))
 		ns = append(ns, issuescomponent.Label{Label: p.Label}.Render()...)
 		ns = append(ns, htmlg.Text(" label"))
main.go
@@ -666,11 +666,11 @@ func loadTemplates(state common.State, bodyPre string) (*template.Template, erro
 		},
 
 		"render": func(c htmlg.Component) template.HTML {
 			return template.HTML(htmlg.Render(c.Render()...))
 		},
-		"event":            func(e change.TimelineItem) htmlg.Component { return component.Event{Event: e} },
+		"event":            func(e change.TimelineItem) htmlg.Component { return component.Event{Event: e, State: state} },
 		"changeStateBadge": func(c change.Change) htmlg.Component { return component.ChangeStateBadge{Change: c} },
 		"time":             func(t time.Time) htmlg.Component { return component.Time{Time: t} },
 		"user":             func(u users.User) htmlg.Component { return component.User{User: u} },
 		"avatar":           func(u users.User) htmlg.Component { return component.Avatar{User: u, Size: 48} },
 	})