loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Group Label Changed Comments in timeline (#13304)

* Create function to group label comments

* Combine multiple label additions into one

* Group removed and added labels in the same comment

* Fix indentation on comments.tmpl

Co-authored-by: zeripath <art27@cantab.net>

Co-authored-by: zeripath <art27@cantab.net>

authored by

Pedro Alves
zeripath
and committed by
GitHub
c40df54e 756c090d

+72 -5
+3 -1
models/issue_comment.go
··· 124 124 IssueID int64 `xorm:"INDEX"` 125 125 Issue *Issue `xorm:"-"` 126 126 LabelID int64 127 - Label *Label `xorm:"-"` 127 + Label *Label `xorm:"-"` 128 + AddedLabels []*Label `xorm:"-"` 129 + RemovedLabels []*Label `xorm:"-"` 128 130 OldProjectID int64 129 131 ProjectID int64 130 132 OldProject *Project `xorm:"-"`
+10
modules/templates/helper.go
··· 343 343 // the table is NOT sorted with this header 344 344 return "" 345 345 }, 346 + "RenderLabels": func(labels []*models.Label) template.HTML { 347 + html := "" 348 + 349 + for _, label := range labels { 350 + html = fmt.Sprintf("%s<div class='ui label' style='color: %s; background-color: %s'>%s</div>", 351 + html, label.ForegroundColor(), label.Color, RenderEmoji(label.Name)) 352 + } 353 + 354 + return template.HTML(html) 355 + }, 346 356 }} 347 357 } 348 358
+5 -2
options/locale/locale_en-US.ini
··· 979 979 issues.label_templates.helper = Select a label set 980 980 issues.label_templates.use = Use Label Set 981 981 issues.label_templates.fail_to_load_file = Failed to load label template file '%s': %v 982 - issues.add_label_at = added the <div class="ui label" style="color: %s\; background-color: %s">%s</div> label %s 983 - issues.remove_label_at = removed the <div class="ui label" style="color: %s\; background-color: %s">%s</div> label %s 982 + issues.add_label = added the %s label %s 983 + issues.add_labels = added the %s labels %s 984 + issues.remove_label = removed the %s label %s 985 + issues.remove_labels = removed the %s labels %s 986 + issues.add_remove_labels = added %s and removed %s labels %s 984 987 issues.add_milestone_at = `added this to the <b>%s</b> milestone %s` 985 988 issues.add_project_at = `added this to the <b>%s</b> project %s` 986 989 issues.change_milestone_at = `modified the milestone from <b>%s</b> to <b>%s</b> %s`
+46
routers/repo/issue.go
··· 1354 1354 } 1355 1355 } 1356 1356 1357 + // Combine multiple label assignments into a single comment 1358 + combineLabelComments(issue) 1359 + 1357 1360 getBranchData(ctx, issue) 1358 1361 if issue.IsPull { 1359 1362 pull := issue.PullRequest ··· 2385 2388 } 2386 2389 return attachHTML 2387 2390 } 2391 + 2392 + func combineLabelComments(issue *models.Issue) { 2393 + for i := 0; i < len(issue.Comments); { 2394 + c := issue.Comments[i] 2395 + var shouldMerge bool 2396 + var removingCur bool 2397 + var prev *models.Comment 2398 + 2399 + if i == 0 { 2400 + shouldMerge = false 2401 + } else { 2402 + prev = issue.Comments[i-1] 2403 + removingCur = c.Content != "1" 2404 + 2405 + shouldMerge = prev.PosterID == c.PosterID && c.CreatedUnix-prev.CreatedUnix < 60 && 2406 + c.Type == prev.Type 2407 + } 2408 + 2409 + if c.Type == models.CommentTypeLabel { 2410 + if !shouldMerge { 2411 + if removingCur { 2412 + c.RemovedLabels = make([]*models.Label, 1) 2413 + c.AddedLabels = make([]*models.Label, 0) 2414 + c.RemovedLabels[0] = c.Label 2415 + } else { 2416 + c.RemovedLabels = make([]*models.Label, 0) 2417 + c.AddedLabels = make([]*models.Label, 1) 2418 + c.AddedLabels[0] = c.Label 2419 + } 2420 + } else { 2421 + if removingCur { 2422 + prev.RemovedLabels = append(prev.RemovedLabels, c.Label) 2423 + } else { 2424 + prev.AddedLabels = append(prev.AddedLabels, c.Label) 2425 + } 2426 + prev.CreatedUnix = c.CreatedUnix 2427 + issue.Comments = append(issue.Comments[:i], issue.Comments[i+1:]...) 2428 + continue 2429 + } 2430 + } 2431 + i++ 2432 + } 2433 + }
+8 -2
templates/repo/issue/view_content/comments.tmpl
··· 161 161 </div> 162 162 </div> 163 163 {{else if eq .Type 7}} 164 - {{if .Label}} 164 + {{if or .AddedLabels .RemovedLabels}} 165 165 <div class="timeline-item event" id="{{.HashTag}}"> 166 166 <span class="badge">{{svg "octicon-tag"}}</span> 167 167 <a class="ui avatar image" href="{{.Poster.HomeLink}}"> ··· 169 169 </a> 170 170 <span class="text grey"> 171 171 <a class="author" href="{{.Poster.HomeLink}}">{{.Poster.GetDisplayName}}</a> 172 - {{if .Content}}{{$.i18n.Tr "repo.issues.add_label_at" .Label.ForegroundColor .Label.Color (.Label.Name|RenderEmoji) $createdStr | Safe}}{{else}}{{$.i18n.Tr "repo.issues.remove_label_at" .Label.ForegroundColor .Label.Color (.Label.Name|RenderEmoji) $createdStr | Safe}}{{end}} 172 + {{if and .AddedLabels (not .RemovedLabels)}} 173 + {{$.i18n.Tr (TrN $.i18n.Lang (len .AddedLabels) "repo.issues.add_label" "repo.issues.add_labels") (RenderLabels .AddedLabels) $createdStr | Safe}} 174 + {{else if and (not .AddedLabels) .RemovedLabels}} 175 + {{$.i18n.Tr (TrN $.i18n.Lang (len .RemovedLabels) "repo.issues.remove_label" "repo.issues.remove_labels") (RenderLabels .RemovedLabels) $createdStr | Safe}} 176 + {{else}} 177 + {{$.i18n.Tr "repo.issues.add_remove_labels" (RenderLabels .AddedLabels) (RenderLabels .RemovedLabels) $createdStr | Safe}} 178 + {{end}} 173 179 </span> 174 180 </div> 175 181 {{end}}