Hide label comments if labels were added and removed immediately (#17455)
* Hide label comments if labels were added and removed immediately * Add comment and rename var * Fix unit test * Add test case Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
d6f4820967
commit
e5b48dcac4
2 changed files with 87 additions and 12 deletions
|
@ -2577,9 +2577,33 @@ func combineLabelComments(issue *models.Issue) {
|
||||||
if cur.Label != nil { // now cur MUST be label comment
|
if cur.Label != nil { // now cur MUST be label comment
|
||||||
if prev.Type == models.CommentTypeLabel { // we can combine them only prev is a label comment
|
if prev.Type == models.CommentTypeLabel { // we can combine them only prev is a label comment
|
||||||
if cur.Content != "1" {
|
if cur.Content != "1" {
|
||||||
prev.RemovedLabels = append(prev.RemovedLabels, cur.Label)
|
// remove labels from the AddedLabels list if the label that was removed is already
|
||||||
|
// in this list, and if it's not in this list, add the label to RemovedLabels
|
||||||
|
addedAndRemoved := false
|
||||||
|
for i, label := range prev.AddedLabels {
|
||||||
|
if cur.Label.ID == label.ID {
|
||||||
|
prev.AddedLabels = append(prev.AddedLabels[:i], prev.AddedLabels[i+1:]...)
|
||||||
|
addedAndRemoved = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !addedAndRemoved {
|
||||||
|
prev.RemovedLabels = append(prev.RemovedLabels, cur.Label)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
prev.AddedLabels = append(prev.AddedLabels, cur.Label)
|
// remove labels from the RemovedLabels list if the label that was added is already
|
||||||
|
// in this list, and if it's not in this list, add the label to AddedLabels
|
||||||
|
removedAndAdded := false
|
||||||
|
for i, label := range prev.RemovedLabels {
|
||||||
|
if cur.Label.ID == label.ID {
|
||||||
|
prev.RemovedLabels = append(prev.RemovedLabels[:i], prev.RemovedLabels[i+1:]...)
|
||||||
|
removedAndAdded = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !removedAndAdded {
|
||||||
|
prev.AddedLabels = append(prev.AddedLabels, cur.Label)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
prev.CreatedUnix = cur.CreatedUnix
|
prev.CreatedUnix = cur.CreatedUnix
|
||||||
// remove the current comment since it has been combined to prev comment
|
// remove the current comment since it has been combined to prev comment
|
||||||
|
|
|
@ -51,16 +51,7 @@ func TestCombineLabelComments(t *testing.T) {
|
||||||
PosterID: 1,
|
PosterID: 1,
|
||||||
Content: "1",
|
Content: "1",
|
||||||
CreatedUnix: 0,
|
CreatedUnix: 0,
|
||||||
AddedLabels: []*models.Label{
|
AddedLabels: []*models.Label{},
|
||||||
{
|
|
||||||
Name: "kind/bug",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RemovedLabels: []*models.Label{
|
|
||||||
{
|
|
||||||
Name: "kind/bug",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Label: &models.Label{
|
Label: &models.Label{
|
||||||
Name: "kind/bug",
|
Name: "kind/bug",
|
||||||
},
|
},
|
||||||
|
@ -310,6 +301,66 @@ func TestCombineLabelComments(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "kase 6",
|
||||||
|
beforeCombined: []*models.Comment{
|
||||||
|
{
|
||||||
|
Type: models.CommentTypeLabel,
|
||||||
|
PosterID: 1,
|
||||||
|
Content: "1",
|
||||||
|
Label: &models.Label{
|
||||||
|
Name: "kind/bug",
|
||||||
|
},
|
||||||
|
CreatedUnix: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: models.CommentTypeLabel,
|
||||||
|
PosterID: 1,
|
||||||
|
Content: "1",
|
||||||
|
Label: &models.Label{
|
||||||
|
Name: "reviewed/confirmed",
|
||||||
|
},
|
||||||
|
CreatedUnix: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: models.CommentTypeLabel,
|
||||||
|
PosterID: 1,
|
||||||
|
Content: "",
|
||||||
|
Label: &models.Label{
|
||||||
|
Name: "kind/bug",
|
||||||
|
},
|
||||||
|
CreatedUnix: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: models.CommentTypeLabel,
|
||||||
|
PosterID: 1,
|
||||||
|
Content: "1",
|
||||||
|
Label: &models.Label{
|
||||||
|
Name: "kind/feature",
|
||||||
|
},
|
||||||
|
CreatedUnix: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
afterCombined: []*models.Comment{
|
||||||
|
{
|
||||||
|
Type: models.CommentTypeLabel,
|
||||||
|
PosterID: 1,
|
||||||
|
Content: "1",
|
||||||
|
Label: &models.Label{
|
||||||
|
Name: "kind/bug",
|
||||||
|
},
|
||||||
|
AddedLabels: []*models.Label{
|
||||||
|
{
|
||||||
|
Name: "reviewed/confirmed",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "kind/feature",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CreatedUnix: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, kase := range kases {
|
for _, kase := range kases {
|
||||||
|
|
Reference in a new issue