@@ -363,17 +363,21 @@ func AddTestPullRequestTask(opts TestPullRequestOptions) {
363363 // If you don't let it run all the way then you will lose data
364364 // TODO: graceful: AddTestPullRequestTask needs to become a queue!
365365
366+ repo , err := repo_model .GetRepositoryByID (ctx , opts .RepoID )
367+ if err != nil {
368+ log .Error ("GetRepositoryByID: %v" , err )
369+ return
370+ }
366371 // GetUnmergedPullRequestsByHeadInfo() only return open and unmerged PR.
367- // TODO: rename the "prs" to a new variable like "headBranchPRs" to distinguish from the "baseBranchPRs" below
368- // The base repositories of headBranchPRs are different
369- prs , err := issues_model .GetUnmergedPullRequestsByHeadInfo (ctx , opts .RepoID , opts .Branch )
372+ headBranchPRs , err := issues_model .GetUnmergedPullRequestsByHeadInfo (ctx , opts .RepoID , opts .Branch )
370373 if err != nil {
371374 log .Error ("Find pull requests [head_repo_id: %d, head_branch: %s]: %v" , opts .RepoID , opts .Branch , err )
372375 return
373376 }
374377
375- for _ , pr := range prs {
378+ for _ , pr := range headBranchPRs {
376379 log .Trace ("Updating PR[%d]: composing new test task" , pr .ID )
380+ pr .HeadRepo = repo // avoid loading again
377381 if pr .Flow == issues_model .PullRequestFlowGithub {
378382 if err := PushToBaseRepo (ctx , pr ); err != nil {
379383 log .Error ("PushToBaseRepo: %v" , err )
@@ -391,14 +395,14 @@ func AddTestPullRequestTask(opts TestPullRequestOptions) {
391395 }
392396
393397 if opts .IsSync {
394- if err = prs .LoadAttributes (ctx ); err != nil {
398+ if err = headBranchPRs .LoadAttributes (ctx ); err != nil {
395399 log .Error ("PullRequestList.LoadAttributes: %v" , err )
396400 }
397- if invalidationErr := checkForInvalidation (ctx , prs , opts .RepoID , opts .Doer , opts .Branch ); invalidationErr != nil {
401+ if invalidationErr := checkForInvalidation (ctx , headBranchPRs , opts .RepoID , opts .Doer , opts .Branch ); invalidationErr != nil {
398402 log .Error ("checkForInvalidation: %v" , invalidationErr )
399403 }
400404 if err == nil {
401- for _ , pr := range prs {
405+ for _ , pr := range headBranchPRs {
402406 objectFormat := git .ObjectFormatFromName (pr .BaseRepo .ObjectFormatName )
403407 if opts .NewCommitID != "" && opts .NewCommitID != objectFormat .EmptyObjectID ().String () {
404408 changed , err := checkIfPRContentChanged (ctx , pr , opts .OldCommitID , opts .NewCommitID )
@@ -446,20 +450,14 @@ func AddTestPullRequestTask(opts TestPullRequestOptions) {
446450 }
447451
448452 log .Trace ("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests" , opts .RepoID , opts .Branch )
449- // TODO: rename the "prs" to a new variable like "baseBranchPRs" to distinguish from the "headBranchPRs" above
450453 // The base repositories of baseBranchPRs are the same one (opts.RepoID)
451- prs , err = issues_model .GetUnmergedPullRequestsByBaseInfo (ctx , opts .RepoID , opts .Branch )
454+ baseBranchPRs , err : = issues_model .GetUnmergedPullRequestsByBaseInfo (ctx , opts .RepoID , opts .Branch )
452455 if err != nil {
453456 log .Error ("Find pull requests [base_repo_id: %d, base_branch: %s]: %v" , opts .RepoID , opts .Branch , err )
454457 return
455458 }
456- baseRepo , err := repo_model .GetRepositoryByID (ctx , opts .RepoID )
457- if err != nil {
458- log .Error ("GetRepositoryByID: %v" , err )
459- return
460- }
461- for _ , pr := range prs {
462- pr .BaseRepo = baseRepo // avoid loading again
459+ for _ , pr := range baseBranchPRs {
460+ pr .BaseRepo = repo // avoid loading again
463461 err = syncCommitDivergence (ctx , pr )
464462 if err != nil {
465463 if errors .Is (err , util .ErrNotExist ) {
0 commit comments