@@ -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 }
@@ -372,19 +372,29 @@ func checkForInvalidation(ctx context.Context, requests issues_model.PullRequest
372372 return nil
373373}
374374
375+ type TestPullRequestOptions struct {
376+ RepoID int64
377+ Doer * user_model.User
378+ Branch string
379+ IsSync bool // True means it's a pull request synchronization, false means it's triggered for pull request merging or updating
380+ IsForcePush bool
381+ OldCommitID string
382+ NewCommitID string
383+ }
384+
375385// AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch,
376386// and generate new patch for testing as needed.
377- func AddTestPullRequestTask (doer * user_model. User , repoID int64 , branch string , isSync bool , oldCommitID , newCommitID string ) {
378- log .Trace ("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests" , repoID , branch )
387+ func AddTestPullRequestTask (opts TestPullRequestOptions ) {
388+ log .Trace ("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests" , opts . RepoID , opts . Branch )
379389 graceful .GetManager ().RunWithShutdownContext (func (ctx context.Context ) {
380390 // There is no sensible way to shut this down ":-("
381391 // If you don't let it run all the way then you will lose data
382392 // TODO: graceful: AddTestPullRequestTask needs to become a queue!
383393
384394 // GetUnmergedPullRequestsByHeadInfo() only return open and unmerged PR.
385- prs , err := issues_model .GetUnmergedPullRequestsByHeadInfo (ctx , repoID , branch )
395+ prs , err := issues_model .GetUnmergedPullRequestsByHeadInfo (ctx , opts . RepoID , opts . Branch )
386396 if err != nil {
387- log .Error ("Find pull requests [head_repo_id: %d, head_branch: %s]: %v" , repoID , branch , err )
397+ log .Error ("Find pull requests [head_repo_id: %d, head_branch: %s]: %v" , opts . RepoID , opts . Branch , err )
388398 return
389399 }
390400
@@ -400,24 +410,24 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
400410 }
401411
402412 AddToTaskQueue (ctx , pr )
403- comment , err := CreatePushPullComment (ctx , doer , pr , oldCommitID , newCommitID )
413+ comment , err := CreatePushPullComment (ctx , opts . Doer , pr , opts . OldCommitID , opts . NewCommitID )
404414 if err == nil && comment != nil {
405- notify_service .PullRequestPushCommits (ctx , doer , pr , comment )
415+ notify_service .PullRequestPushCommits (ctx , opts . Doer , pr , comment )
406416 }
407417 }
408418
409- if isSync {
419+ if opts . IsSync {
410420 if err = prs .LoadAttributes (ctx ); err != nil {
411421 log .Error ("PullRequestList.LoadAttributes: %v" , err )
412422 }
413- if invalidationErr := checkForInvalidation (ctx , prs , repoID , doer , branch ); invalidationErr != nil {
423+ if invalidationErr := checkForInvalidation (ctx , prs , opts . RepoID , opts . Doer , opts . Branch ); invalidationErr != nil {
414424 log .Error ("checkForInvalidation: %v" , invalidationErr )
415425 }
416426 if err == nil {
417427 for _ , pr := range prs {
418428 objectFormat := git .ObjectFormatFromName (pr .BaseRepo .ObjectFormatName )
419- if newCommitID != "" && newCommitID != objectFormat .EmptyObjectID ().String () {
420- changed , err := checkIfPRContentChanged (ctx , pr , oldCommitID , newCommitID )
429+ if opts . NewCommitID != "" && opts . NewCommitID != objectFormat .EmptyObjectID ().String () {
430+ changed , err := checkIfPRContentChanged (ctx , pr , opts . OldCommitID , opts . NewCommitID )
421431 if err != nil {
422432 log .Error ("checkIfPRContentChanged: %v" , err )
423433 }
@@ -433,12 +443,12 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
433443 log .Error ("GetFirstMatchProtectedBranchRule: %v" , err )
434444 }
435445 if pb != nil && pb .DismissStaleApprovals {
436- if err := DismissApprovalReviews (ctx , doer , pr ); err != nil {
446+ if err := DismissApprovalReviews (ctx , opts . Doer , pr ); err != nil {
437447 log .Error ("DismissApprovalReviews: %v" , err )
438448 }
439449 }
440450 }
441- if err := issues_model .MarkReviewsAsNotStale (ctx , pr .IssueID , newCommitID ); err != nil {
451+ if err := issues_model .MarkReviewsAsNotStale (ctx , pr .IssueID , opts . NewCommitID ); err != nil {
442452 log .Error ("MarkReviewsAsNotStale: %v" , err )
443453 }
444454 divergence , err := GetDiverging (ctx , pr )
@@ -452,15 +462,30 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
452462 }
453463 }
454464
455- notify_service .PullRequestSynchronized (ctx , doer , pr )
465+ if ! pr .IsWorkInProgress (ctx ) {
466+ var reviewNotifiers []* issue_service.ReviewRequestNotifier
467+ if opts .IsForcePush {
468+ reviewNotifiers , err = issue_service .PullRequestCodeOwnersReview (ctx , pr )
469+ } else {
470+ reviewNotifiers , err = issue_service .PullRequestCodeOwnersReviewSpecialCommits (ctx , pr , opts .OldCommitID , opts .NewCommitID )
471+ }
472+ if err != nil {
473+ log .Error ("PullRequestCodeOwnersReview: %v" , err )
474+ }
475+ if len (reviewNotifiers ) > 0 {
476+ issue_service .ReviewRequestNotify (ctx , pr .Issue , opts .Doer , reviewNotifiers )
477+ }
478+ }
479+
480+ notify_service .PullRequestSynchronized (ctx , opts .Doer , pr )
456481 }
457482 }
458483 }
459484
460- log .Trace ("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests" , repoID , branch )
461- prs , err = issues_model .GetUnmergedPullRequestsByBaseInfo (ctx , repoID , branch )
485+ log .Trace ("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests" , opts . RepoID , opts . Branch )
486+ prs , err = issues_model .GetUnmergedPullRequestsByBaseInfo (ctx , opts . RepoID , opts . Branch )
462487 if err != nil {
463- log .Error ("Find pull requests [base_repo_id: %d, base_branch: %s]: %v" , repoID , branch , err )
488+ log .Error ("Find pull requests [base_repo_id: %d, base_branch: %s]: %v" , opts . RepoID , opts . Branch , err )
464489 return
465490 }
466491 for _ , pr := range prs {
0 commit comments