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:
@ -49,21 +49,15 @@ func (d *RetryDownloader) retry(work func() error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// SetContext set context
|
||||
func (d *RetryDownloader) SetContext(ctx context.Context) {
|
||||
d.ctx = ctx
|
||||
d.Downloader.SetContext(ctx)
|
||||
}
|
||||
|
||||
// GetRepoInfo returns a repository information with retry
|
||||
func (d *RetryDownloader) GetRepoInfo() (*Repository, error) {
|
||||
func (d *RetryDownloader) GetRepoInfo(ctx context.Context) (*Repository, error) {
|
||||
var (
|
||||
repo *Repository
|
||||
err error
|
||||
)
|
||||
|
||||
err = d.retry(func() error {
|
||||
repo, err = d.Downloader.GetRepoInfo()
|
||||
repo, err = d.Downloader.GetRepoInfo(ctx)
|
||||
return err
|
||||
})
|
||||
|
||||
@ -71,14 +65,14 @@ func (d *RetryDownloader) GetRepoInfo() (*Repository, error) {
|
||||
}
|
||||
|
||||
// GetTopics returns a repository's topics with retry
|
||||
func (d *RetryDownloader) GetTopics() ([]string, error) {
|
||||
func (d *RetryDownloader) GetTopics(ctx context.Context) ([]string, error) {
|
||||
var (
|
||||
topics []string
|
||||
err error
|
||||
)
|
||||
|
||||
err = d.retry(func() error {
|
||||
topics, err = d.Downloader.GetTopics()
|
||||
topics, err = d.Downloader.GetTopics(ctx)
|
||||
return err
|
||||
})
|
||||
|
||||
@ -86,14 +80,14 @@ func (d *RetryDownloader) GetTopics() ([]string, error) {
|
||||
}
|
||||
|
||||
// GetMilestones returns a repository's milestones with retry
|
||||
func (d *RetryDownloader) GetMilestones() ([]*Milestone, error) {
|
||||
func (d *RetryDownloader) GetMilestones(ctx context.Context) ([]*Milestone, error) {
|
||||
var (
|
||||
milestones []*Milestone
|
||||
err error
|
||||
)
|
||||
|
||||
err = d.retry(func() error {
|
||||
milestones, err = d.Downloader.GetMilestones()
|
||||
milestones, err = d.Downloader.GetMilestones(ctx)
|
||||
return err
|
||||
})
|
||||
|
||||
@ -101,14 +95,14 @@ func (d *RetryDownloader) GetMilestones() ([]*Milestone, error) {
|
||||
}
|
||||
|
||||
// GetReleases returns a repository's releases with retry
|
||||
func (d *RetryDownloader) GetReleases() ([]*Release, error) {
|
||||
func (d *RetryDownloader) GetReleases(ctx context.Context) ([]*Release, error) {
|
||||
var (
|
||||
releases []*Release
|
||||
err error
|
||||
)
|
||||
|
||||
err = d.retry(func() error {
|
||||
releases, err = d.Downloader.GetReleases()
|
||||
releases, err = d.Downloader.GetReleases(ctx)
|
||||
return err
|
||||
})
|
||||
|
||||
@ -116,14 +110,14 @@ func (d *RetryDownloader) GetReleases() ([]*Release, error) {
|
||||
}
|
||||
|
||||
// GetLabels returns a repository's labels with retry
|
||||
func (d *RetryDownloader) GetLabels() ([]*Label, error) {
|
||||
func (d *RetryDownloader) GetLabels(ctx context.Context) ([]*Label, error) {
|
||||
var (
|
||||
labels []*Label
|
||||
err error
|
||||
)
|
||||
|
||||
err = d.retry(func() error {
|
||||
labels, err = d.Downloader.GetLabels()
|
||||
labels, err = d.Downloader.GetLabels(ctx)
|
||||
return err
|
||||
})
|
||||
|
||||
@ -131,7 +125,7 @@ func (d *RetryDownloader) GetLabels() ([]*Label, error) {
|
||||
}
|
||||
|
||||
// GetIssues returns a repository's issues with retry
|
||||
func (d *RetryDownloader) GetIssues(page, perPage int) ([]*Issue, bool, error) {
|
||||
func (d *RetryDownloader) GetIssues(ctx context.Context, page, perPage int) ([]*Issue, bool, error) {
|
||||
var (
|
||||
issues []*Issue
|
||||
isEnd bool
|
||||
@ -139,7 +133,7 @@ func (d *RetryDownloader) GetIssues(page, perPage int) ([]*Issue, bool, error) {
|
||||
)
|
||||
|
||||
err = d.retry(func() error {
|
||||
issues, isEnd, err = d.Downloader.GetIssues(page, perPage)
|
||||
issues, isEnd, err = d.Downloader.GetIssues(ctx, page, perPage)
|
||||
return err
|
||||
})
|
||||
|
||||
@ -147,7 +141,7 @@ func (d *RetryDownloader) GetIssues(page, perPage int) ([]*Issue, bool, error) {
|
||||
}
|
||||
|
||||
// GetComments returns a repository's comments with retry
|
||||
func (d *RetryDownloader) GetComments(commentable Commentable) ([]*Comment, bool, error) {
|
||||
func (d *RetryDownloader) GetComments(ctx context.Context, commentable Commentable) ([]*Comment, bool, error) {
|
||||
var (
|
||||
comments []*Comment
|
||||
isEnd bool
|
||||
@ -155,7 +149,7 @@ func (d *RetryDownloader) GetComments(commentable Commentable) ([]*Comment, bool
|
||||
)
|
||||
|
||||
err = d.retry(func() error {
|
||||
comments, isEnd, err = d.Downloader.GetComments(commentable)
|
||||
comments, isEnd, err = d.Downloader.GetComments(ctx, commentable)
|
||||
return err
|
||||
})
|
||||
|
||||
@ -163,7 +157,7 @@ func (d *RetryDownloader) GetComments(commentable Commentable) ([]*Comment, bool
|
||||
}
|
||||
|
||||
// GetPullRequests returns a repository's pull requests with retry
|
||||
func (d *RetryDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bool, error) {
|
||||
func (d *RetryDownloader) GetPullRequests(ctx context.Context, page, perPage int) ([]*PullRequest, bool, error) {
|
||||
var (
|
||||
prs []*PullRequest
|
||||
err error
|
||||
@ -171,7 +165,7 @@ func (d *RetryDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bo
|
||||
)
|
||||
|
||||
err = d.retry(func() error {
|
||||
prs, isEnd, err = d.Downloader.GetPullRequests(page, perPage)
|
||||
prs, isEnd, err = d.Downloader.GetPullRequests(ctx, page, perPage)
|
||||
return err
|
||||
})
|
||||
|
||||
@ -179,14 +173,13 @@ func (d *RetryDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bo
|
||||
}
|
||||
|
||||
// GetReviews returns pull requests reviews
|
||||
func (d *RetryDownloader) GetReviews(reviewable Reviewable) ([]*Review, error) {
|
||||
func (d *RetryDownloader) GetReviews(ctx context.Context, reviewable Reviewable) ([]*Review, error) {
|
||||
var (
|
||||
reviews []*Review
|
||||
err error
|
||||
)
|
||||
|
||||
err = d.retry(func() error {
|
||||
reviews, err = d.Downloader.GetReviews(reviewable)
|
||||
reviews, err = d.Downloader.GetReviews(ctx, reviewable)
|
||||
return err
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user