From fdd3444c52069bc5f68d79e57c6f29af76b352a5 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Mon, 5 Dec 2022 14:46:34 +0800 Subject: [PATCH] fix: add missing ctx --- models/bots/run.go | 6 ++--- models/user/user.go | 2 +- modules/notification/bots/bots.go | 40 ++++++++++++++--------------- modules/notification/bots/helper.go | 2 +- services/bots/bots.go | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/models/bots/run.go b/models/bots/run.go index e9e3686836..cfeccc4f09 100644 --- a/models/bots/run.go +++ b/models/bots/run.go @@ -60,7 +60,7 @@ func (run *BotRun) LoadAttributes(ctx context.Context) error { } if run.Repo == nil { - repo, err := repo_model.GetRepositoryByIDCtx(ctx, run.RepoID) + repo, err := repo_model.GetRepositoryByID(ctx, run.RepoID) if err != nil { return err } @@ -151,7 +151,7 @@ func InsertRun(run *BotRun, jobs []*jobparser.SingleWorkflow) error { } if run.Repo == nil { - repo, err := repo_model.GetRepositoryByIDCtx(ctx, run.RepoID) + repo, err := repo_model.GetRepositoryByID(ctx, run.RepoID) if err != nil { return err } @@ -254,7 +254,7 @@ func UpdateRun(ctx context.Context, run *BotRun, cols ...string) error { } } if run.Repo == nil { - repo, err := repo_model.GetRepositoryByIDCtx(ctx, run.RepoID) + repo, err := repo_model.GetRepositoryByID(ctx, run.RepoID) if err != nil { return err } diff --git a/models/user/user.go b/models/user/user.go index e35c3c856a..419eead83b 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -988,7 +988,7 @@ func GetPossbileUserByID(ctx context.Context, id int64) (*User, error) { case 0: return nil, ErrUserNotExist{} default: - return GetUserByIDCtx(ctx, id) + return GetUserByID(ctx, id) } } diff --git a/modules/notification/bots/bots.go b/modules/notification/bots/bots.go index c7b0aef1b4..697571e698 100644 --- a/modules/notification/bots/bots.go +++ b/modules/notification/bots/bots.go @@ -51,7 +51,7 @@ func (n *botsNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.I Action: api.HookIssueOpened, Index: issue.Index, Issue: convert.ToAPIIssue(ctx, issue), - Repository: convert.ToRepo(issue.Repo, mode), + Repository: convert.ToRepo(ctx, issue.Repo, mode), Sender: convert.ToUser(issue.Poster, nil), }).Notify(withMethod(ctx, "NotifyNewIssue")) } @@ -69,7 +69,7 @@ func (n *botsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_m apiPullRequest := &api.PullRequestPayload{ Index: issue.Index, PullRequest: convert.ToAPIPullRequest(db.DefaultContext, issue.PullRequest, nil), - Repository: convert.ToRepo(issue.Repo, mode), + Repository: convert.ToRepo(ctx, issue.Repo, mode), Sender: convert.ToUser(doer, nil), } if isClosed { @@ -86,7 +86,7 @@ func (n *botsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_m apiIssue := &api.IssuePayload{ Index: issue.Index, Issue: convert.ToAPIIssue(ctx, issue), - Repository: convert.ToRepo(issue.Repo, mode), + Repository: convert.ToRepo(ctx, issue.Repo, mode), Sender: convert.ToUser(doer, nil), } if isClosed { @@ -132,7 +132,7 @@ func (n *botsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_m Action: api.HookIssueLabelUpdated, Index: issue.Index, PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil), - Repository: convert.ToRepo(issue.Repo, perm.AccessModeNone), + Repository: convert.ToRepo(ctx, issue.Repo, perm.AccessModeNone), Sender: convert.ToUser(doer, nil), }). Notify(ctx) @@ -144,7 +144,7 @@ func (n *botsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_m Action: api.HookIssueLabelUpdated, Index: issue.Index, Issue: convert.ToAPIIssue(ctx, issue), - Repository: convert.ToRepo(issue.Repo, mode), + Repository: convert.ToRepo(ctx, issue.Repo, mode), Sender: convert.ToUser(doer, nil), }). Notify(ctx) @@ -165,7 +165,7 @@ func (n *botsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_ Action: api.HookIssueCommentCreated, Issue: convert.ToAPIIssue(ctx, issue), Comment: convert.ToComment(comment), - Repository: convert.ToRepo(repo, mode), + Repository: convert.ToRepo(ctx, repo, mode), Sender: convert.ToUser(doer, nil), IsPull: true, }). @@ -178,7 +178,7 @@ func (n *botsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_ Action: api.HookIssueCommentCreated, Issue: convert.ToAPIIssue(ctx, issue), Comment: convert.ToComment(comment), - Repository: convert.ToRepo(repo, mode), + Repository: convert.ToRepo(ctx, repo, mode), Sender: convert.ToUser(doer, nil), IsPull: false, }). @@ -208,7 +208,7 @@ func (n *botsNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues_mo Action: api.HookIssueOpened, Index: pull.Issue.Index, PullRequest: convert.ToAPIPullRequest(ctx, pull, nil), - Repository: convert.ToRepo(pull.Issue.Repo, mode), + Repository: convert.ToRepo(ctx, pull.Issue.Repo, mode), Sender: convert.ToUser(pull.Issue.Poster, nil), }). WithPullRequest(pull). @@ -220,7 +220,7 @@ func (n *botsNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user newNotifyInput(repo, doer, webhook.HookEventRepository).WithPayload(&api.RepositoryPayload{ Action: api.HookRepoCreated, - Repository: convert.ToRepo(repo, perm.AccessModeOwner), + Repository: convert.ToRepo(ctx, repo, perm.AccessModeOwner), Organization: convert.ToUser(u, nil), Sender: convert.ToUser(doer, nil), }).Notify(ctx) @@ -234,8 +234,8 @@ func (n *botsNotifier) NotifyForkRepository(ctx context.Context, doer *user_mode // forked webhook newNotifyInput(oldRepo, doer, webhook.HookEventFork).WithPayload(&api.ForkPayload{ - Forkee: convert.ToRepo(oldRepo, oldMode), - Repo: convert.ToRepo(repo, mode), + Forkee: convert.ToRepo(ctx, oldRepo, oldMode), + Repo: convert.ToRepo(ctx, repo, mode), Sender: convert.ToUser(doer, nil), }).Notify(ctx) @@ -247,7 +247,7 @@ func (n *botsNotifier) NotifyForkRepository(ctx context.Context, doer *user_mode WithRef(oldRepo.DefaultBranch). WithPayload(&api.RepositoryPayload{ Action: api.HookRepoCreated, - Repository: convert.ToRepo(repo, perm.AccessModeOwner), + Repository: convert.ToRepo(ctx, repo, perm.AccessModeOwner), Organization: convert.ToUser(u, nil), Sender: convert.ToUser(doer, nil), }).Notify(ctx) @@ -289,7 +289,7 @@ func (n *botsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_m Action: api.HookIssueReviewed, Index: review.Issue.Index, PullRequest: convert.ToAPIPullRequest(db.DefaultContext, pr, nil), - Repository: convert.ToRepo(review.Issue.Repo, mode), + Repository: convert.ToRepo(ctx, review.Issue.Repo, mode), Sender: convert.ToUser(review.Reviewer, nil), Review: &api.ReviewPayload{ Type: string(reviewHookType), @@ -327,7 +327,7 @@ func (*botsNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_mode apiPullRequest := &api.PullRequestPayload{ Index: pr.Issue.Index, PullRequest: convert.ToAPIPullRequest(db.DefaultContext, pr, nil), - Repository: convert.ToRepo(pr.Issue.Repo, mode), + Repository: convert.ToRepo(ctx, pr.Issue.Repo, mode), Sender: convert.ToUser(doer, nil), Action: api.HookIssueClosed, } @@ -358,7 +358,7 @@ func (n *botsNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model CompareURL: setting.AppURL + commits.CompareURL, Commits: apiCommits, HeadCommit: apiHeadCommit, - Repo: convert.ToRepo(repo, perm.AccessModeOwner), + Repo: convert.ToRepo(ctx, repo, perm.AccessModeOwner), Pusher: apiPusher, Sender: apiPusher, }). @@ -369,7 +369,7 @@ func (n *botsNotifier) NotifyCreateRef(ctx context.Context, pusher *user_model.U ctx = withMethod(ctx, "NotifyCreateRef") apiPusher := convert.ToUser(pusher, nil) - apiRepo := convert.ToRepo(repo, perm.AccessModeNone) + apiRepo := convert.ToRepo(ctx, repo, perm.AccessModeNone) refName := git.RefEndName(refFullName) newNotifyInput(repo, pusher, webhook.HookEventCreate). @@ -388,7 +388,7 @@ func (n *botsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.U ctx = withMethod(ctx, "NotifyDeleteRef") apiPusher := convert.ToUser(pusher, nil) - apiRepo := convert.ToRepo(repo, perm.AccessModeNone) + apiRepo := convert.ToRepo(ctx, repo, perm.AccessModeNone) refName := git.RefEndName(refFullName) newNotifyInput(repo, pusher, webhook.HookEventDelete). @@ -423,7 +423,7 @@ func (n *botsNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_m Commits: apiCommits, TotalCommits: commits.Len, HeadCommit: apiHeadCommit, - Repo: convert.ToRepo(repo, perm.AccessModeOwner), + Repo: convert.ToRepo(ctx, repo, perm.AccessModeOwner), Pusher: apiPusher, Sender: apiPusher, }). @@ -488,7 +488,7 @@ func (n *botsNotifier) NotifyPullRequestSynchronized(ctx context.Context, doer * Action: api.HookIssueSynchronized, Index: pr.Issue.Index, PullRequest: convert.ToAPIPullRequest(ctx, pr, nil), - Repository: convert.ToRepo(pr.Issue.Repo, perm.AccessModeNone), + Repository: convert.ToRepo(ctx, pr.Issue.Repo, perm.AccessModeNone), Sender: convert.ToUser(doer, nil), }). WithPullRequest(pr). @@ -519,7 +519,7 @@ func (n *botsNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Context, }, }, PullRequest: convert.ToAPIPullRequest(ctx, pr, nil), - Repository: convert.ToRepo(pr.Issue.Repo, mode), + Repository: convert.ToRepo(ctx, pr.Issue.Repo, mode), Sender: convert.ToUser(doer, nil), }). WithPullRequest(pr). diff --git a/modules/notification/bots/helper.go b/modules/notification/bots/helper.go index e7e4015d14..0b1712c9bd 100644 --- a/modules/notification/bots/helper.go +++ b/modules/notification/bots/helper.go @@ -189,7 +189,7 @@ func notifyRelease(ctx context.Context, doer *user_model.User, rel *repo_model.R WithPayload(&api.ReleasePayload{ Action: action, Release: convert.ToRelease(rel), - Repository: convert.ToRepo(rel.Repo, mode), + Repository: convert.ToRepo(ctx, rel.Repo, mode), Sender: convert.ToUser(doer, nil), }). Notify(ctx) diff --git a/services/bots/bots.go b/services/bots/bots.go index 0f0fff06dc..c3f5317319 100644 --- a/services/bots/bots.go +++ b/services/bots/bots.go @@ -80,7 +80,7 @@ func CreateCommitStatus(ctx context.Context, job *bots_model.BotRunJob) error { return fmt.Errorf("GetPushEventPayload: %w", err) } - creator, err := user_model.GetUserByID(payload.Pusher.ID) + creator, err := user_model.GetUserByID(ctx, payload.Pusher.ID) if err != nil { return fmt.Errorf("GetUserByID: %w", err) }