mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 09:07:19 +00:00
More db.DefaultContext
refactor (#27265)
Part of #27065 This PR touches functions used in templates. As templates are not static typed, errors are harder to find, but I hope I catch it all. I think some tests from other persons do not hurt.
This commit is contained in:
@ -371,42 +371,42 @@ func (c *Comment) AfterDelete(ctx context.Context) {
|
||||
}
|
||||
|
||||
// HTMLURL formats a URL-string to the issue-comment
|
||||
func (c *Comment) HTMLURL() string {
|
||||
err := c.LoadIssue(db.DefaultContext)
|
||||
func (c *Comment) HTMLURL(ctx context.Context) string {
|
||||
err := c.LoadIssue(ctx)
|
||||
if err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("LoadIssue(%d): %v", c.IssueID, err)
|
||||
return ""
|
||||
}
|
||||
err = c.Issue.LoadRepo(db.DefaultContext)
|
||||
err = c.Issue.LoadRepo(ctx)
|
||||
if err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||
return ""
|
||||
}
|
||||
return c.Issue.HTMLURL() + c.hashLink()
|
||||
return c.Issue.HTMLURL() + c.hashLink(ctx)
|
||||
}
|
||||
|
||||
// Link formats a relative URL-string to the issue-comment
|
||||
func (c *Comment) Link() string {
|
||||
err := c.LoadIssue(db.DefaultContext)
|
||||
func (c *Comment) Link(ctx context.Context) string {
|
||||
err := c.LoadIssue(ctx)
|
||||
if err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("LoadIssue(%d): %v", c.IssueID, err)
|
||||
return ""
|
||||
}
|
||||
err = c.Issue.LoadRepo(db.DefaultContext)
|
||||
err = c.Issue.LoadRepo(ctx)
|
||||
if err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||
return ""
|
||||
}
|
||||
return c.Issue.Link() + c.hashLink()
|
||||
return c.Issue.Link() + c.hashLink(ctx)
|
||||
}
|
||||
|
||||
func (c *Comment) hashLink() string {
|
||||
func (c *Comment) hashLink(ctx context.Context) string {
|
||||
if c.Type == CommentTypeCode {
|
||||
if c.ReviewID == 0 {
|
||||
return "/files#" + c.HashTag()
|
||||
}
|
||||
if c.Review == nil {
|
||||
if err := c.LoadReview(); err != nil {
|
||||
if err := c.LoadReview(ctx); err != nil {
|
||||
log.Warn("LoadReview(%d): %v", c.ReviewID, err)
|
||||
return "/files#" + c.HashTag()
|
||||
}
|
||||
@ -419,13 +419,13 @@ func (c *Comment) hashLink() string {
|
||||
}
|
||||
|
||||
// APIURL formats a API-string to the issue-comment
|
||||
func (c *Comment) APIURL() string {
|
||||
err := c.LoadIssue(db.DefaultContext)
|
||||
func (c *Comment) APIURL(ctx context.Context) string {
|
||||
err := c.LoadIssue(ctx)
|
||||
if err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("LoadIssue(%d): %v", c.IssueID, err)
|
||||
return ""
|
||||
}
|
||||
err = c.Issue.LoadRepo(db.DefaultContext)
|
||||
err = c.Issue.LoadRepo(ctx)
|
||||
if err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||
return ""
|
||||
@ -435,8 +435,8 @@ func (c *Comment) APIURL() string {
|
||||
}
|
||||
|
||||
// IssueURL formats a URL-string to the issue
|
||||
func (c *Comment) IssueURL() string {
|
||||
err := c.LoadIssue(db.DefaultContext)
|
||||
func (c *Comment) IssueURL(ctx context.Context) string {
|
||||
err := c.LoadIssue(ctx)
|
||||
if err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("LoadIssue(%d): %v", c.IssueID, err)
|
||||
return ""
|
||||
@ -446,7 +446,7 @@ func (c *Comment) IssueURL() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
err = c.Issue.LoadRepo(db.DefaultContext)
|
||||
err = c.Issue.LoadRepo(ctx)
|
||||
if err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||
return ""
|
||||
@ -455,14 +455,14 @@ func (c *Comment) IssueURL() string {
|
||||
}
|
||||
|
||||
// PRURL formats a URL-string to the pull-request
|
||||
func (c *Comment) PRURL() string {
|
||||
err := c.LoadIssue(db.DefaultContext)
|
||||
func (c *Comment) PRURL(ctx context.Context) string {
|
||||
err := c.LoadIssue(ctx)
|
||||
if err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("LoadIssue(%d): %v", c.IssueID, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
err = c.Issue.LoadRepo(db.DefaultContext)
|
||||
err = c.Issue.LoadRepo(ctx)
|
||||
if err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||
return ""
|
||||
@ -490,9 +490,9 @@ func (c *Comment) EventTag() string {
|
||||
}
|
||||
|
||||
// LoadLabel if comment.Type is CommentTypeLabel, then load Label
|
||||
func (c *Comment) LoadLabel() error {
|
||||
func (c *Comment) LoadLabel(ctx context.Context) error {
|
||||
var label Label
|
||||
has, err := db.GetEngine(db.DefaultContext).ID(c.LabelID).Get(&label)
|
||||
has, err := db.GetEngine(ctx).ID(c.LabelID).Get(&label)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if has {
|
||||
@ -506,10 +506,10 @@ func (c *Comment) LoadLabel() error {
|
||||
}
|
||||
|
||||
// LoadProject if comment.Type is CommentTypeProject, then load project.
|
||||
func (c *Comment) LoadProject() error {
|
||||
func (c *Comment) LoadProject(ctx context.Context) error {
|
||||
if c.OldProjectID > 0 {
|
||||
var oldProject project_model.Project
|
||||
has, err := db.GetEngine(db.DefaultContext).ID(c.OldProjectID).Get(&oldProject)
|
||||
has, err := db.GetEngine(ctx).ID(c.OldProjectID).Get(&oldProject)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if has {
|
||||
@ -519,7 +519,7 @@ func (c *Comment) LoadProject() error {
|
||||
|
||||
if c.ProjectID > 0 {
|
||||
var project project_model.Project
|
||||
has, err := db.GetEngine(db.DefaultContext).ID(c.ProjectID).Get(&project)
|
||||
has, err := db.GetEngine(ctx).ID(c.ProjectID).Get(&project)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if has {
|
||||
@ -569,8 +569,8 @@ func (c *Comment) LoadAttachments(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// UpdateAttachments update attachments by UUIDs for the comment
|
||||
func (c *Comment) UpdateAttachments(uuids []string) error {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
func (c *Comment) UpdateAttachments(ctx context.Context, uuids []string) error {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -591,11 +591,11 @@ func (c *Comment) UpdateAttachments(uuids []string) error {
|
||||
}
|
||||
|
||||
// LoadAssigneeUserAndTeam if comment.Type is CommentTypeAssignees, then load assignees
|
||||
func (c *Comment) LoadAssigneeUserAndTeam() error {
|
||||
func (c *Comment) LoadAssigneeUserAndTeam(ctx context.Context) error {
|
||||
var err error
|
||||
|
||||
if c.AssigneeID > 0 && c.Assignee == nil {
|
||||
c.Assignee, err = user_model.GetUserByID(db.DefaultContext, c.AssigneeID)
|
||||
c.Assignee, err = user_model.GetUserByID(ctx, c.AssigneeID)
|
||||
if err != nil {
|
||||
if !user_model.IsErrUserNotExist(err) {
|
||||
return err
|
||||
@ -603,20 +603,20 @@ func (c *Comment) LoadAssigneeUserAndTeam() error {
|
||||
c.Assignee = user_model.NewGhostUser()
|
||||
}
|
||||
} else if c.AssigneeTeamID > 0 && c.AssigneeTeam == nil {
|
||||
if err = c.LoadIssue(db.DefaultContext); err != nil {
|
||||
if err = c.LoadIssue(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = c.Issue.LoadRepo(db.DefaultContext); err != nil {
|
||||
if err = c.Issue.LoadRepo(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = c.Issue.Repo.LoadOwner(db.DefaultContext); err != nil {
|
||||
if err = c.Issue.Repo.LoadOwner(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.Issue.Repo.Owner.IsOrganization() {
|
||||
c.AssigneeTeam, err = organization.GetTeamByID(db.DefaultContext, c.AssigneeTeamID)
|
||||
c.AssigneeTeam, err = organization.GetTeamByID(ctx, c.AssigneeTeamID)
|
||||
if err != nil && !organization.IsErrTeamNotExist(err) {
|
||||
return err
|
||||
}
|
||||
@ -626,11 +626,11 @@ func (c *Comment) LoadAssigneeUserAndTeam() error {
|
||||
}
|
||||
|
||||
// LoadResolveDoer if comment.Type is CommentTypeCode and ResolveDoerID not zero, then load resolveDoer
|
||||
func (c *Comment) LoadResolveDoer() (err error) {
|
||||
func (c *Comment) LoadResolveDoer(ctx context.Context) (err error) {
|
||||
if c.ResolveDoerID == 0 || c.Type != CommentTypeCode {
|
||||
return nil
|
||||
}
|
||||
c.ResolveDoer, err = user_model.GetUserByID(db.DefaultContext, c.ResolveDoerID)
|
||||
c.ResolveDoer, err = user_model.GetUserByID(ctx, c.ResolveDoerID)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
c.ResolveDoer = user_model.NewGhostUser()
|
||||
@ -646,11 +646,11 @@ func (c *Comment) IsResolved() bool {
|
||||
}
|
||||
|
||||
// LoadDepIssueDetails loads Dependent Issue Details
|
||||
func (c *Comment) LoadDepIssueDetails() (err error) {
|
||||
func (c *Comment) LoadDepIssueDetails(ctx context.Context) (err error) {
|
||||
if c.DependentIssueID <= 0 || c.DependentIssue != nil {
|
||||
return nil
|
||||
}
|
||||
c.DependentIssue, err = GetIssueByID(db.DefaultContext, c.DependentIssueID)
|
||||
c.DependentIssue, err = GetIssueByID(ctx, c.DependentIssueID)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -683,8 +683,8 @@ func (c *Comment) loadReactions(ctx context.Context, repo *repo_model.Repository
|
||||
}
|
||||
|
||||
// LoadReactions loads comment reactions
|
||||
func (c *Comment) LoadReactions(repo *repo_model.Repository) error {
|
||||
return c.loadReactions(db.DefaultContext, repo)
|
||||
func (c *Comment) LoadReactions(ctx context.Context, repo *repo_model.Repository) error {
|
||||
return c.loadReactions(ctx, repo)
|
||||
}
|
||||
|
||||
func (c *Comment) loadReview(ctx context.Context) (err error) {
|
||||
@ -698,8 +698,8 @@ func (c *Comment) loadReview(ctx context.Context) (err error) {
|
||||
}
|
||||
|
||||
// LoadReview loads the associated review
|
||||
func (c *Comment) LoadReview() error {
|
||||
return c.loadReview(db.DefaultContext)
|
||||
func (c *Comment) LoadReview(ctx context.Context) error {
|
||||
return c.loadReview(ctx)
|
||||
}
|
||||
|
||||
// DiffSide returns "previous" if Comment.Line is a LOC of the previous changes and "proposed" if it is a LOC of the proposed changes.
|
||||
@ -719,13 +719,13 @@ func (c *Comment) UnsignedLine() uint64 {
|
||||
}
|
||||
|
||||
// CodeCommentLink returns the url to a comment in code
|
||||
func (c *Comment) CodeCommentLink() string {
|
||||
err := c.LoadIssue(db.DefaultContext)
|
||||
func (c *Comment) CodeCommentLink(ctx context.Context) string {
|
||||
err := c.LoadIssue(ctx)
|
||||
if err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("LoadIssue(%d): %v", c.IssueID, err)
|
||||
return ""
|
||||
}
|
||||
err = c.Issue.LoadRepo(db.DefaultContext)
|
||||
err = c.Issue.LoadRepo(ctx)
|
||||
if err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||
return ""
|
||||
@ -1074,8 +1074,8 @@ func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList,
|
||||
}
|
||||
|
||||
// CountComments count all comments according options by ignoring pagination
|
||||
func CountComments(opts *FindCommentsOptions) (int64, error) {
|
||||
sess := db.GetEngine(db.DefaultContext).Where(opts.ToConds())
|
||||
func CountComments(ctx context.Context, opts *FindCommentsOptions) (int64, error) {
|
||||
sess := db.GetEngine(ctx).Where(opts.ToConds())
|
||||
if opts.RepoID > 0 {
|
||||
sess.Join("INNER", "issue", "issue.id = comment.issue_id")
|
||||
}
|
||||
@ -1089,8 +1089,8 @@ func UpdateCommentInvalidate(ctx context.Context, c *Comment) error {
|
||||
}
|
||||
|
||||
// UpdateComment updates information of comment.
|
||||
func UpdateComment(c *Comment, doer *user_model.User) error {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
func UpdateComment(ctx context.Context, c *Comment, doer *user_model.User) error {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1147,8 +1147,8 @@ func DeleteComment(ctx context.Context, comment *Comment) error {
|
||||
}
|
||||
|
||||
// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id
|
||||
func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
|
||||
_, err := db.GetEngine(db.DefaultContext).Table("comment").
|
||||
func UpdateCommentsMigrationsByType(ctx context.Context, tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
|
||||
_, err := db.GetEngine(ctx).Table("comment").
|
||||
Where(builder.In("issue_id",
|
||||
builder.Select("issue.id").
|
||||
From("issue").
|
||||
@ -1250,7 +1250,7 @@ func (c *Comment) HasOriginalAuthor() bool {
|
||||
}
|
||||
|
||||
// InsertIssueComments inserts many comments of issues.
|
||||
func InsertIssueComments(comments []*Comment) error {
|
||||
func InsertIssueComments(ctx context.Context, comments []*Comment) error {
|
||||
if len(comments) == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -1260,7 +1260,7 @@ func InsertIssueComments(comments []*Comment) error {
|
||||
issueIDs.Add(comment.IssueID)
|
||||
}
|
||||
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -99,11 +99,11 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
|
||||
comments[n] = comment
|
||||
n++
|
||||
|
||||
if err := comment.LoadResolveDoer(); err != nil {
|
||||
if err := comment.LoadResolveDoer(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := comment.LoadReactions(issue.Repo); err != nil {
|
||||
if err := comment.LoadReactions(ctx, issue.Repo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ func TestMigrate_InsertIssueComments(t *testing.T) {
|
||||
Reactions: []*issues_model.Reaction{reaction},
|
||||
}
|
||||
|
||||
err := issues_model.InsertIssueComments([]*issues_model.Comment{comment})
|
||||
err := issues_model.InsertIssueComments(db.DefaultContext, []*issues_model.Comment{comment})
|
||||
assert.NoError(t, err)
|
||||
|
||||
issueModified := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
|
||||
|
@ -253,7 +253,7 @@ func testInsertIssue(t *testing.T, title, content string, expectIndex int64) *is
|
||||
Title: title,
|
||||
Content: content,
|
||||
}
|
||||
err := issues_model.NewIssue(repo, &issue, nil, nil)
|
||||
err := issues_model.NewIssue(db.DefaultContext, repo, &issue, nil, nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
has, err := db.GetEngine(db.DefaultContext).ID(issue.ID).Get(&newIssue)
|
||||
|
@ -165,8 +165,8 @@ func ChangeIssueTitle(ctx context.Context, issue *Issue, doer *user_model.User,
|
||||
}
|
||||
|
||||
// ChangeIssueRef changes the branch of this issue, as the given user.
|
||||
func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err error) {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
func ChangeIssueRef(ctx context.Context, issue *Issue, doer *user_model.User, oldRef string) (err error) {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -215,8 +215,8 @@ func AddDeletePRBranchComment(ctx context.Context, doer *user_model.User, repo *
|
||||
}
|
||||
|
||||
// UpdateIssueAttachments update attachments by UUIDs for the issue
|
||||
func UpdateIssueAttachments(issueID int64, uuids []string) (err error) {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
func UpdateIssueAttachments(ctx context.Context, issueID int64, uuids []string) (err error) {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -235,8 +235,8 @@ func UpdateIssueAttachments(issueID int64, uuids []string) (err error) {
|
||||
}
|
||||
|
||||
// ChangeIssueContent changes issue content, as the given user.
|
||||
func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (err error) {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
func ChangeIssueContent(ctx context.Context, issue *Issue, doer *user_model.User, content string) (err error) {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -381,8 +381,8 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
|
||||
}
|
||||
|
||||
// NewIssue creates new issue with labels for repository.
|
||||
func NewIssue(repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -432,8 +432,8 @@ func UpdateIssueMentions(ctx context.Context, issueID int64, mentions []*user_mo
|
||||
// UpdateIssueByAPI updates all allowed fields of given issue.
|
||||
// If the issue status is changed a statusChangeComment is returned
|
||||
// similarly if the title is changed the titleChanged bool is set to true
|
||||
func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment *Comment, titleChanged bool, err error) {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
func UpdateIssueByAPI(ctx context.Context, issue *Issue, doer *user_model.User) (statusChangeComment *Comment, titleChanged bool, err error) {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@ -486,12 +486,12 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment
|
||||
}
|
||||
|
||||
// UpdateIssueDeadline updates an issue deadline and adds comments. Setting a deadline to 0 means deleting it.
|
||||
func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *user_model.User) (err error) {
|
||||
func UpdateIssueDeadline(ctx context.Context, issue *Issue, deadlineUnix timeutil.TimeStamp, doer *user_model.User) (err error) {
|
||||
// if the deadline hasn't changed do nothing
|
||||
if issue.DeadlineUnix == deadlineUnix {
|
||||
return nil
|
||||
}
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -669,8 +669,8 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
|
||||
}
|
||||
|
||||
// UpdateIssuesMigrationsByType updates all migrated repositories' issues from gitServiceType to replace originalAuthorID to posterID
|
||||
func UpdateIssuesMigrationsByType(gitServiceType api.GitServiceType, originalAuthorID string, posterID int64) error {
|
||||
_, err := db.GetEngine(db.DefaultContext).Table("issue").
|
||||
func UpdateIssuesMigrationsByType(ctx context.Context, gitServiceType api.GitServiceType, originalAuthorID string, posterID int64) error {
|
||||
_, err := db.GetEngine(ctx).Table("issue").
|
||||
Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
|
||||
And("original_author_id = ?", originalAuthorID).
|
||||
Update(map[string]any{
|
||||
@ -682,8 +682,8 @@ func UpdateIssuesMigrationsByType(gitServiceType api.GitServiceType, originalAut
|
||||
}
|
||||
|
||||
// UpdateReactionsMigrationsByType updates all migrated repositories' reactions from gitServiceType to replace originalAuthorID to posterID
|
||||
func UpdateReactionsMigrationsByType(gitServiceType api.GitServiceType, originalAuthorID string, userID int64) error {
|
||||
_, err := db.GetEngine(db.DefaultContext).Table("reaction").
|
||||
func UpdateReactionsMigrationsByType(ctx context.Context, gitServiceType api.GitServiceType, originalAuthorID string, userID int64) error {
|
||||
_, err := db.GetEngine(ctx).Table("reaction").
|
||||
Where("original_author_id = ?", originalAuthorID).
|
||||
And(migratedIssueCond(gitServiceType)).
|
||||
Update(map[string]any{
|
||||
@ -809,7 +809,7 @@ func DeleteOrphanedIssues(ctx context.Context) error {
|
||||
|
||||
// Remove issue attachment files.
|
||||
for i := range attachmentPaths {
|
||||
system_model.RemoveAllWithNotice(db.DefaultContext, "Delete issue attachment", attachmentPaths[i])
|
||||
system_model.RemoveAllWithNotice(ctx, "Delete issue attachment", attachmentPaths[i])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -252,22 +252,22 @@ func (c *Comment) neuterCrossReferences(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// LoadRefComment loads comment that created this reference from database
|
||||
func (c *Comment) LoadRefComment() (err error) {
|
||||
func (c *Comment) LoadRefComment(ctx context.Context) (err error) {
|
||||
if c.RefComment != nil {
|
||||
return nil
|
||||
}
|
||||
c.RefComment, err = GetCommentByID(db.DefaultContext, c.RefCommentID)
|
||||
c.RefComment, err = GetCommentByID(ctx, c.RefCommentID)
|
||||
return err
|
||||
}
|
||||
|
||||
// LoadRefIssue loads comment that created this reference from database
|
||||
func (c *Comment) LoadRefIssue() (err error) {
|
||||
func (c *Comment) LoadRefIssue(ctx context.Context) (err error) {
|
||||
if c.RefIssue != nil {
|
||||
return nil
|
||||
}
|
||||
c.RefIssue, err = GetIssueByID(db.DefaultContext, c.RefIssueID)
|
||||
c.RefIssue, err = GetIssueByID(ctx, c.RefIssueID)
|
||||
if err == nil {
|
||||
err = c.RefIssue.LoadRepo(db.DefaultContext)
|
||||
err = c.RefIssue.LoadRepo(ctx)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@ -278,21 +278,21 @@ func CommentTypeIsRef(t CommentType) bool {
|
||||
}
|
||||
|
||||
// RefCommentLink returns the relative URL for the comment that created this reference
|
||||
func (c *Comment) RefCommentLink() string {
|
||||
func (c *Comment) RefCommentLink(ctx context.Context) string {
|
||||
// Edge case for when the reference is inside the title or the description of the referring issue
|
||||
if c.RefCommentID == 0 {
|
||||
return c.RefIssueLink()
|
||||
return c.RefIssueLink(ctx)
|
||||
}
|
||||
if err := c.LoadRefComment(); err != nil { // Silently dropping errors :unamused:
|
||||
if err := c.LoadRefComment(ctx); err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("LoadRefComment(%d): %v", c.RefCommentID, err)
|
||||
return ""
|
||||
}
|
||||
return c.RefComment.Link()
|
||||
return c.RefComment.Link(ctx)
|
||||
}
|
||||
|
||||
// RefIssueLink returns the relative URL of the issue where this reference was created
|
||||
func (c *Comment) RefIssueLink() string {
|
||||
if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
|
||||
func (c *Comment) RefIssueLink(ctx context.Context) string {
|
||||
if err := c.LoadRefIssue(ctx); err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
|
||||
return ""
|
||||
}
|
||||
@ -300,8 +300,8 @@ func (c *Comment) RefIssueLink() string {
|
||||
}
|
||||
|
||||
// RefIssueTitle returns the title of the issue where this reference was created
|
||||
func (c *Comment) RefIssueTitle() string {
|
||||
if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
|
||||
func (c *Comment) RefIssueTitle(ctx context.Context) string {
|
||||
if err := c.LoadRefIssue(ctx); err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
|
||||
return ""
|
||||
}
|
||||
@ -309,8 +309,8 @@ func (c *Comment) RefIssueTitle() string {
|
||||
}
|
||||
|
||||
// RefIssueIdent returns the user friendly identity (e.g. "#1234") of the issue where this reference was created
|
||||
func (c *Comment) RefIssueIdent() string {
|
||||
if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
|
||||
func (c *Comment) RefIssueIdent(ctx context.Context) string {
|
||||
if err := c.LoadRefIssue(ctx); err != nil { // Silently dropping errors :unamused:
|
||||
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
|
||||
return ""
|
||||
}
|
||||
|
@ -329,8 +329,8 @@ func GetCurrentReview(ctx context.Context, reviewer *user_model.User, issue *Iss
|
||||
}
|
||||
|
||||
// ReviewExists returns whether a review exists for a particular line of code in the PR
|
||||
func ReviewExists(issue *Issue, treePath string, line int64) (bool, error) {
|
||||
return db.GetEngine(db.DefaultContext).Cols("id").Exist(&Comment{IssueID: issue.ID, TreePath: treePath, Line: line, Type: CommentTypeCode})
|
||||
func ReviewExists(ctx context.Context, issue *Issue, treePath string, line int64) (bool, error) {
|
||||
return db.GetEngine(ctx).Cols("id").Exist(&Comment{IssueID: issue.ID, TreePath: treePath, Line: line, Type: CommentTypeCode})
|
||||
}
|
||||
|
||||
// ContentEmptyErr represents an content empty error
|
||||
@ -347,8 +347,8 @@ func IsContentEmptyErr(err error) bool {
|
||||
}
|
||||
|
||||
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
|
||||
func SubmitReview(doer *user_model.User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool, attachmentUUIDs []string) (*Review, *Comment, error) {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
func SubmitReview(ctx context.Context, doer *user_model.User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool, attachmentUUIDs []string) (*Review, *Comment, error) {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -494,15 +494,15 @@ func GetTeamReviewerByIssueIDAndTeamID(ctx context.Context, issueID, teamID int6
|
||||
}
|
||||
|
||||
// MarkReviewsAsStale marks existing reviews as stale
|
||||
func MarkReviewsAsStale(issueID int64) (err error) {
|
||||
_, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `review` SET stale=? WHERE issue_id=?", true, issueID)
|
||||
func MarkReviewsAsStale(ctx context.Context, issueID int64) (err error) {
|
||||
_, err = db.GetEngine(ctx).Exec("UPDATE `review` SET stale=? WHERE issue_id=?", true, issueID)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// MarkReviewsAsNotStale marks existing reviews as not stale for a giving commit SHA
|
||||
func MarkReviewsAsNotStale(issueID int64, commitID string) (err error) {
|
||||
_, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `review` SET stale=? WHERE issue_id=? AND commit_id=?", false, issueID, commitID)
|
||||
func MarkReviewsAsNotStale(ctx context.Context, issueID int64, commitID string) (err error) {
|
||||
_, err = db.GetEngine(ctx).Exec("UPDATE `review` SET stale=? WHERE issue_id=? AND commit_id=?", false, issueID, commitID)
|
||||
|
||||
return err
|
||||
}
|
||||
@ -525,8 +525,8 @@ func DismissReview(ctx context.Context, review *Review, isDismiss bool) (err err
|
||||
}
|
||||
|
||||
// InsertReviews inserts review and review comments
|
||||
func InsertReviews(reviews []*Review) error {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
func InsertReviews(ctx context.Context, reviews []*Review) error {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -803,7 +803,7 @@ func RemoveTeamReviewRequest(ctx context.Context, issue *Issue, reviewer *organi
|
||||
}
|
||||
|
||||
// MarkConversation Add or remove Conversation mark for a code comment
|
||||
func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (err error) {
|
||||
func MarkConversation(ctx context.Context, comment *Comment, doer *user_model.User, isResolve bool) (err error) {
|
||||
if comment.Type != CommentTypeCode {
|
||||
return nil
|
||||
}
|
||||
@ -813,7 +813,7 @@ func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", doer.ID, comment.ID); err != nil {
|
||||
if _, err = db.GetEngine(ctx).Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", doer.ID, comment.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
@ -821,7 +821,7 @@ func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", 0, comment.ID); err != nil {
|
||||
if _, err = db.GetEngine(ctx).Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", 0, comment.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -831,24 +831,24 @@ func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (
|
||||
|
||||
// CanMarkConversation Add or remove Conversation mark for a code comment permission check
|
||||
// the PR writer , offfcial reviewer and poster can do it
|
||||
func CanMarkConversation(issue *Issue, doer *user_model.User) (permResult bool, err error) {
|
||||
func CanMarkConversation(ctx context.Context, issue *Issue, doer *user_model.User) (permResult bool, err error) {
|
||||
if doer == nil || issue == nil {
|
||||
return false, fmt.Errorf("issue or doer is nil")
|
||||
}
|
||||
|
||||
if doer.ID != issue.PosterID {
|
||||
if err = issue.LoadRepo(db.DefaultContext); err != nil {
|
||||
if err = issue.LoadRepo(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
p, err := access_model.GetUserRepoPermission(db.DefaultContext, issue.Repo, doer)
|
||||
p, err := access_model.GetUserRepoPermission(ctx, issue.Repo, doer)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
permResult = p.CanAccess(perm.AccessModeWrite, unit.TypePullRequests)
|
||||
if !permResult {
|
||||
if permResult, err = IsOfficialReviewer(db.DefaultContext, issue, doer); err != nil {
|
||||
if permResult, err = IsOfficialReviewer(ctx, issue, doer); err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
@ -862,8 +862,8 @@ func CanMarkConversation(issue *Issue, doer *user_model.User) (permResult bool,
|
||||
}
|
||||
|
||||
// DeleteReview delete a review and it's code comments
|
||||
func DeleteReview(r *Review) error {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
func DeleteReview(ctx context.Context, r *Review) error {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -912,7 +912,7 @@ func DeleteReview(r *Review) error {
|
||||
}
|
||||
|
||||
// GetCodeCommentsCount return count of CodeComments a Review has
|
||||
func (r *Review) GetCodeCommentsCount() int {
|
||||
func (r *Review) GetCodeCommentsCount(ctx context.Context) int {
|
||||
opts := FindCommentsOptions{
|
||||
Type: CommentTypeCode,
|
||||
IssueID: r.IssueID,
|
||||
@ -923,7 +923,7 @@ func (r *Review) GetCodeCommentsCount() int {
|
||||
conds = conds.And(builder.Eq{"invalidated": false})
|
||||
}
|
||||
|
||||
count, err := db.GetEngine(db.DefaultContext).Where(conds).Count(new(Comment))
|
||||
count, err := db.GetEngine(ctx).Where(conds).Count(new(Comment))
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
@ -931,18 +931,18 @@ func (r *Review) GetCodeCommentsCount() int {
|
||||
}
|
||||
|
||||
// HTMLURL formats a URL-string to the related review issue-comment
|
||||
func (r *Review) HTMLURL() string {
|
||||
func (r *Review) HTMLURL(ctx context.Context) string {
|
||||
opts := FindCommentsOptions{
|
||||
Type: CommentTypeReview,
|
||||
IssueID: r.IssueID,
|
||||
ReviewID: r.ID,
|
||||
}
|
||||
comment := new(Comment)
|
||||
has, err := db.GetEngine(db.DefaultContext).Where(opts.ToConds()).Get(comment)
|
||||
has, err := db.GetEngine(ctx).Where(opts.ToConds()).Get(comment)
|
||||
if err != nil || !has {
|
||||
return ""
|
||||
}
|
||||
return comment.HTMLURL()
|
||||
return comment.HTMLURL(ctx)
|
||||
}
|
||||
|
||||
// RemapExternalUser ExternalUserRemappable interface
|
||||
@ -963,8 +963,8 @@ func (r *Review) GetExternalName() string { return r.OriginalAuthor }
|
||||
func (r *Review) GetExternalID() int64 { return r.OriginalAuthorID }
|
||||
|
||||
// UpdateReviewsMigrationsByType updates reviews' migrations information via given git service type and original id and poster id
|
||||
func UpdateReviewsMigrationsByType(tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
|
||||
_, err := db.GetEngine(db.DefaultContext).Table("review").
|
||||
func UpdateReviewsMigrationsByType(ctx context.Context, tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
|
||||
_, err := db.GetEngine(ctx).Table("review").
|
||||
Where("original_author_id = ?", originalAuthorID).
|
||||
And(migratedIssueCond(tp)).
|
||||
Update(map[string]any{
|
||||
|
@ -248,7 +248,7 @@ func TestDeleteReview(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, issues_model.DeleteReview(review2))
|
||||
assert.NoError(t, issues_model.DeleteReview(db.DefaultContext, review2))
|
||||
|
||||
_, err = issues_model.GetReviewByID(db.DefaultContext, review2.ID)
|
||||
assert.Error(t, err)
|
||||
|
Reference in New Issue
Block a user