summaryrefslogtreecommitdiffstats
path: root/models/issues
diff options
context:
space:
mode:
authorJason Song <i@wolfogre.com>2023-02-05 19:57:38 +0800
committerGitHub <noreply@github.com>2023-02-05 19:57:38 +0800
commitc18a62279a54f1ba0dc0293dddbe197f527fbf00 (patch)
treeab934e0e90acc1fe042c8a8f40aab69f7635590e /models/issues
parentdf789d962b3d568a77773dd53f98eb37c8bd1f6b (diff)
downloadgitea-c18a62279a54f1ba0dc0293dddbe197f527fbf00.tar.gz
gitea-c18a62279a54f1ba0dc0293dddbe197f527fbf00.zip
Fix time to NotifyPullRequestSynchronized (#22650)
Should call `PushToBaseRepo` before `notification.NotifyPullRequestSynchronized`. Or the notifier will get an old commit when reading branch `pull/xxx/head`. Found by ~#21937~ #22679. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models/issues')
-rw-r--r--models/issues/pull_list.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/models/issues/pull_list.go b/models/issues/pull_list.go
index 007c2fd903..68f62ffc43 100644
--- a/models/issues/pull_list.go
+++ b/models/issues/pull_list.go
@@ -13,6 +13,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/util"
"xorm.io/xorm"
)
@@ -175,7 +176,17 @@ func (prs PullRequestList) loadAttributes(ctx context.Context) error {
}
for _, pr := range prs {
pr.Issue = set[pr.IssueID]
- pr.Issue.PullRequest = pr // panic here means issueIDs and prs are not in sync
+ /*
+ Old code:
+ pr.Issue.PullRequest = pr // panic here means issueIDs and prs are not in sync
+
+ It's worth panic because it's almost impossible to happen under normal use.
+ But in integration testing, an asynchronous task could read a database that has been reset.
+ So returning an error would make more sense, let the caller has a choice to ignore it.
+ */
+ if pr.Issue == nil {
+ return fmt.Errorf("issues and prs may be not in sync: cannot find issue %v for pr %v: %w", pr.IssueID, pr.ID, util.ErrNotExist)
+ }
}
return nil
}