diff options
author | Giteabot <teabot@gitea.io> | 2023-09-29 21:35:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-29 13:35:01 +0000 |
commit | f13a294b47e901e22ec02d9b9d92ddd835155f53 (patch) | |
tree | 87bbe9736cda387bdcc129aca62db660849ff9f8 /services | |
parent | 84ee02faa7086504f45cb1dc3ae01c4937653936 (diff) | |
download | gitea-f13a294b47e901e22ec02d9b9d92ddd835155f53.tar.gz gitea-f13a294b47e901e22ec02d9b9d92ddd835155f53.zip |
More `db.DefaultContext` refactor (#27265) (#27347)
Backport #27265 by @JakobDev
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.
Co-authored-by: JakobDev <jakobdev@gmx.de>
Diffstat (limited to 'services')
-rw-r--r-- | services/convert/issue_comment.go | 20 | ||||
-rw-r--r-- | services/convert/notification.go | 18 | ||||
-rw-r--r-- | services/convert/pull_review.go | 6 | ||||
-rw-r--r-- | services/cron/tasks_extended.go | 2 | ||||
-rw-r--r-- | services/externalaccount/user.go | 8 | ||||
-rw-r--r-- | services/feed/action.go | 2 | ||||
-rw-r--r-- | services/issue/comments.go | 2 | ||||
-rw-r--r-- | services/issue/content.go | 2 | ||||
-rw-r--r-- | services/issue/issue.go | 4 | ||||
-rw-r--r-- | services/migrations/gitea_uploader.go | 4 | ||||
-rw-r--r-- | services/mirror/mirror.go | 4 | ||||
-rw-r--r-- | services/mirror/mirror_pull.go | 4 | ||||
-rw-r--r-- | services/pull/pull.go | 4 | ||||
-rw-r--r-- | services/pull/review.go | 4 | ||||
-rw-r--r-- | services/uinotification/notify.go | 2 |
15 files changed, 43 insertions, 43 deletions
diff --git a/services/convert/issue_comment.go b/services/convert/issue_comment.go index 1308051e7c..f2bb4c88f3 100644 --- a/services/convert/issue_comment.go +++ b/services/convert/issue_comment.go @@ -19,9 +19,9 @@ func ToAPIComment(ctx context.Context, repo *repo_model.Repository, c *issues_mo return &api.Comment{ ID: c.ID, Poster: ToUser(ctx, c.Poster, nil), - HTMLURL: c.HTMLURL(), - IssueURL: c.IssueURL(), - PRURL: c.PRURL(), + HTMLURL: c.HTMLURL(ctx), + IssueURL: c.IssueURL(ctx), + PRURL: c.PRURL(ctx), Body: c.Content, Attachments: ToAPIAttachments(repo, c.Attachments), Created: c.CreatedUnix.AsTime(), @@ -37,19 +37,19 @@ func ToTimelineComment(ctx context.Context, repo *repo_model.Repository, c *issu return nil } - err = c.LoadAssigneeUserAndTeam() + err = c.LoadAssigneeUserAndTeam(ctx) if err != nil { log.Error("LoadAssigneeUserAndTeam: %v", err) return nil } - err = c.LoadResolveDoer() + err = c.LoadResolveDoer(ctx) if err != nil { log.Error("LoadResolveDoer: %v", err) return nil } - err = c.LoadDepIssueDetails() + err = c.LoadDepIssueDetails(ctx) if err != nil { log.Error("LoadDepIssueDetails: %v", err) return nil @@ -61,7 +61,7 @@ func ToTimelineComment(ctx context.Context, repo *repo_model.Repository, c *issu return nil } - err = c.LoadLabel() + err = c.LoadLabel(ctx) if err != nil { log.Error("LoadLabel: %v", err) return nil @@ -82,9 +82,9 @@ func ToTimelineComment(ctx context.Context, repo *repo_model.Repository, c *issu ID: c.ID, Type: c.Type.String(), Poster: ToUser(ctx, c.Poster, nil), - HTMLURL: c.HTMLURL(), - IssueURL: c.IssueURL(), - PRURL: c.PRURL(), + HTMLURL: c.HTMLURL(ctx), + IssueURL: c.IssueURL(ctx), + PRURL: c.PRURL(ctx), Body: c.Content, Created: c.CreatedUnix.AsTime(), Updated: c.UpdatedUnix.AsTime(), diff --git a/services/convert/notification.go b/services/convert/notification.go index 3906fa9b38..7f724cf156 100644 --- a/services/convert/notification.go +++ b/services/convert/notification.go @@ -4,17 +4,17 @@ package convert import ( + "context" "net/url" activities_model "code.gitea.io/gitea/models/activities" - "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/perm" access_model "code.gitea.io/gitea/models/perm/access" api "code.gitea.io/gitea/modules/structs" ) // ToNotificationThread convert a Notification to api.NotificationThread -func ToNotificationThread(n *activities_model.Notification) *api.NotificationThread { +func ToNotificationThread(ctx context.Context, n *activities_model.Notification) *api.NotificationThread { result := &api.NotificationThread{ ID: n.ID, Unread: !(n.Status == activities_model.NotificationStatusRead || n.Status == activities_model.NotificationStatusPinned), @@ -25,7 +25,7 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr // since user only get notifications when he has access to use minimal access mode if n.Repository != nil { - result.Repository = ToRepo(db.DefaultContext, n.Repository, access_model.Permission{AccessMode: perm.AccessModeRead}) + result.Repository = ToRepo(ctx, n.Repository, access_model.Permission{AccessMode: perm.AccessModeRead}) // This permission is not correct and we should not be reporting it for repository := result.Repository; repository != nil; repository = repository.Parent { @@ -44,8 +44,8 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr result.Subject.State = n.Issue.State() comment, err := n.Issue.GetLastComment() if err == nil && comment != nil { - result.Subject.LatestCommentURL = comment.APIURL() - result.Subject.LatestCommentHTMLURL = comment.HTMLURL() + result.Subject.LatestCommentURL = comment.APIURL(ctx) + result.Subject.LatestCommentHTMLURL = comment.HTMLURL(ctx) } } case activities_model.NotificationSourcePullRequest: @@ -57,8 +57,8 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr result.Subject.State = n.Issue.State() comment, err := n.Issue.GetLastComment() if err == nil && comment != nil { - result.Subject.LatestCommentURL = comment.APIURL() - result.Subject.LatestCommentHTMLURL = comment.HTMLURL() + result.Subject.LatestCommentURL = comment.APIURL(ctx) + result.Subject.LatestCommentHTMLURL = comment.HTMLURL(ctx) } pr, _ := n.Issue.GetPullRequest() @@ -88,10 +88,10 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr } // ToNotifications convert list of Notification to api.NotificationThread list -func ToNotifications(nl activities_model.NotificationList) []*api.NotificationThread { +func ToNotifications(ctx context.Context, nl activities_model.NotificationList) []*api.NotificationThread { result := make([]*api.NotificationThread, 0, len(nl)) for _, n := range nl { - result = append(result, ToNotificationThread(n)) + result = append(result, ToNotificationThread(ctx, n)) } return result } diff --git a/services/convert/pull_review.go b/services/convert/pull_review.go index 5d5d5d883c..0332606285 100644 --- a/services/convert/pull_review.go +++ b/services/convert/pull_review.go @@ -36,10 +36,10 @@ func ToPullReview(ctx context.Context, r *issues_model.Review, doer *user_model. Stale: r.Stale, Official: r.Official, Dismissed: r.Dismissed, - CodeCommentsCount: r.GetCodeCommentsCount(), + CodeCommentsCount: r.GetCodeCommentsCount(ctx), Submitted: r.CreatedUnix.AsTime(), Updated: r.UpdatedUnix.AsTime(), - HTMLURL: r.HTMLURL(), + HTMLURL: r.HTMLURL(ctx), HTMLPullURL: r.Issue.HTMLURL(), } @@ -102,7 +102,7 @@ func ToPullReviewCommentList(ctx context.Context, review *issues_model.Review, d CommitID: comment.CommitSHA, OrigCommitID: comment.OldRef, DiffHunk: patch2diff(comment.Patch), - HTMLURL: comment.HTMLURL(), + HTMLURL: comment.HTMLURL(ctx), HTMLPullURL: review.Issue.HTMLURL(), } diff --git a/services/cron/tasks_extended.go b/services/cron/tasks_extended.go index 5b483b000e..b9fd1dfcff 100644 --- a/services/cron/tasks_extended.go +++ b/services/cron/tasks_extended.go @@ -135,7 +135,7 @@ func registerDeleteOldActions() { OlderThan: 365 * 24 * time.Hour, }, func(ctx context.Context, _ *user_model.User, config Config) error { olderThanConfig := config.(*OlderThanConfig) - return activities_model.DeleteOldActions(olderThanConfig.OlderThan) + return activities_model.DeleteOldActions(ctx, olderThanConfig.OlderThan) }) } diff --git a/services/externalaccount/user.go b/services/externalaccount/user.go index 51a0f9a4ef..a80ba6fee7 100644 --- a/services/externalaccount/user.go +++ b/services/externalaccount/user.go @@ -82,11 +82,11 @@ func UpdateExternalUser(user *user_model.User, gothUser goth.User) error { // UpdateMigrationsByType updates all migrated repositories' posterid from gitServiceType to replace originalAuthorID to posterID func UpdateMigrationsByType(ctx context.Context, tp structs.GitServiceType, externalUserID string, userID int64) error { - if err := issues_model.UpdateIssuesMigrationsByType(tp, externalUserID, userID); err != nil { + if err := issues_model.UpdateIssuesMigrationsByType(ctx, tp, externalUserID, userID); err != nil { return err } - if err := issues_model.UpdateCommentsMigrationsByType(tp, externalUserID, userID); err != nil { + if err := issues_model.UpdateCommentsMigrationsByType(ctx, tp, externalUserID, userID); err != nil { return err } @@ -94,8 +94,8 @@ func UpdateMigrationsByType(ctx context.Context, tp structs.GitServiceType, exte return err } - if err := issues_model.UpdateReactionsMigrationsByType(tp, externalUserID, userID); err != nil { + if err := issues_model.UpdateReactionsMigrationsByType(ctx, tp, externalUserID, userID); err != nil { return err } - return issues_model.UpdateReviewsMigrationsByType(tp, externalUserID, userID) + return issues_model.UpdateReviewsMigrationsByType(ctx, tp, externalUserID, userID) } diff --git a/services/feed/action.go b/services/feed/action.go index 6bf1158cc9..83daaa1438 100644 --- a/services/feed/action.go +++ b/services/feed/action.go @@ -265,7 +265,7 @@ func (a *actionNotifier) PullRequestReview(ctx context.Context, pr *issues_model actions = append(actions, action) } - if err := activities_model.NotifyWatchersActions(actions); err != nil { + if err := activities_model.NotifyWatchersActions(ctx, actions); err != nil { log.Error("notify watchers '%d/%d': %v", review.Reviewer.ID, review.Issue.RepoID, err) } } diff --git a/services/issue/comments.go b/services/issue/comments.go index 4a8574edd5..8d8c575c14 100644 --- a/services/issue/comments.go +++ b/services/issue/comments.go @@ -84,7 +84,7 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, doer *user_mode } } - if err := issues_model.UpdateComment(c, doer); err != nil { + if err := issues_model.UpdateComment(ctx, c, doer); err != nil { return err } diff --git a/services/issue/content.go b/services/issue/content.go index 41f1bfefe8..6e56714ddf 100644 --- a/services/issue/content.go +++ b/services/issue/content.go @@ -15,7 +15,7 @@ import ( func ChangeContent(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, content string) (err error) { oldContent := issue.Content - if err := issues_model.ChangeIssueContent(issue, doer, content); err != nil { + if err := issues_model.ChangeIssueContent(ctx, issue, doer, content); err != nil { return err } diff --git a/services/issue/issue.go b/services/issue/issue.go index 828599be6b..fb95fcada3 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -22,7 +22,7 @@ import ( // NewIssue creates new issue with labels for repository. func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *issues_model.Issue, labelIDs []int64, uuids []string, assigneeIDs []int64) error { - if err := issues_model.NewIssue(repo, issue, labelIDs, uuids); err != nil { + if err := issues_model.NewIssue(ctx, repo, issue, labelIDs, uuids); err != nil { return err } @@ -73,7 +73,7 @@ func ChangeIssueRef(ctx context.Context, issue *issues_model.Issue, doer *user_m oldRef := issue.Ref issue.Ref = ref - if err := issues_model.ChangeIssueRef(issue, doer, oldRef); err != nil { + if err := issues_model.ChangeIssueRef(ctx, issue, doer, oldRef); err != nil { return err } diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index 1d9ac2964e..9e4adc55be 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -510,7 +510,7 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error { if len(cms) == 0 { return nil } - return issues_model.InsertIssueComments(cms) + return issues_model.InsertIssueComments(g.ctx, cms) } // CreatePullRequests creates pull requests @@ -917,7 +917,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error { } } - return issues_model.InsertReviews(cms) + return issues_model.InsertReviews(g.ctx, cms) } // Rollback when migrating failed, this will rollback all the changes. diff --git a/services/mirror/mirror.go b/services/mirror/mirror.go index 0fc871b214..f496e05a3f 100644 --- a/services/mirror/mirror.go +++ b/services/mirror/mirror.go @@ -46,7 +46,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error { var referenceID int64 if m, ok := bean.(*repo_model.Mirror); ok { - if m.GetRepository() == nil { + if m.GetRepository(ctx) == nil { log.Error("Disconnected mirror found: %d", m.ID) return nil } @@ -90,7 +90,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error { pullMirrorsRequested := 0 if pullLimit != 0 { - if err := repo_model.MirrorsIterate(pullLimit, func(idx int, bean any) error { + if err := repo_model.MirrorsIterate(ctx, pullLimit, func(idx int, bean any) error { if err := handler(idx, bean); err != nil { return err } diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index 75b367c437..38b6986c4a 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -31,7 +31,7 @@ const gitShortEmptySha = "0000000" // UpdateAddress writes new address to Git repository and database func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error { remoteName := m.GetRemoteName() - repoPath := m.GetRepository().RepoPath() + repoPath := m.GetRepository(ctx).RepoPath() // Remove old remote _, _, err := git.NewCommand(ctx, "remote", "rm").AddDynamicArguments(remoteName).RunStdString(&git.RunOpts{Dir: repoPath}) if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") { @@ -428,7 +428,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { log.Error("SyncMirrors [repo_id: %v]: unable to GetMirrorByRepoID: %v", repoID, err) return false } - _ = m.GetRepository() // force load repository of mirror + _ = m.GetRepository(ctx) // force load repository of mirror ctx, _, finished := process.GetManager().AddContext(ctx, fmt.Sprintf("Syncing Mirror %s/%s", m.Repo.OwnerName, m.Repo.Name)) defer finished() diff --git a/services/pull/pull.go b/services/pull/pull.go index 8e57aebe3d..5e76fac815 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -336,7 +336,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, } if changed { // Mark old reviews as stale if diff to mergebase has changed - if err := issues_model.MarkReviewsAsStale(pr.IssueID); err != nil { + if err := issues_model.MarkReviewsAsStale(ctx, pr.IssueID); err != nil { log.Error("MarkReviewsAsStale: %v", err) } @@ -351,7 +351,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, } } } - if err := issues_model.MarkReviewsAsNotStale(pr.IssueID, newCommitID); err != nil { + if err := issues_model.MarkReviewsAsNotStale(ctx, pr.IssueID, newCommitID); err != nil { log.Error("MarkReviewsAsNotStale: %v", err) } divergence, err := GetDiverging(ctx, pr) diff --git a/services/pull/review.go b/services/pull/review.go index c82d1341b6..64eea22eec 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -84,7 +84,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git. if !pendingReview && replyReviewID != 0 { // It's not part of a review; maybe a reply to a review comment or a single comment. // Check if there are reviews for that line already; if there are, this is a reply - if existsReview, err = issues_model.ReviewExists(issue, treePath, line); err != nil { + if existsReview, err = issues_model.ReviewExists(ctx, issue, treePath, line); err != nil { return nil, err } } @@ -288,7 +288,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos } } - review, comm, err := issues_model.SubmitReview(doer, issue, reviewType, content, commitID, stale, attachmentUUIDs) + review, comm, err := issues_model.SubmitReview(ctx, doer, issue, reviewType, content, commitID, stale, attachmentUUIDs) if err != nil { return nil, nil, err } diff --git a/services/uinotification/notify.go b/services/uinotification/notify.go index 9cf4fe73d7..9230d1ee6c 100644 --- a/services/uinotification/notify.go +++ b/services/uinotification/notify.go @@ -52,7 +52,7 @@ func NewNotifier() notify_service.Notifier { func handler(items ...issueNotificationOpts) []issueNotificationOpts { for _, opts := range items { - if err := activities_model.CreateOrUpdateIssueNotifications(opts.IssueID, opts.CommentID, opts.NotificationAuthorID, opts.ReceiverID); err != nil { + if err := activities_model.CreateOrUpdateIssueNotifications(db.DefaultContext, opts.IssueID, opts.CommentID, opts.NotificationAuthorID, opts.ReceiverID); err != nil { log.Error("Was unable to create issue notification: %v", err) } } |