Fix intermittent panic in notify issue change content (#23019)
Ensure that issue pullrequests are loaded before trying to set the self-reference. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: delvh <leon@kske.dev> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
97aacc3ea1
commit
35d2fa744a
2 changed files with 12 additions and 9 deletions
|
@ -251,13 +251,15 @@ func (issue *Issue) LoadPoster(ctx context.Context) (err error) {
|
||||||
|
|
||||||
// LoadPullRequest loads pull request info
|
// LoadPullRequest loads pull request info
|
||||||
func (issue *Issue) LoadPullRequest(ctx context.Context) (err error) {
|
func (issue *Issue) LoadPullRequest(ctx context.Context) (err error) {
|
||||||
if issue.IsPull && issue.PullRequest == nil {
|
if issue.IsPull {
|
||||||
issue.PullRequest, err = GetPullRequestByIssueID(ctx, issue.ID)
|
if issue.PullRequest == nil {
|
||||||
if err != nil {
|
issue.PullRequest, err = GetPullRequestByIssueID(ctx, issue.ID)
|
||||||
if IsErrPullRequestNotExist(err) {
|
if err != nil {
|
||||||
return err
|
if IsErrPullRequestNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return fmt.Errorf("getPullRequestByIssueID [%d]: %w", issue.ID, err)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("getPullRequestByIssueID [%d]: %w", issue.ID, err)
|
|
||||||
}
|
}
|
||||||
issue.PullRequest.Issue = issue
|
issue.PullRequest.Issue = issue
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,6 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *u
|
||||||
log.Error("LoadPullRequest failed: %v", err)
|
log.Error("LoadPullRequest failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
issue.PullRequest.Issue = issue
|
|
||||||
apiPullRequest := &api.PullRequestPayload{
|
apiPullRequest := &api.PullRequestPayload{
|
||||||
Index: issue.Index,
|
Index: issue.Index,
|
||||||
PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil),
|
PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil),
|
||||||
|
@ -196,7 +195,6 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user
|
||||||
log.Error("LoadPullRequest failed: %v", err)
|
log.Error("LoadPullRequest failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
issue.PullRequest.Issue = issue
|
|
||||||
err = PrepareWebhooks(ctx, EventSource{Repository: issue.Repo}, webhook_module.HookEventPullRequest, &api.PullRequestPayload{
|
err = PrepareWebhooks(ctx, EventSource{Repository: issue.Repo}, webhook_module.HookEventPullRequest, &api.PullRequestPayload{
|
||||||
Action: api.HookIssueEdited,
|
Action: api.HookIssueEdited,
|
||||||
Index: issue.Index,
|
Index: issue.Index,
|
||||||
|
@ -328,7 +326,10 @@ func (m *webhookNotifier) NotifyIssueChangeContent(ctx context.Context, doer *us
|
||||||
mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
|
mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
|
||||||
var err error
|
var err error
|
||||||
if issue.IsPull {
|
if issue.IsPull {
|
||||||
issue.PullRequest.Issue = issue
|
if err := issue.LoadPullRequest(ctx); err != nil {
|
||||||
|
log.Error("LoadPullRequest: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
err = PrepareWebhooks(ctx, EventSource{Repository: issue.Repo}, webhook_module.HookEventPullRequest, &api.PullRequestPayload{
|
err = PrepareWebhooks(ctx, EventSource{Repository: issue.Repo}, webhook_module.HookEventPullRequest, &api.PullRequestPayload{
|
||||||
Action: api.HookIssueEdited,
|
Action: api.HookIssueEdited,
|
||||||
Index: issue.Index,
|
Index: issue.Index,
|
||||||
|
|
Loading…
Reference in a new issue