mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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>
This commit is contained in:
@@ -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++
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user