From 6a123c31f8a5656f280c791c3bbb06f03c7d16df Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Tue, 16 Dec 2025 03:52:38 +0000 Subject: [PATCH] appview/models: add helper func to count total comments on a PR Signed-off-by: oppiliappan --- appview/models/pull.go | 24 +++++++----------------- appview/pages/templates/repo/pulls/pulls.html | 15 +++------------ appview/pages/templates/repo/pulls/fragments/summarizedPullHeader.html | 5 ++--- 3 file(s) changed, 12 insertion(s)(+), 32 deletion(s)(-) diff --git a/appview/models/pull.go b/appview/models/pull.go --- a/appview/models/pull.go +++ b/appview/models/pull.go @@ -171,23 +171,13 @@ return syntax.ATURI(p.CommentAt) } -// func (p *PullComment) AsRecord() tangled.RepoPullComment { -// mentions := make([]string, len(p.Mentions)) -// for i, did := range p.Mentions { -// mentions[i] = string(did) -// } -// references := make([]string, len(p.References)) -// for i, uri := range p.References { -// references[i] = string(uri) -// } -// return tangled.RepoPullComment{ -// Pull: p.PullAt, -// Body: p.Body, -// Mentions: mentions, -// References: references, -// CreatedAt: p.Created.Format(time.RFC3339), -// } -// } +func (p *Pull) TotalComments() int { + total := 0 + for _, s := range p.Submissions { + total += len(s.Comments) + } + return total +} func (p *Pull) LastRoundNumber() int { return len(p.Submissions) - 1 diff --git a/appview/pages/templates/repo/pulls/pulls.html b/appview/pages/templates/repo/pulls/pulls.html --- a/appview/pages/templates/repo/pulls/pulls.html +++ b/appview/pages/templates/repo/pulls/pulls.html @@ -112,18 +112,9 @@ {{ template "repo/fragments/time" .Created }} - - {{ $latestRound := .LastRoundNumber }} - {{ $lastSubmission := index .Submissions $latestRound }} - - {{ $commentCount := len $lastSubmission.Comments }} - {{ $s := "s" }} - {{ if eq $commentCount 1 }} - {{ $s = "" }} - {{ end }} - - {{ len $lastSubmission.Comments}} comment{{$s}} + {{ $commentCount := .TotalComments }} + {{ $commentCount }} comment{{ if ne $commentCount 1 }}s{{ end }} @@ -136,7 +127,7 @@ {{ $pipeline := index $.Pipelines .LatestSha }} {{ if and $pipeline $pipeline.Id }} - {{ template "repo/pipelines/fragments/pipelineSymbol" $pipeline }} + {{ template "repo/pipelines/fragments/pipelineSymbol" (dict "Pipeline" $pipeline "ShortSummary" true) }} {{ end }} {{ $state := .Labels }} diff --git a/appview/pages/templates/repo/pulls/fragments/summarizedPullHeader.html b/appview/pages/templates/repo/pulls/fragments/summarizedPullHeader.html --- a/appview/pages/templates/repo/pulls/fragments/summarizedPullHeader.html +++ b/appview/pages/templates/repo/pulls/fragments/summarizedPullHeader.html @@ -15,10 +15,9 @@
{{ $latestRound := .LastRoundNumber }} - {{ $lastSubmission := index .Submissions $latestRound }} - {{ $commentCount := len $lastSubmission.Comments }} + {{ $commentCount := .TotalComments }} {{ if and $pipeline $pipeline.Id }} - {{ template "repo/pipelines/fragments/pipelineSymbol" $pipeline }} + {{ template "repo/pipelines/fragments/pipelineSymbol" (dict "Pipeline" $pipeline "ShortSummary" true) }} {{ end }} -- tangled.sh