Skip to content

Commit

Permalink
[UI] Hide consecutive additions and removals of the same label (#13315)
Browse files Browse the repository at this point in the history
  • Loading branch information
pta2002 authored Oct 27, 2020
1 parent afe9d79 commit 8e368e7
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2418,11 +2418,34 @@ func combineLabelComments(issue *models.Issue) {
c.AddedLabels[0] = c.Label
}
} else {
// Remove duplicated "added" and "removed" labels
// This way, adding and immediately removing a label won't generate a comment.
var appendingTo *[]*models.Label
var other *[]*models.Label

if removingCur {
prev.RemovedLabels = append(prev.RemovedLabels, c.Label)
appendingTo = &prev.RemovedLabels
other = &prev.AddedLabels
} else {
prev.AddedLabels = append(prev.AddedLabels, c.Label)
appendingTo = &prev.AddedLabels
other = &prev.RemovedLabels
}

appending := true

for i := 0; i < len(*other); i++ {
l := (*other)[i]
if l.ID == c.Label.ID {
*other = append((*other)[:i], (*other)[i+1:]...)
appending = false
break
}
}

if appending {
*appendingTo = append(*appendingTo, c.Label)
}

prev.CreatedUnix = c.CreatedUnix
issue.Comments = append(issue.Comments[:i], issue.Comments[i+1:]...)
continue
Expand Down

0 comments on commit 8e368e7

Please sign in to comment.