fix: add missing ctx

This commit is contained in:
Jason Song 2022-12-05 14:46:34 +08:00
parent bd1af5b7f8
commit fdd3444c52
No known key found for this signature in database
GPG Key ID: 8402EEEE4511A8B5
5 changed files with 26 additions and 26 deletions

View File

@ -60,7 +60,7 @@ func (run *BotRun) LoadAttributes(ctx context.Context) error {
} }
if run.Repo == nil { if run.Repo == nil {
repo, err := repo_model.GetRepositoryByIDCtx(ctx, run.RepoID) repo, err := repo_model.GetRepositoryByID(ctx, run.RepoID)
if err != nil { if err != nil {
return err return err
} }
@ -151,7 +151,7 @@ func InsertRun(run *BotRun, jobs []*jobparser.SingleWorkflow) error {
} }
if run.Repo == nil { if run.Repo == nil {
repo, err := repo_model.GetRepositoryByIDCtx(ctx, run.RepoID) repo, err := repo_model.GetRepositoryByID(ctx, run.RepoID)
if err != nil { if err != nil {
return err return err
} }
@ -254,7 +254,7 @@ func UpdateRun(ctx context.Context, run *BotRun, cols ...string) error {
} }
} }
if run.Repo == nil { if run.Repo == nil {
repo, err := repo_model.GetRepositoryByIDCtx(ctx, run.RepoID) repo, err := repo_model.GetRepositoryByID(ctx, run.RepoID)
if err != nil { if err != nil {
return err return err
} }

View File

@ -988,7 +988,7 @@ func GetPossbileUserByID(ctx context.Context, id int64) (*User, error) {
case 0: case 0:
return nil, ErrUserNotExist{} return nil, ErrUserNotExist{}
default: default:
return GetUserByIDCtx(ctx, id) return GetUserByID(ctx, id)
} }
} }

View File

