From 597dec92da6a24aa7c22a88a05063c72e863946a Mon Sep 17 00:00:00 2001 From: Amolith Date: Sat, 18 Oct 2025 15:22:30 -0600 Subject: [PATCH] feat(web): show dynamic status in bugs list Bugs list now displays "Closed" or "Reopened" instead of generic "Updated" when the last event was a status change. Other events (comments, title changes, label changes) still show "Updated". Implements: bug-f3568dc Co-authored-by: Crush --- pkg/web/templates/bugs.html | 2 +- pkg/web/webui_bugs.go | 90 ++++++++++++++++++++++++++++--------- 2 files changed, 69 insertions(+), 23 deletions(-) diff --git a/pkg/web/templates/bugs.html b/pkg/web/templates/bugs.html index ff58408b9c0b0fe64041b0e2873e8216e6dc0034..36ec873ca1cec1af11099147d7385823e12264f6 100644 --- a/pkg/web/templates/bugs.html +++ b/pkg/web/templates/bugs.html @@ -34,7 +34,7 @@ {{if .AuthorAvatar}}{{end}}{{.Author}} opened {{- if gt .CommentCount 0}}{{.CommentCount}} {{if eq .CommentCount 1}}comment{{else}}comments{{end}} {{- end}} - {{- if .HasActivity}}Updated + {{- if .HasActivity}}{{if eq .LastEventAction "closed"}}Closed{{else if eq .LastEventAction "reopened"}}Reopened{{else}}Updated{{end}} {{- end}} diff --git a/pkg/web/webui_bugs.go b/pkg/web/webui_bugs.go index 58d8d68b8437c51d4ca3619bb79647e013560644..40be7859fef69985b4a96b534cd180a3cdc86df1 100644 --- a/pkg/web/webui_bugs.go +++ b/pkg/web/webui_bugs.go @@ -32,17 +32,18 @@ type BugsData struct { } type BugListItem struct { - ID string - FullID string - Title string - Author string - AuthorAvatar string - Status string - CreatedAt time.Time - LastActivity time.Time - HasActivity bool - CommentCount int - Labels []Label + ID string + FullID string + Title string + Author string + AuthorAvatar string + Status string + CreatedAt time.Time + LastActivity time.Time + HasActivity bool + LastEventAction string + CommentCount int + Labels []Label } type BugData struct { @@ -131,17 +132,18 @@ func getBugsList(rc *cache.RepoCache, status string) ([]BugListItem, error) { } bugs = append(bugs, BugListItem{ - ID: snap.Id().Human(), - FullID: snap.Id().String(), - Title: snap.Title, - Author: snap.Author.DisplayName(), - AuthorAvatar: snap.Author.AvatarUrl(), - Status: snap.Status.String(), - CreatedAt: snap.CreateTime, - LastActivity: getLastActivity(snap), - HasActivity: len(snap.Timeline) > 1, - CommentCount: countComments(snap), - Labels: labels, + ID: snap.Id().Human(), + FullID: snap.Id().String(), + Title: snap.Title, + Author: snap.Author.DisplayName(), + AuthorAvatar: snap.Author.AvatarUrl(), + Status: snap.Status.String(), + CreatedAt: snap.CreateTime, + LastActivity: getLastActivity(snap), + HasActivity: len(snap.Timeline) > 1, + LastEventAction: getLastEventAction(snap), + CommentCount: countComments(snap), + Labels: labels, }) } @@ -179,6 +181,50 @@ func getLastActivity(snap *bug.Snapshot) time.Time { return lastTime } +func getLastEventAction(snap *bug.Snapshot) string { + var lastTime time.Time + var lastAction string + + for _, item := range snap.Timeline { + var itemTime time.Time + + switch op := item.(type) { + case *bug.CreateTimelineItem: + itemTime = op.CreatedAt.Time() + if itemTime.After(lastTime) { + lastTime = itemTime + lastAction = "created" + } + case *bug.AddCommentTimelineItem: + itemTime = op.CreatedAt.Time() + if itemTime.After(lastTime) { + lastTime = itemTime + lastAction = "commented" + } + case *bug.SetTitleTimelineItem: + itemTime = op.UnixTime.Time() + if itemTime.After(lastTime) { + lastTime = itemTime + lastAction = "updated" + } + case *bug.SetStatusTimelineItem: + itemTime = op.UnixTime.Time() + if itemTime.After(lastTime) { + lastTime = itemTime + lastAction = op.Status.Action() + } + case *bug.LabelChangeTimelineItem: + itemTime = op.UnixTime.Time() + if itemTime.After(lastTime) { + lastTime = itemTime + lastAction = "updated" + } + } + } + + return lastAction +} + func countComments(snap *bug.Snapshot) int { count := 0 for _, item := range snap.Timeline {