@@ -176,7 +176,7 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
176176 }
177177
178178 if ! pr .IsWorkInProgress (ctx ) {
179- reviewNotifiers , err = issue_service .PullRequestCodeOwnersReview (ctx , issue , pr )
179+ reviewNotifiers , err = issue_service .PullRequestCodeOwnersReview (ctx , pr )
180180 if err != nil {
181181 return err
182182 }
@@ -349,19 +349,29 @@ func checkForInvalidation(ctx context.Context, requests issues_model.PullRequest
349349 return nil
350350}
351351
352+ type TestPullRequestOptions struct {
353+ RepoID int64
354+ Doer * user_model.User
355+ Branch string
356+ IsSync bool // True means it's a pull request synchronization, false means it's triggered for pull request merging or updating
357+ IsForcePush bool
358+ OldCommitID string
359+ NewCommitID string
360+ }
361+
352362// AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch,
353363// and generate new patch for testing as needed.
354- func AddTestPullRequestTask (doer * user_model. User , repoID int64 , branch string , isSync bool , oldCommitID , newCommitID string ) {
355- log .Trace ("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests" , repoID , branch )
364+ func AddTestPullRequestTask (opts TestPullRequestOptions ) {
365+ log .Trace ("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests" , opts . RepoID , opts . Branch )
356366 graceful .GetManager ().RunWithShutdownContext (func (ctx context.Context ) {
357367 // There is no sensible way to shut this down ":-("
358368 // If you don't let it run all the way then you will lose data
359369 // TODO: graceful: AddTestPullRequestTask needs to become a queue!
360370
361371 // GetUnmergedPullRequestsByHeadInfo() only return open and unmerged PR.
362- prs , err := issues_model .GetUnmergedPullRequestsByHeadInfo (ctx , repoID , branch )
372+ prs , err := issues_model .GetUnmergedPullRequestsByHeadInfo (ctx , opts . RepoID , opts . Branch )
363373 if err != nil {
364- log .Error ("Find pull requests [head_repo_id: %d, head_branch: %s]: %v" , repoID , branch , err )
374+ log .Error ("Find pull requests [head_repo_id: %d, head_branch: %s]: %v" , opts . RepoID , opts . Branch , err )
365375 return
366376 }
367377
@@ -377,25 +387,24 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
377387 }
378388
379389 AddToTaskQueue (ctx , pr )
380- comment , err := CreatePushPullComment (ctx , doer , pr , oldCommitID , newCommitID )
390+ comment , err := CreatePushPullComment (ctx , opts . Doer , pr , opts . OldCommitID , opts . NewCommitID )
381391 if err == nil && comment != nil {
382- notify_service .PullRequestPushCommits (ctx , doer , pr , comment )
392+ notify_service .PullRequestPushCommits (ctx , opts . Doer , pr , comment )
383393 }
384394 }
385395
386- if isSync {
387- requests := issues_model .PullRequestList (prs )
388- if err = requests .LoadAttributes (ctx ); err != nil {
396+ if opts .IsSync {
397+ if err = issues_model .PullRequestList (prs ).LoadAttributes (ctx ); err != nil {
389398 log .Error ("PullRequestList.LoadAttributes: %v" , err )
390399 }
391- if invalidationErr := checkForInvalidation (ctx , requests , repoID , doer , branch ); invalidationErr != nil {
400+ if invalidationErr := checkForInvalidation (ctx , prs , opts . RepoID , opts . Doer , opts . Branch ); invalidationErr != nil {
392401 log .Error ("checkForInvalidation: %v" , invalidationErr )
393402 }
394403 if err == nil {
395404 for _ , pr := range prs {
396405 objectFormat := git .ObjectFormatFromName (pr .BaseRepo .ObjectFormatName )
397- if newCommitID != "" && newCommitID != objectFormat .EmptyObjectID ().String () {
398- changed , err := checkIfPRContentChanged (ctx , pr , oldCommitID , newCommitID )
406+ if opts . NewCommitID != "" && opts . NewCommitID != objectFormat .EmptyObjectID ().String () {
407+ changed , err := checkIfPRContentChanged (ctx , pr , opts . OldCommitID , opts . NewCommitID )
399408 if err != nil {
400409 log .Error ("checkIfPRContentChanged: %v" , err )
401410 }
@@ -411,12 +420,12 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
411420 log .Error ("GetFirstMatchProtectedBranchRule: %v" , err )
412421 }
413422 if pb != nil && pb .DismissStaleApprovals {
414- if err := DismissApprovalReviews (ctx , doer , pr ); err != nil {
423+ if err := DismissApprovalReviews (ctx , opts . Doer , pr ); err != nil {
415424 log .Error ("DismissApprovalReviews: %v" , err )
416425 }
417426 }
418427 }
419- if err := issues_model .MarkReviewsAsNotStale (ctx , pr .IssueID , newCommitID ); err != nil {
428+ if err := issues_model .MarkReviewsAsNotStale (ctx , pr .IssueID , opts . NewCommitID ); err != nil {
420429 log .Error ("MarkReviewsAsNotStale: %v" , err )
421430 }
422431 divergence , err := GetDiverging (ctx , pr )
@@ -430,15 +439,30 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
430439 }
431440 }
432441
433- notify_service .PullRequestSynchronized (ctx , doer , pr )
442+ if ! pr .IsWorkInProgress (ctx ) {
443+ var reviewNotifiers []* issue_service.ReviewRequestNotifier
444+ if opts .IsForcePush {
445+ reviewNotifiers , err = issue_service .PullRequestCodeOwnersReview (ctx , pr )
446+ } else {
447+ reviewNotifiers , err = issue_service .PullRequestCodeOwnersReviewSpecialCommits (ctx , pr , opts .OldCommitID , opts .NewCommitID )
448+ }
449+ if err != nil {
450+ log .Error ("PullRequestCodeOwnersReview: %v" , err )
451+ }
452+ if len (reviewNotifiers ) > 0 {
453+ issue_service .ReviewRequestNotify (ctx , pr .Issue , opts .Doer , reviewNotifiers )
454+ }
455+ }
456+
457+ notify_service .PullRequestSynchronized (ctx , opts .Doer , pr )
434458 }
435459 }
436460 }
437461
438- log .Trace ("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests" , repoID , branch )
439- prs , err = issues_model .GetUnmergedPullRequestsByBaseInfo (ctx , repoID , branch )
462+ log .Trace ("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests" , opts . RepoID , opts . Branch )
463+ prs , err = issues_model .GetUnmergedPullRequestsByBaseInfo (ctx , opts . RepoID , opts . Branch )
440464 if err != nil {
441- log .Error ("Find pull requests [base_repo_id: %d, base_branch: %s]: %v" , repoID , branch , err )
465+ log .Error ("Find pull requests [base_repo_id: %d, base_branch: %s]: %v" , opts . RepoID , opts . Branch , err )
442466 return
443467 }
444468 for _ , pr := range prs {
0 commit comments