summaryrefslogtreecommitdiffstats
path: root/routers/repo/issue.go
diff options
context:
space:
mode:
authorPedro Alves <pta2002@users.noreply.github.com>2020-10-25 21:49:48 +0000
committerGitHub <noreply@github.com>2020-10-25 17:49:48 -0400
commitc40df54e28fe1a1cfd0fc5f834451996d96028f3 (patch)
treec4337b06fe24f70b385dd6b7e1198f2d4c26de9b /routers/repo/issue.go
parent756c090dbef0f4a1caffe8292780eea6c1d24c77 (diff)
downloadgitea-c40df54e28fe1a1cfd0fc5f834451996d96028f3.tar.gz
gitea-c40df54e28fe1a1cfd0fc5f834451996d96028f3.zip
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>
Diffstat (limited to 'routers/repo/issue.go')
-rw-r--r--routers/repo/issue.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 835a952e5e..1763b1c1a2 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -1354,6 +1354,9 @@ func ViewIssue(ctx *context.Context) {
}
}
+ // Combine multiple label assignments into a single comment
+ combineLabelComments(issue)
+
getBranchData(ctx, issue)
if issue.IsPull {
pull := issue.PullRequest
@@ -2385,3 +2388,46 @@ func attachmentsHTML(ctx *context.Context, attachments []*models.Attachment) str
}
return attachHTML
}
+
+func combineLabelComments(issue *models.Issue) {
+ for i := 0; i < len(issue.Comments); {
+ c := issue.Comments[i]
+ var shouldMerge bool
+ var removingCur bool
+ var prev *models.Comment
+
+ if i == 0 {
+ shouldMerge = false
+ } else {
+ prev = issue.Comments[i-1]
+ removingCur = c.Content != "1"
+
+ shouldMerge = prev.PosterID == c.PosterID && c.CreatedUnix-prev.CreatedUnix < 60 &&
+ c.Type == prev.Type
+ }
+
+ if c.Type == models.CommentTypeLabel {
+ if !shouldMerge {
+ if removingCur {
+ c.RemovedLabels = make([]*models.Label, 1)
+ c.AddedLabels = make([]*models.Label, 0)
+ c.RemovedLabels[0] = c.Label
+ } else {
+ c.RemovedLabels = make([]*models.Label, 0)
+ c.AddedLabels = make([]*models.Label, 1)
+ c.AddedLabels[0] = c.Label
+ }
+ } else {
+ if removingCur {
+ prev.RemovedLabels = append(prev.RemovedLabels, c.Label)
+ } else {
+ prev.AddedLabels = append(prev.AddedLabels, c.Label)
+ }
+ prev.CreatedUnix = c.CreatedUnix
+ issue.Comments = append(issue.Comments[:i], issue.Comments[i+1:]...)
+ continue
+ }
+ }
+ i++
+ }
+}