@@ -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
}
@@ -349,19 +349,29 @@ func checkForInvalidation(ctx context.Context, requests issues_model.PullRequest
349
349
return nil
350
350
}
351
351
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
+
352
362
// AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch,
353
363
// 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 )
356
366
graceful .GetManager ().RunWithShutdownContext (func (ctx context.Context ) {
357
367
// There is no sensible way to shut this down ":-("
358
368
// If you don't let it run all the way then you will lose data
359
369
// TODO: graceful: AddTestPullRequestTask needs to become a queue!
360
370
361
371
// 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 )
363
373
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 )
365
375
return
366
376
}
367
377
@@ -377,25 +387,24 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
377
387
}
378
388
379
389
AddToTaskQueue (ctx , pr )
380
- comment , err := CreatePushPullComment (ctx , doer , pr , oldCommitID , newCommitID )
390
+ comment , err := CreatePushPullComment (ctx , opts . Doer , pr , opts . OldCommitID , opts . NewCommitID )
381
391
if err == nil && comment != nil {
382
- notify_service .PullRequestPushCommits (ctx , doer , pr , comment )
392
+ notify_service .PullRequestPushCommits (ctx , opts . Doer , pr , comment )
383
393
}
384
394
}
385
395
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 {
389
398
log .Error ("PullRequestList.LoadAttributes: %v" , err )
390
399
}
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 {
392
401
log .Error ("checkForInvalidation: %v" , invalidationErr )
393
402
}
394
403
if err == nil {
395
404
for _ , pr := range prs {
396
405
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 )
399
408
if err != nil {
400
409
log .Error ("checkIfPRContentChanged: %v" , err )
401
410
}
@@ -411,12 +420,12 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
411
420
log .Error ("GetFirstMatchProtectedBranchRule: %v" , err )
412
421
}
413
422
if pb != nil && pb .DismissStaleApprovals {
414
- if err := DismissApprovalReviews (ctx , doer , pr ); err != nil {
423
+ if err := DismissApprovalReviews (ctx , opts . Doer , pr ); err != nil {
415
424
log .Error ("DismissApprovalReviews: %v" , err )
416
425
}
417
426
}
418
427
}
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 {
420
429
log .Error ("MarkReviewsAsNotStale: %v" , err )
421
430
}
422
431
divergence , err := GetDiverging (ctx , pr )
@@ -430,15 +439,30 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
430
439
}
431
440
}
432
441
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 )
434
458
}
435
459
}
436
460
}
437
461
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 )
440
464
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 )
442
466
return
443
467
}
444
468
for _ , pr := range prs {
0 commit comments