@ -1354,6 +1354,9 @@ func ViewIssue(ctx *context.Context) {
}
}
}
}
// Combine multiple label assignments into a single comment
combineLabelComments ( issue )
getBranchData ( ctx , issue )
getBranchData ( ctx , issue )
if issue . IsPull {
if issue . IsPull {
pull := issue . PullRequest
pull := issue . PullRequest
@ -2385,3 +2388,46 @@ func attachmentsHTML(ctx *context.Context, attachments []*models.Attachment) str
}
}
return attachHTML
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 ++
}
}