@@ -176,7 +176,7 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
176
176
}
177
177
178
178
if ! pr .IsWorkInProgress (ctx ) {
179
- reviewNotifiers , err = issue_service .PullRequestCodeOwnersReview (ctx , issue , pr )
179
+ reviewNotifiers , err = issue_service .PullRequestCodeOwnersReview (ctx , pr )
180
180
if err != nil {
181
181
return err
182
182
}
@@ -372,19 +372,29 @@ func checkForInvalidation(ctx context.Context, requests issues_model.PullRequest
372
372
return nil
373
373
}
374
374
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
+
375
385
// AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch,
376
386
// 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 )
379
389
graceful .GetManager ().RunWithShutdownContext (func (ctx context.Context ) {
380
390
// There is no sensible way to shut this down ":-("
381
391
// If you don't let it run all the way then you will lose data
382
392
// TODO: graceful: AddTestPullRequestTask needs to become a queue!
383
393
384
394
// 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 )
386
396
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 )
388
398
return
389
399
}
390
400
@@ -400,24 +410,24 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
400
410
}
401
411
402
412
AddToTaskQueue (ctx , pr )
403
- comment , err := CreatePushPullComment (ctx , doer , pr , oldCommitID , newCommitID )
413
+ comment , err := CreatePushPullComment (ctx , opts . Doer , pr , opts . OldCommitID , opts . NewCommitID )
404
414
if err == nil && comment != nil {
405
- notify_service .PullRequestPushCommits (ctx , doer , pr , comment )
415
+ notify_service .PullRequestPushCommits (ctx , opts . Doer , pr , comment )
406
416
}
407
417
}
408
418
409
- if isSync {
419
+ if opts . IsSync {
410
420
if err = prs .LoadAttributes (ctx ); err != nil {
411
421
log .Error ("PullRequestList.LoadAttributes: %v" , err )
412
422
}
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 {
414
424
log .Error ("checkForInvalidation: %v" , invalidationErr )
415
425
}
416
426
if err == nil {
417
427
for _ , pr := range prs {
418
428
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 )
421
431
if err != nil {
422
432
log .Error ("checkIfPRContentChanged: %v" , err )
423
433
}
@@ -433,12 +443,12 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
433
443
log .Error ("GetFirstMatchProtectedBranchRule: %v" , err )
434
444
}
435
445
if pb != nil && pb .DismissStaleApprovals {
436
- if err := DismissApprovalReviews (ctx , doer , pr ); err != nil {
446
+ if err := DismissApprovalReviews (ctx , opts . Doer , pr ); err != nil {
437
447
log .Error ("DismissApprovalReviews: %v" , err )
438
448
}
439
449
}
440
450
}
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 {
442
452
log .Error ("MarkReviewsAsNotStale: %v" , err )
443
453
}
444
454
divergence , err := GetDiverging (ctx , pr )
@@ -452,15 +462,30 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
452
462
}
453
463
}
454
464
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 )
456
481
}
457
482
}
458
483
}
459
484
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 )
462
487
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 )
464
489
return
465
490
}
466
491
for _ , pr := range prs {
0 commit comments