Add context.Context to more methods (#21546)

This PR adds a context parameter to a bunch of methods. Some helper
`xxxCtx()` methods got replaced with the normal name now.

Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
KN4CK3R 2022-11-19 09:12:33 +01:00 committed by GitHub
parent fefdb7ffd1
commit 044c754ea5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
148 changed files with 1411 additions and 1564 deletions

View file

@ -5,7 +5,8 @@
package convert
import (
"code.gitea.io/gitea/models/db"
"context"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
@ -28,8 +29,8 @@ func ToComment(c *issues_model.Comment) *api.Comment {
}
// ToTimelineComment converts a issues_model.Comment to the api.TimelineComment format
func ToTimelineComment(c *issues_model.Comment, doer *user_model.User) *api.TimelineComment {
err := c.LoadMilestone()
func ToTimelineComment(ctx context.Context, c *issues_model.Comment, doer *user_model.User) *api.TimelineComment {
err := c.LoadMilestone(ctx)
if err != nil {
log.Error("LoadMilestone: %v", err)
return nil
@ -107,25 +108,25 @@ func ToTimelineComment(c *issues_model.Comment, doer *user_model.User) *api.Time
return nil
}
comment.TrackedTime = ToTrackedTime(c.Time)
comment.TrackedTime = ToTrackedTime(ctx, c.Time)
}
if c.RefIssueID != 0 {
issue, err := issues_model.GetIssueByID(db.DefaultContext, c.RefIssueID)
issue, err := issues_model.GetIssueByID(ctx, c.RefIssueID)
if err != nil {
log.Error("GetIssueByID(%d): %v", c.RefIssueID, err)
return nil
}
comment.RefIssue = ToAPIIssue(issue)
comment.RefIssue = ToAPIIssue(ctx, issue)
}
if c.RefCommentID != 0 {
com, err := issues_model.GetCommentByID(db.DefaultContext, c.RefCommentID)
com, err := issues_model.GetCommentByID(ctx, c.RefCommentID)
if err != nil {
log.Error("GetCommentByID(%d): %v", c.RefCommentID, err)
return nil
}
err = com.LoadPoster()
err = com.LoadPoster(ctx)
if err != nil {
log.Error("LoadPoster: %v", err)
return nil
@ -138,17 +139,17 @@ func ToTimelineComment(c *issues_model.Comment, doer *user_model.User) *api.Time
var repo *repo_model.Repository
if c.Label.BelongsToOrg() {
var err error
org, err = user_model.GetUserByID(c.Label.OrgID)
org, err = user_model.GetUserByIDCtx(ctx, c.Label.OrgID)
if err != nil {
log.Error("GetUserByID(%d): %v", c.Label.OrgID, err)
log.Error("GetUserByIDCtx(%d): %v", c.Label.OrgID, err)
return nil
}
}
if c.Label.BelongsToRepo() {
var err error
repo, err = repo_model.GetRepositoryByID(c.Label.RepoID)
repo, err = repo_model.GetRepositoryByIDCtx(ctx, c.Label.RepoID)
if err != nil {
log.Error("GetRepositoryByID(%d): %v", c.Label.RepoID, err)
log.Error("GetRepositoryByIDCtx(%d): %v", c.Label.RepoID, err)
return nil
}
}
@ -167,7 +168,7 @@ func ToTimelineComment(c *issues_model.Comment, doer *user_model.User) *api.Time
}
if c.DependentIssue != nil {
comment.DependentIssue = ToAPIIssue(c.DependentIssue)
comment.DependentIssue = ToAPIIssue(ctx, c.DependentIssue)
}
return comment