From a4291fd55378ee73dbda70a19b93764e8c547377 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Thu, 19 Dec 2024 17:14:04 +0800 Subject: [PATCH] Add more load functions to make sure the reference object loaded (#32901) (#32912) Backport #32901 by @lunny Fix #32897 Co-authored-by: Lunny Xiao --- services/convert/pull.go | 5 +++++ services/webhook/notifier.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/services/convert/pull.go b/services/convert/pull.go index ddaaa300a4..a1ab7eeb8e 100644 --- a/services/convert/pull.go +++ b/services/convert/pull.go @@ -31,6 +31,11 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u err error ) + if err = pr.LoadIssue(ctx); err != nil { + log.Error("pr.LoadIssue[%d]: %v", pr.ID, err) + return nil + } + if err = pr.Issue.LoadRepo(ctx); err != nil { log.Error("pr.Issue.LoadRepo[%d]: %v", pr.ID, err) return nil diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index cc263947e9..a3d5cb34b1 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -410,6 +410,10 @@ func (m *webhookNotifier) CreateIssueComment(ctx context.Context, doer *user_mod var pullRequest *api.PullRequest if issue.IsPull { eventType = webhook_module.HookEventPullRequestComment + if err := issue.LoadPullRequest(ctx); err != nil { + log.Error("LoadPullRequest: %v", err) + return + } pullRequest = convert.ToAPIPullRequest(ctx, issue.PullRequest, doer) } else { eventType = webhook_module.HookEventIssueComment