@@ -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
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 , isForPush 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,25 +410,25 @@ 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 requests := issues_model .PullRequestList (prs )
411421 if err = requests .LoadAttributes (ctx ); err != nil {
412422 log .Error ("PullRequestList.LoadAttributes: %v" , err )
413423 }
414- if invalidationErr := checkForInvalidation (ctx , requests , repoID , doer , branch ); invalidationErr != nil {
424+ if invalidationErr := checkForInvalidation (ctx , requests , opts . RepoID , opts . Doer , opts . Branch ); invalidationErr != nil {
415425 log .Error ("checkForInvalidation: %v" , invalidationErr )
416426 }
417427 if err == nil {
418428 for _ , pr := range prs {
419429 objectFormat := git .ObjectFormatFromName (pr .BaseRepo .ObjectFormatName )
420- if newCommitID != "" && newCommitID != objectFormat .EmptyObjectID ().String () {
421- changed , err := checkIfPRContentChanged (ctx , pr , oldCommitID , newCommitID )
430+ if opts . NewCommitID != "" && opts . NewCommitID != objectFormat .EmptyObjectID ().String () {
431+ changed , err := checkIfPRContentChanged (ctx , pr , opts . OldCommitID , opts . NewCommitID )
422432 if err != nil {
423433 log .Error ("checkIfPRContentChanged: %v" , err )
424434 }
@@ -434,12 +444,12 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
434444 log .Error ("GetFirstMatchProtectedBranchRule: %v" , err )
435445 }
436446 if pb != nil && pb .DismissStaleApprovals {
437- if err := DismissApprovalReviews (ctx , doer , pr ); err != nil {
447+ if err := DismissApprovalReviews (ctx , opts . Doer , pr ); err != nil {
438448 log .Error ("DismissApprovalReviews: %v" , err )
439449 }
440450 }
441451 }
442- if err := issues_model .MarkReviewsAsNotStale (ctx , pr .IssueID , newCommitID ); err != nil {
452+ if err := issues_model .MarkReviewsAsNotStale (ctx , pr .IssueID , opts . NewCommitID ); err != nil {
443453 log .Error ("MarkReviewsAsNotStale: %v" , err )
444454 }
445455 divergence , err := GetDiverging (ctx , pr )
@@ -455,28 +465,28 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
455465
456466 if ! pr .IsWorkInProgress (ctx ) {
457467 var reviewNotifiers []* issue_service.ReviewRequestNotifier
458- if isForPush {
468+ if opts . IsForcePush {
459469 reviewNotifiers , err = issue_service .PullRequestCodeOwnersReview (ctx , pr )
460470 } else {
461- reviewNotifiers , err = issue_service .PullRequestCodeOwnersReviewSpecialCommits (ctx , pr , oldCommitID , newCommitID )
471+ reviewNotifiers , err = issue_service .PullRequestCodeOwnersReviewSpecialCommits (ctx , pr , opts . OldCommitID , opts . NewCommitID )
462472 }
463473 if err != nil {
464474 log .Error ("PullRequestCodeOwnersReview: %v" , err )
465475 }
466476 if len (reviewNotifiers ) > 0 {
467- issue_service .ReviewRequestNotify (ctx , pr .Issue , doer , reviewNotifiers )
477+ issue_service .ReviewRequestNotify (ctx , pr .Issue , opts . Doer , reviewNotifiers )
468478 }
469479 }
470480
471- notify_service .PullRequestSynchronized (ctx , doer , pr )
481+ notify_service .PullRequestSynchronized (ctx , opts . Doer , pr )
472482 }
473483 }
474484 }
475485
476- log .Trace ("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests" , repoID , branch )
477- prs , err = issues_model .GetUnmergedPullRequestsByBaseInfo (ctx , repoID , branch )
486+ log .Trace ("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests" , opts . RepoID , opts . Branch )
487+ prs , err = issues_model .GetUnmergedPullRequestsByBaseInfo (ctx , opts . RepoID , opts . Branch )
478488 if err != nil {
479- log .Error ("Find pull requests [base_repo_id: %d, base_branch: %s]: %v" , repoID , branch , err )
489+ log .Error ("Find pull requests [base_repo_id: %d, base_branch: %s]: %v" , opts . RepoID , opts . Branch , err )
480490 return
481491 }
482492 for _ , pr := range prs {
0 commit comments