aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPedro Alves <pta2002@users.noreply.github.com>2020-10-27 07:12:01 +0000
committerGitHub <noreply@github.com>2020-10-27 09:12:01 +0200
commit8e368e7065eff5708ed2d7de042fe701cf0764c2 (patch)
tree9e2252d241e04b82f1963a679e1d2d04a3a0e817
parentafe9d79104eaed5993c722beccf78f9f1493b129 (diff)
downloadgitea-8e368e7065eff5708ed2d7de042fe701cf0764c2.tar.gz
gitea-8e368e7065eff5708ed2d7de042fe701cf0764c2.zip
[UI] Hide consecutive additions and removals of the same label (#13315)
-rw-r--r--routers/repo/issue.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 1763b1c1a2..009af784e7 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -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