1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-13 14:07:20 +00:00

refactor: decouple context from migration structs (#33399)

Use context as much as possible.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
TheFox0x7
2025-02-07 06:37:32 +01:00
committed by GitHub
parent 466cc725bc
commit 1ec8d80fa3
23 changed files with 455 additions and 509 deletions

View File

@ -22,11 +22,12 @@ func TestOneDevDownloadRepo(t *testing.T) {
}
u, _ := url.Parse("https://code.onedev.io")
downloader := NewOneDevDownloader(context.Background(), u, "", "", "go-gitea-test_repo")
ctx := context.Background()
downloader := NewOneDevDownloader(ctx, u, "", "", "go-gitea-test_repo")
if err != nil {
t.Fatalf("NewOneDevDownloader is nil: %v", err)
}
repo, err := downloader.GetRepoInfo()
repo, err := downloader.GetRepoInfo(ctx)
assert.NoError(t, err)
assertRepositoryEqual(t, &base.Repository{
Name: "go-gitea-test_repo",
@ -36,7 +37,7 @@ func TestOneDevDownloadRepo(t *testing.T) {
OriginalURL: "https://code.onedev.io/projects/go-gitea-test_repo",
}, repo)
milestones, err := downloader.GetMilestones()
milestones, err := downloader.GetMilestones(ctx)
assert.NoError(t, err)
deadline := time.Unix(1620086400, 0)
assertMilestonesEqual(t, []*base.Milestone{
@ -51,11 +52,11 @@ func TestOneDevDownloadRepo(t *testing.T) {
},
}, milestones)
labels, err := downloader.GetLabels()
labels, err := downloader.GetLabels(ctx)
assert.NoError(t, err)
assert.Len(t, labels, 6)
issues, isEnd, err := downloader.GetIssues(1, 2)
issues, isEnd, err := downloader.GetIssues(ctx, 1, 2)
assert.NoError(t, err)
assert.False(t, isEnd)
assertIssuesEqual(t, []*base.Issue{
@ -94,7 +95,7 @@ func TestOneDevDownloadRepo(t *testing.T) {
},
}, issues)
comments, _, err := downloader.GetComments(&base.Issue{
comments, _, err := downloader.GetComments(ctx, &base.Issue{
Number: 4,
ForeignIndex: 398,
Context: onedevIssueContext{IsPullRequest: false},
@ -110,7 +111,7 @@ func TestOneDevDownloadRepo(t *testing.T) {
},
}, comments)
prs, _, err := downloader.GetPullRequests(1, 1)
prs, _, err := downloader.GetPullRequests(ctx, 1, 1)
assert.NoError(t, err)
assertPullRequestsEqual(t, []*base.PullRequest{
{
@ -136,7 +137,7 @@ func TestOneDevDownloadRepo(t *testing.T) {
},
}, prs)
rvs, err := downloader.GetReviews(&base.PullRequest{Number: 5, ForeignIndex: 186})
rvs, err := downloader.GetReviews(ctx, &base.PullRequest{Number: 5, ForeignIndex: 186})
assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{
{