From 5003002614ec30225844c66d096210981c2c880a Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 26 Oct 2020 13:05:55 +0000 Subject: [PATCH 1/2] Hide consecutive additions and removals of the same label --- routers/repo/issue.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 1763b1c1a234b..daad2ad3f080b 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 imediately 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 From b5fab130776de004eff52fceae5f163c969cb6c1 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 26 Oct 2020 13:13:18 +0000 Subject: [PATCH 2/2] fix typo in comment --- routers/repo/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index daad2ad3f080b..009af784e775a 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -2419,7 +2419,7 @@ func combineLabelComments(issue *models.Issue) { } } else { // Remove duplicated "added" and "removed" labels - // This way, adding and imediately removing a label won't generate a comment. + // This way, adding and immediately removing a label won't generate a comment. var appendingTo *[]*models.Label var other *[]*models.Label