Files
gitea/routers/web/repo/issue_test.go
T
6624d96689 feat(migrations): GraphQL fast path for GitHub migration + rate-limit resilience (#38694)
Adds a batched GraphQL path for GitHub migrations that fetches each
issue or pull request together with its comments, reviews, reactions and
timeline events instead of the REST N+1 pattern, sharply reducing
rate-limit pressure on large repositories.

- GraphQL is used for authenticated migrations with issues or pull
requests and falls back to REST automatically when it fails
- timeline events (close/reopen, lock, rename, label, milestone, merge,
branch deletion, pin, auto-merge) are imported as typed comments showing
their GitHub author
- GitBucket issue migrations no longer stop after the first page,
GitBucket sends no Link header

Fixes: https://github.com/go-gitea/gitea/issues/13243
Fixes: https://github.com/go-gitea/gitea/issues/31856
Signed-off-by: David E. Lovas <david@rexovas.com>
Co-authored-by: bircni <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
2026-10-23 02:23:28 +00:00

424 lines
10 KiB
Go

// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package repo
import (
"testing"
issues_model "gitea.dev/models/issues"
"gitea.dev/modules/references"
"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) {
kases := []struct {
name string
beforeCombined []*issues_model.Comment
afterCombined []*issues_model.Comment
}{
{
name: "kase 1",
beforeCombined: []*issues_model.Comment{
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "",
Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeComment,
PosterID: 1,
Content: "test",
CreatedUnix: 0,
},
},
afterCombined: []*issues_model.Comment{
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
CreatedUnix: 0,
AddedLabels: []*issues_model.Label{},
Label: &issues_model.Label{
Name: "kind/bug",
},
},
{
Type: issues_model.CommentTypeComment,
PosterID: 1,
Content: "test",
CreatedUnix: 0,
},
},
},
{
name: "kase 2",
beforeCombined: []*issues_model.Comment{
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "",
Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 70,
},
{
Type: issues_model.CommentTypeComment,
PosterID: 1,
Content: "test",
CreatedUnix: 0,
},
},
afterCombined: []*issues_model.Comment{
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
CreatedUnix: 0,
AddedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
},
Label: &issues_model.Label{
Name: "kind/bug",
},
},
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "",
CreatedUnix: 70,
RemovedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
},
Label: &issues_model.Label{
Name: "kind/bug",
},
},
{
Type: issues_model.CommentTypeComment,
PosterID: 1,
Content: "test",
CreatedUnix: 0,
},
},
},
{
name: "kase 3",
beforeCombined: []*issues_model.Comment{
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeLabel,
PosterID: 2,
Content: "",
Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeComment,
PosterID: 1,
Content: "test",
CreatedUnix: 0,
},
},
afterCombined: []*issues_model.Comment{
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
CreatedUnix: 0,
AddedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
},
Label: &issues_model.Label{
Name: "kind/bug",
},
},
{
Type: issues_model.CommentTypeLabel,
PosterID: 2,
Content: "",
CreatedUnix: 0,
RemovedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
},
Label: &issues_model.Label{
Name: "kind/bug",
},
},
{
Type: issues_model.CommentTypeComment,
PosterID: 1,
Content: "test",
CreatedUnix: 0,
},
},
},
{
name: "migrated events of different original authors",
beforeCombined: []*issues_model.Comment{
{Type: issues_model.CommentTypeComment, PosterID: 1},
{Type: issues_model.CommentTypeLabel, PosterID: 1, OriginalAuthor: "alice", Content: "1", Label: &issues_model.Label{Name: "kind/bug"}},
{Type: issues_model.CommentTypeLabel, PosterID: 1, OriginalAuthor: "bob", Content: "1", Label: &issues_model.Label{Name: "kind/ui"}},
},
afterCombined: []*issues_model.Comment{
{Type: issues_model.CommentTypeComment, PosterID: 1},
{Type: issues_model.CommentTypeLabel, PosterID: 1, OriginalAuthor: "alice", Content: "1", Label: &issues_model.Label{Name: "kind/bug"}, AddedLabels: []*issues_model.Label{{Name: "kind/bug"}}},
{Type: issues_model.CommentTypeLabel, PosterID: 1, OriginalAuthor: "bob", Content: "1", Label: &issues_model.Label{Name: "kind/ui"}, AddedLabels: []*issues_model.Label{{Name: "kind/ui"}}},
},
},
{
name: "kase 4",
beforeCombined: []*issues_model.Comment{
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
Label: &issues_model.Label{
Name: "kind/backport",
},
CreatedUnix: 10,
},
},
afterCombined: []*issues_model.Comment{
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
CreatedUnix: 10,
AddedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
{
Name: "kind/backport",
},
},
Label: &issues_model.Label{
Name: "kind/bug",
},
},
},
},
{
name: "kase 5",
beforeCombined: []*issues_model.Comment{
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeComment,
PosterID: 2,
Content: "testtest",
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "",
Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
},
afterCombined: []*issues_model.Comment{
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
Label: &issues_model.Label{
Name: "kind/bug",
},
AddedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
},
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeComment,
PosterID: 2,
Content: "testtest",
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "",
RemovedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
},
Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
},
},
{
name: "kase 6",
beforeCombined: []*issues_model.Comment{
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
Label: &issues_model.Label{
Name: "reviewed/confirmed",
},
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "",
Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
Label: &issues_model.Label{
Name: "kind/feature",
},
CreatedUnix: 0,
},
},
afterCombined: []*issues_model.Comment{
{
Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
Label: &issues_model.Label{
Name: "kind/bug",
},
AddedLabels: []*issues_model.Label{
{
Name: "reviewed/confirmed",
},
{
Name: "kind/feature",
},
},
CreatedUnix: 0,
},
},
},
{
name: "project workflow",
beforeCombined: []*issues_model.Comment{
{Type: issues_model.CommentTypeLabel, PosterID: 1, Content: "1", Label: &issues_model.Label{Name: "kind/bug"}},
{Type: issues_model.CommentTypeLabel, PosterID: 1, Content: "1", Label: &issues_model.Label{Name: "status/done"}, CommentMetaData: &issues_model.CommentMetaData{SpecialDoerName: issues_model.SpecialDoerNameProjectWorkflow}},
},
afterCombined: []*issues_model.Comment{
{Type: issues_model.CommentTypeLabel, PosterID: 1, Content: "1", Label: &issues_model.Label{Name: "kind/bug"}, AddedLabels: []*issues_model.Label{{Name: "kind/bug"}}},
{Type: issues_model.CommentTypeLabel, PosterID: 1, Content: "1", Label: &issues_model.Label{Name: "status/done"}, AddedLabels: []*issues_model.Label{{Name: "status/done"}}, CommentMetaData: &issues_model.CommentMetaData{SpecialDoerName: issues_model.SpecialDoerNameProjectWorkflow}},
},
},
}
for _, kase := range kases {
t.Run(kase.name, func(t *testing.T) {
issue := issues_model.Issue{
Comments: kase.beforeCombined,
}
combineLabelComments(&issue)
assert.EqualValues(t, kase.afterCombined, issue.Comments)
})
}
}