Skip to content

Commit 51508b4

Browse files
committed
Remove unnecessary AddTestPullRequestTask invoking and adjust adding push comments before checking
1 parent 22b92e3 commit 51508b4

File tree

6 files changed

+18
-27
lines changed

6 files changed

+18
-27
lines changed

services/issue/comments.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ func LoadCommentPushCommits(ctx context.Context, c *issues_model.Comment) (err e
164164

165165
c.IsForcePush = data.IsForcePush
166166

167+
if err := c.LoadIssue(ctx); err != nil {
168+
return err
169+
}
170+
if err := c.Issue.LoadRepo(ctx); err != nil {
171+
return err
172+
}
173+
167174
if c.IsForcePush {
168175
if len(data.CommitIDs) != 2 {
169176
return nil

services/pull/merge.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,8 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
247247
return fmt.Errorf("lock.Lock: %w", err)
248248
}
249249
defer releaser()
250-
defer func() {
251-
go AddTestPullRequestTask(TestPullRequestOptions{
252-
RepoID: pr.BaseRepo.ID,
253-
Doer: doer,
254-
Branch: pr.BaseBranch,
255-
IsSync: false,
256-
IsForcePush: false,
257-
OldCommitID: "",
258-
NewCommitID: "",
259-
})
260-
}()
261250

251+
// since test pull request task will be called after push, so we don't need to check again here
262252
_, err = doMergeAndPush(ctx, pr, doer, mergeStyle, expectedHeadCommitID, message, repo_module.PushTriggerPRMergeToBase)
263253
releaser()
264254
if err != nil {

services/pull/pull.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ func AddTestPullRequestTask(opts TestPullRequestOptions) {
376376
graceful.GetManager().RunWithShutdownContext(func(ctx context.Context) {
377377
// There is no sensible way to shut this down ":-("
378378
// If you don't let it run all the way then you will lose data
379-
// TODO: graceful: AddTestPullRequestTask needs to become a queue!
380379

381380
repo, err := repo_model.GetRepositoryByID(ctx, opts.RepoID)
382381
if err != nil {
@@ -402,11 +401,15 @@ func AddTestPullRequestTask(opts TestPullRequestOptions) {
402401
continue
403402
}
404403

405-
StartPullRequestCheckImmediately(ctx, pr)
404+
// create push comment first then check pull request status so the test
405+
// will get a stable result
406406
comment, err := CreatePushPullComment(ctx, opts.Doer, pr, opts.OldCommitID, opts.NewCommitID, opts.IsForcePush)
407407
if err == nil && comment != nil {
408408
notify_service.PullRequestPushCommits(ctx, opts.Doer, pr, comment)
409409
}
410+
// FIXME: since AddTestPullRequestTask was called in a goroutine or a queue worker, is it still necessary to
411+
// call another queue to handle the PR check? Maybe we can use checkPullRequestMergeable directly here?
412+
StartPullRequestCheckImmediately(ctx, pr)
410413
}
411414

412415
if opts.IsSync {

services/pull/update.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,7 @@ func Update(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.
6262
return fmt.Errorf("unable to load HeadRepo for PR[%d] during update-by-merge: %w", pr.ID, err)
6363
}
6464

65-
defer func() {
66-
go AddTestPullRequestTask(TestPullRequestOptions{
67-
RepoID: pr.BaseRepo.ID,
68-
Doer: doer,
69-
Branch: pr.BaseBranch,
70-
IsSync: false,
71-
IsForcePush: false,
72-
OldCommitID: "",
73-
NewCommitID: "",
74-
})
75-
}()
76-
65+
// we don't need to run pull request check here because it will be triggered by push
7766
if rebase {
7867
return updateHeadByRebaseOnToBase(ctx, pr, doer)
7968
}

services/repository/push.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ func pushUpdateBranch(_ context.Context, repo *repo_model.Repository, pusher *us
310310
}
311311

312312
// only update branch can trigger pull request task because the pull request hasn't been created yet when creating a branch
313-
go pull_service.AddTestPullRequestTask(pull_service.TestPullRequestOptions{
313+
// since pushUpdateBrach is called in a queue worker, we don't need to call it in a go routine again
314+
pull_service.AddTestPullRequestTask(pull_service.TestPullRequestOptions{
314315
RepoID: repo.ID,
315316
Doer: pusher,
316317
Branch: branch,

tests/integration/pull_comment_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ func testPullCommentRebase(t *testing.T, u *url.URL, session *TestSession) {
6262
doGitPushTestRepositoryFail(dstPath, "base-repo", "local-branch/rebase:test-branch/rebase")(t)
6363
doGitPushTestRepository(dstPath, "--force", "base-repo", "local-branch/rebase:test-branch/rebase")(t)
6464

65-
// reload the pr
65+
// FIXME: Both the status of the pull request before pushing and the waiting are mergeable. So that
66+
// if it's fast enough here, the pull request checking might be not process yet.
6667
prIssue := testWaitForPullRequestStatus(t, &issues_model.Issue{Title: testPRTitle}, issues_model.PullRequestStatusMergeable)
6768
comments, err := issues_model.FindComments(t.Context(), &issues_model.FindCommentsOptions{
6869
IssueID: prIssue.ID,

0 commit comments

Comments
 (0)