@ -51,7 +51,7 @@ func (n *botsNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.I
Action: api.HookIssueOpened, Action: api.HookIssueOpened,
Index: issue.Index, Index: issue.Index,
Issue: convert.ToAPIIssue(ctx, issue), Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(issue.Repo, mode), Repository: convert.ToRepo(ctx, issue.Repo, mode),
Sender: convert.ToUser(issue.Poster, nil), Sender: convert.ToUser(issue.Poster, nil),
}).Notify(withMethod(ctx, "NotifyNewIssue")) }).Notify(withMethod(ctx, "NotifyNewIssue"))
} }
@ -69,7 +69,7 @@ func (n *botsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_m
apiPullRequest := &api.PullRequestPayload{ apiPullRequest := &api.PullRequestPayload{
Index: issue.Index, Index: issue.Index,
PullRequest: convert.ToAPIPullRequest(db.DefaultContext, issue.PullRequest, nil), 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), Sender: convert.ToUser(doer, nil),
} }
if isClosed { if isClosed {
@ -86,7 +86,7 @@ func (n *botsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_m
apiIssue := &api.IssuePayload{ apiIssue := &api.IssuePayload{
Index: issue.Index, Index: issue.Index,
Issue: convert.ToAPIIssue(ctx, issue), Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(issue.Repo, mode), Repository: convert.ToRepo(ctx, issue.Repo, mode),
Sender: convert.ToUser(doer, nil), Sender: convert.ToUser(doer, nil),
} }
if isClosed { if isClosed {
@ -132,7 +132,7 @@ func (n *botsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_m
Action: api.HookIssueLabelUpdated, Action: api.HookIssueLabelUpdated,
Index: issue.Index, Index: issue.Index,
PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil), 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), Sender: convert.ToUser(doer, nil),
}). }).
Notify(ctx) Notify(ctx)
@ -144,7 +144,7 @@ func (n *botsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_m
Action: api.HookIssueLabelUpdated, Action: api.HookIssueLabelUpdated,
Index: issue.Index, Index: issue.Index,
Issue: convert.ToAPIIssue(ctx, issue), Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(issue.Repo, mode), Repository: convert.ToRepo(ctx, issue.Repo, mode),
Sender: convert.ToUser(doer, nil), Sender: convert.ToUser(doer, nil),
}). }).
Notify(ctx) Notify(ctx)
@ -165,7 +165,7 @@ func (n *botsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_
Action: api.HookIssueCommentCreated, Action: api.HookIssueCommentCreated,
Issue: convert.ToAPIIssue(ctx, issue), Issue: convert.ToAPIIssue(ctx, issue),
Comment: convert.ToComment(comment), Comment: convert.ToComment(comment),
Repository: convert.ToRepo(repo, mode), Repository: convert.ToRepo(ctx, repo, mode),
Sender: convert.ToUser(doer, nil), Sender: convert.ToUser(doer, nil),
IsPull: true, IsPull: true,
}). }).
@ -178,7 +178,7 @@ func (n *botsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_
Action: api.HookIssueCommentCreated, Action: api.HookIssueCommentCreated,
Issue: convert.ToAPIIssue(ctx, issue), Issue: convert.ToAPIIssue(ctx, issue),
Comment: convert.ToComment(comment), Comment: convert.ToComment(comment),
Repository: convert.ToRepo(repo, mode), Repository: convert.ToRepo(ctx, repo, mode),
Sender: convert.ToUser(doer, nil), Sender: convert.ToUser(doer, nil),
IsPull: false, IsPull: false,
}). }).
@ -208,7 +208,7 @@ func (n *botsNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues_mo
Action: api.HookIssueOpened, Action: api.HookIssueOpened,
Index: pull.Issue.Index, Index: pull.Issue.Index,
PullRequest: convert.ToAPIPullRequest(ctx, pull, nil), 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), Sender: convert.ToUser(pull.Issue.Poster, nil),
}). }).
WithPullRequest(pull). WithPullRequest(pull).
@ -220,7 +220,7 @@ func (n *botsNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user
newNotifyInput(repo, doer, webhook.HookEventRepository).WithPayload(&api.RepositoryPayload{ newNotifyInput(repo, doer, webhook.HookEventRepository).WithPayload(&api.RepositoryPayload{
Action: api.HookRepoCreated, Action: api.HookRepoCreated,
Repository: convert.ToRepo(repo, perm.AccessModeOwner), Repository: convert.ToRepo(ctx, repo, perm.AccessModeOwner),
Organization: convert.ToUser(u, nil), Organization: convert.ToUser(u, nil),
Sender: convert.ToUser(doer, nil), Sender: convert.ToUser(doer, nil),
}).Notify(ctx) }).Notify(ctx)
@ -234,8 +234,8 @@ func (n *botsNotifier) NotifyForkRepository(ctx context.Context, doer *user_mode
// forked webhook // forked webhook
newNotifyInput(oldRepo, doer, webhook.HookEventFork).WithPayload(&api.ForkPayload{ newNotifyInput(oldRepo, doer, webhook.HookEventFork).WithPayload(&api.ForkPayload{
Forkee: convert.ToRepo(oldRepo, oldMode), Forkee: convert.ToRepo(ctx, oldRepo, oldMode),
Repo: convert.ToRepo(repo, mode), Repo: convert.ToRepo(ctx, repo, mode),
Sender: convert.ToUser(doer, nil), Sender: convert.ToUser(doer, nil),
}).Notify(ctx) }).Notify(ctx)
@ -247,7 +247,7 @@ func (n *botsNotifier) NotifyForkRepository(ctx context.Context, doer *user_mode
WithRef(oldRepo.DefaultBranch). WithRef(oldRepo.DefaultBranch).
WithPayload(&api.RepositoryPayload{ WithPayload(&api.RepositoryPayload{
Action: api.HookRepoCreated, Action: api.HookRepoCreated,
Repository: convert.ToRepo(repo, perm.AccessModeOwner), Repository: convert.ToRepo(ctx, repo, perm.AccessModeOwner),
Organization: convert.ToUser(u, nil), Organization: convert.ToUser(u, nil),
Sender: convert.ToUser(doer, nil), Sender: convert.ToUser(doer, nil),
}).Notify(ctx) }).Notify(ctx)
@ -289,7 +289,7 @@ func (n *botsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_m
Action: api.HookIssueReviewed, Action: api.HookIssueReviewed,
Index: review.Issue.Index, Index: review.Issue.Index,
PullRequest: convert.ToAPIPullRequest(db.DefaultContext, pr, nil), 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), Sender: convert.ToUser(review.Reviewer, nil),
Review: &api.ReviewPayload{ Review: &api.ReviewPayload{
Type: string(reviewHookType), Type: string(reviewHookType),
@ -327,7 +327,7 @@ func (*botsNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_mode
apiPullRequest := &api.PullRequestPayload{ apiPullRequest := &api.PullRequestPayload{
Index: pr.Issue.Index, Index: pr.Issue.Index,
PullRequest: convert.ToAPIPullRequest(db.DefaultContext, pr, nil), 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), Sender: convert.ToUser(doer, nil),
Action: api.HookIssueClosed, Action: api.HookIssueClosed,
} }
@ -358,7 +358,7 @@ func (n *botsNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model
CompareURL: setting.AppURL + commits.CompareURL, CompareURL: setting.AppURL + commits.CompareURL,
Commits: apiCommits, Commits: apiCommits,
HeadCommit: apiHeadCommit, HeadCommit: apiHeadCommit,
Repo: convert.ToRepo(repo, perm.AccessModeOwner), Repo: convert.ToRepo(ctx, repo, perm.AccessModeOwner),
Pusher: apiPusher, Pusher: apiPusher,
Sender: apiPusher, Sender: apiPusher,
}). }).
@ -369,7 +369,7 @@ func (n *botsNotifier) NotifyCreateRef(ctx context.Context, pusher *user_model.U
ctx = withMethod(ctx, "NotifyCreateRef") ctx = withMethod(ctx, "NotifyCreateRef")
apiPusher := convert.ToUser(pusher, nil) apiPusher := convert.ToUser(pusher, nil)
apiRepo := convert.ToRepo(repo, perm.AccessModeNone) apiRepo := convert.ToRepo(ctx, repo, perm.AccessModeNone)
refName := git.RefEndName(refFullName) refName := git.RefEndName(refFullName)
newNotifyInput(repo, pusher, webhook.HookEventCreate). newNotifyInput(repo, pusher, webhook.HookEventCreate).
@ -388,7 +388,7 @@ func (n *botsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.U
ctx = withMethod(ctx, "NotifyDeleteRef") ctx = withMethod(ctx, "NotifyDeleteRef")
apiPusher := convert.ToUser(pusher, nil) apiPusher := convert.ToUser(pusher, nil)
apiRepo := convert.ToRepo(repo, perm.AccessModeNone) apiRepo := convert.ToRepo(ctx, repo, perm.AccessModeNone)
refName := git.RefEndName(refFullName) refName := git.RefEndName(refFullName)
newNotifyInput(repo, pusher, webhook.HookEventDelete). newNotifyInput(repo, pusher, webhook.HookEventDelete).
@ -423,7 +423,7 @@ func (n *botsNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_m
Commits: apiCommits, Commits: apiCommits,
TotalCommits: commits.Len, TotalCommits: commits.Len,
HeadCommit: apiHeadCommit, HeadCommit: apiHeadCommit,
Repo: convert.ToRepo(repo, perm.AccessModeOwner), Repo: convert.ToRepo(ctx, repo, perm.AccessModeOwner),
Pusher: apiPusher, Pusher: apiPusher,
Sender: apiPusher, Sender: apiPusher,
}). }).
@ -488,7 +488,7 @@ func (n *botsNotifier) NotifyPullRequestSynchronized(ctx context.Context, doer *
Action: api.HookIssueSynchronized, Action: api.HookIssueSynchronized,
Index: pr.Issue.Index, Index: pr.Issue.Index,
PullRequest: convert.ToAPIPullRequest(ctx, pr, nil), 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), Sender: convert.ToUser(doer, nil),
}). }).
WithPullRequest(pr). WithPullRequest(pr).
@ -519,7 +519,7 @@ func (n *botsNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Context,
}, },
}, },
PullRequest: convert.ToAPIPullRequest(ctx, pr, nil), 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), Sender: convert.ToUser(doer, nil),
}). }).
WithPullRequest(pr). WithPullRequest(pr).

View File

@ -189,7 +189,7 @@ func notifyRelease(ctx context.Context, doer *user_model.User, rel *repo_model.R
WithPayload(&api.ReleasePayload{ WithPayload(&api.ReleasePayload{
Action: action, Action: action,
Release: convert.ToRelease(rel), Release: convert.ToRelease(rel),
Repository: convert.ToRepo(rel.Repo, mode), Repository: convert.ToRepo(ctx, rel.Repo, mode),
Sender: convert.ToUser(doer, nil), Sender: convert.ToUser(doer, nil),
}). }).
Notify(ctx) Notify(ctx)

View File

@ -80,7 +80,7 @@ func CreateCommitStatus(ctx context.Context, job *bots_model.BotRunJob) error {
return fmt.Errorf("GetPushEventPayload: %w", err) 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 { if err != nil {
return fmt.Errorf("GetUserByID: %w", err) return fmt.Errorf("GetUserByID: %w", err)
} }