mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-05 23:34:11 +02:00
fix: dedupe issue cross-reference timeline entries (#38881)
Removing and re-adding a mention, or changing `closes #1` to a plain `#1`, added duplicate references to the issue's timeline. The timeline now renders a single entry per referencing issue or pull request, positioned at the first mention, like GitHub does.
This commit is contained in:
1 parent
3875db1974
commit
4eebefbce5
2 files changed
+52
No files matched your search
@@ -7,10 +7,34 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
issues_model "gitea.dev/models/issues"
|
issues_model "gitea.dev/models/issues"
|
||||||
|
"gitea.dev/modules/references"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestCombineXRefComments(t *testing.T) {
|
||||||
|
none, closes, neutered := references.XRefActionNone, references.XRefActionCloses, references.XRefActionNeutered
|
||||||
|
xref := func(id, refIssueID, refCommentID int64, action references.XRefAction) *issues_model.Comment {
|
||||||
|
return &issues_model.Comment{ID: id, Type: issues_model.CommentTypeIssueRef, RefIssueID: refIssueID, RefCommentID: refCommentID, RefAction: action}
|
||||||
|
}
|
||||||
|
issue := issues_model.Issue{Comments: issues_model.CommentList{
|
||||||
|
xref(1, 10, 1, neutered),
|
||||||
|
xref(2, 11, 2, none),
|
||||||
|
xref(3, 10, 3, none),
|
||||||
|
xref(4, 11, 4, closes),
|
||||||
|
xref(5, 11, 5, neutered),
|
||||||
|
xref(6, 0, 0, none),
|
||||||
|
xref(7, 0, 0, none),
|
||||||
|
}}
|
||||||
|
combineXRefComments(&issue)
|
||||||
|
assert.Equal(t, issues_model.CommentList{
|
||||||
|
xref(1, 10, 3, none),
|
||||||
|
xref(2, 11, 2, closes),
|
||||||
|
xref(6, 0, 0, none),
|
||||||
|
xref(7, 0, 0, none),
|
||||||
|
}, issue.Comments)
|
||||||
|
}
|
||||||
|
|
||||||
func TestCombineLabelComments(t *testing.T) {
|
func TestCombineLabelComments(t *testing.T) {
|
||||||
kases := []struct {
|
kases := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import (
|
|||||||
"gitea.dev/modules/log"
|
"gitea.dev/modules/log"
|
||||||
"gitea.dev/modules/markup"
|
"gitea.dev/modules/markup"
|
||||||
"gitea.dev/modules/markup/markdown"
|
"gitea.dev/modules/markup/markdown"
|
||||||
|
"gitea.dev/modules/references"
|
||||||
"gitea.dev/modules/setting"
|
"gitea.dev/modules/setting"
|
||||||
"gitea.dev/modules/svg"
|
"gitea.dev/modules/svg"
|
||||||
"gitea.dev/modules/templates/vars"
|
"gitea.dev/modules/templates/vars"
|
||||||
@@ -189,6 +190,32 @@ func filterXRefComments(ctx *context.Context, issue *issues_model.Issue) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// combineXRefComments keeps only the first reference from each issue, carrying over the action of later ones
|
||||||
|
func combineXRefComments(issue *issues_model.Issue) {
|
||||||
|
first := make(map[int64]*issues_model.Comment)
|
||||||
|
for i := 0; i < len(issue.Comments); {
|
||||||
|
c := issue.Comments[i]
|
||||||
|
if !issues_model.CommentTypeIsRef(c.Type) || c.RefIssueID == 0 {
|
||||||
|
i++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
prev, ok := first[c.RefIssueID]
|
||||||
|
if !ok {
|
||||||
|
first[c.RefIssueID] = c
|
||||||
|
i++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case c.RefAction == references.XRefActionNeutered: // a removed mention never overrides a live one
|
||||||
|
case prev.RefAction == references.XRefActionNeutered:
|
||||||
|
prev.RefAction, prev.RefCommentID = c.RefAction, c.RefCommentID
|
||||||
|
case c.RefAction != references.XRefActionNone:
|
||||||
|
prev.RefAction = c.RefAction
|
||||||
|
}
|
||||||
|
issue.Comments = append(issue.Comments[:i], issue.Comments[i+1:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// combineLabelComments combine the nearby label comments as one.
|
// combineLabelComments combine the nearby label comments as one.
|
||||||
func combineLabelComments(issue *issues_model.Issue) {
|
func combineLabelComments(issue *issues_model.Issue) {
|
||||||
var prev, cur *issues_model.Comment
|
var prev, cur *issues_model.Comment
|
||||||
@@ -346,6 +373,7 @@ func ViewIssue(ctx *context.Context) {
|
|||||||
ctx.ServerError("filterXRefComments", err)
|
ctx.ServerError("filterXRefComments", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
combineXRefComments(issue)
|
||||||
|
|
||||||
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, emoji.ReplaceAliases(issue.Title))
|
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, emoji.ReplaceAliases(issue.Title))
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user