@ -176,7 +176,7 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
}
if ! pr . IsWorkInProgress ( ctx ) {
reviewNotifiers , err = issue_service . PullRequestCodeOwnersReview ( ctx , issue, pr)
reviewNotifiers , err = issue_service . PullRequestCodeOwnersReview ( ctx , pr)
if err != nil {
return err
}
@ -372,19 +372,29 @@ func checkForInvalidation(ctx context.Context, requests issues_model.PullRequest
return nil
}
type TestPullRequestOptions struct {
RepoID int64
Doer * user_model . User
Branch string
IsSync bool // True means it's a pull request synchronization, false means it's triggered for pull request merging or updating
IsForcePush bool
OldCommitID string
NewCommitID string
}
// AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch,
// and generate new patch for testing as needed.
func AddTestPullRequestTask ( doer * user_model . User , repoID int64 , branch string , isSync bool , oldCommitID , newCommitID string ) {
log . Trace ( "AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests" , repoID , branch )
func AddTestPullRequestTask ( opts TestPullRequestOptions ) {
log . Trace ( "AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests" , opts. RepoID , opts . B ranch)
graceful . GetManager ( ) . RunWithShutdownContext ( func ( ctx context . Context ) {
// There is no sensible way to shut this down ":-("
// If you don't let it run all the way then you will lose data
// TODO: graceful: AddTestPullRequestTask needs to become a queue!
// GetUnmergedPullRequestsByHeadInfo() only return open and unmerged PR.
prs , err := issues_model . GetUnmergedPullRequestsByHeadInfo ( ctx , repoID, b ranch)
prs , err := issues_model . GetUnmergedPullRequestsByHeadInfo ( ctx , opts. RepoID , opts . B ranch)
if err != nil {
log . Error ( "Find pull requests [head_repo_id: %d, head_branch: %s]: %v" , repoID, b ranch, err )
log . Error ( "Find pull requests [head_repo_id: %d, head_branch: %s]: %v" , opts. RepoID , opts . B ranch, err )
return
}
@ -400,24 +410,24 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
}
AddToTaskQueue ( ctx , pr )
comment , err := CreatePushPullComment ( ctx , doer, pr , oldCommitID , n ewCommitID)
comment , err := CreatePushPullComment ( ctx , opts. Doer , pr , opts . OldCommitID , opts . N ewCommitID)
if err == nil && comment != nil {
notify_service . PullRequestPushCommits ( ctx , d oer, pr , comment )
notify_service . PullRequestPushCommits ( ctx , opts. D oer, pr , comment )
}
}
if i sSync {
if opts. I sSync {
if err = prs . LoadAttributes ( ctx ) ; err != nil {
log . Error ( "PullRequestList.LoadAttributes: %v" , err )
}
if invalidationErr := checkForInvalidation ( ctx , prs , repoID, doer , b ranch) ; invalidationErr != nil {
if invalidationErr := checkForInvalidation ( ctx , prs , opts. RepoID , opts . Doer , opts . B ranch) ; invalidationErr != nil {
log . Error ( "checkForInvalidation: %v" , invalidationErr )
}
if err == nil {
for _ , pr := range prs {
objectFormat := git . ObjectFormatFromName ( pr . BaseRepo . ObjectFormatName )
if newCommitID != "" && n ewCommitID != objectFormat . EmptyObjectID ( ) . String ( ) {
changed , err := checkIfPRContentChanged ( ctx , pr , o ldCommitID, n ewCommitID)
if opts. NewCommitID != "" && opts . N ewCommitID != objectFormat . EmptyObjectID ( ) . String ( ) {
changed , err := checkIfPRContentChanged ( ctx , pr , o pts. OldCommitID , opts . N ewCommitID)
if err != nil {
log . Error ( "checkIfPRContentChanged: %v" , err )
}
@ -433,12 +443,12 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
log . Error ( "GetFirstMatchProtectedBranchRule: %v" , err )
}
if pb != nil && pb . DismissStaleApprovals {
if err := DismissApprovalReviews ( ctx , d oer, pr ) ; err != nil {
if err := DismissApprovalReviews ( ctx , opts. D oer, pr ) ; err != nil {
log . Error ( "DismissApprovalReviews: %v" , err )
}
}
}
if err := issues_model . MarkReviewsAsNotStale ( ctx , pr . IssueID , n ewCommitID) ; err != nil {
if err := issues_model . MarkReviewsAsNotStale ( ctx , pr . IssueID , opts. N ewCommitID) ; err != nil {
log . Error ( "MarkReviewsAsNotStale: %v" , err )
}
divergence , err := GetDiverging ( ctx , pr )
@ -452,15 +462,30 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
}
}
notify_service . PullRequestSynchronized ( ctx , doer , pr )
if ! pr . IsWorkInProgress ( ctx ) {
var reviewNotifiers [ ] * issue_service . ReviewRequestNotifier
if opts . IsForcePush {
reviewNotifiers , err = issue_service . PullRequestCodeOwnersReview ( ctx , pr )
} else {
reviewNotifiers , err = issue_service . PullRequestCodeOwnersReviewSpecialCommits ( ctx , pr , opts . OldCommitID , opts . NewCommitID )
}
if err != nil {
log . Error ( "PullRequestCodeOwnersReview: %v" , err )
}
if len ( reviewNotifiers ) > 0 {
issue_service . ReviewRequestNotify ( ctx , pr . Issue , opts . Doer , reviewNotifiers )
}
}
notify_service . PullRequestSynchronized ( ctx , opts . Doer , pr )
}
}
}
log . Trace ( "AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests" , repoID , branch )
prs , err = issues_model . GetUnmergedPullRequestsByBaseInfo ( ctx , repoID , branch )
log . Trace ( "AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests" , opts. RepoID , opts . B ranch)
prs , err = issues_model . GetUnmergedPullRequestsByBaseInfo ( ctx , opts. RepoID , opts . B ranch)
if err != nil {
log . Error ( "Find pull requests [base_repo_id: %d, base_branch: %s]: %v" , repoID , branch , err )
log . Error ( "Find pull requests [base_repo_id: %d, base_branch: %s]: %v" , opts. RepoID , opts . B ranch, err )
return
}
for _ , pr := range prs {