@ -28,12 +28,12 @@ import (
asymkey_service "code.gitea.io/gitea/services/asymkey"
asymkey_service "code.gitea.io/gitea/services/asymkey"
)
)
// prQueue represents a queue to handle update pull request tests
// prPatchChecker Queue represents a queue to handle update pull request tests
var prQueue queue . UniqueQueue
var prPatchChecker Queue queue . UniqueQueue
var (
var (
ErrIsClosed = errors . New ( "pull is cosed" )
ErrIsClosed = errors . New ( "pull is cl osed" )
ErrUserNotAllowedToMerge = errors . New ( "user not allowed to merge" )
ErrUserNotAllowedToMerge = models . ErrDisallowedToMerge { }
ErrHasMerged = errors . New ( "has already been merged" )
ErrHasMerged = errors . New ( "has already been merged" )
ErrIsWorkInProgress = errors . New ( "work in progress PRs cannot be merged" )
ErrIsWorkInProgress = errors . New ( "work in progress PRs cannot be merged" )
ErrIsChecking = errors . New ( "cannot merge while conflict checking is in progress" )
ErrIsChecking = errors . New ( "cannot merge while conflict checking is in progress" )
@ -43,7 +43,7 @@ var (
// AddToTaskQueue adds itself to pull request test task queue.
// AddToTaskQueue adds itself to pull request test task queue.
func AddToTaskQueue ( pr * models . PullRequest ) {
func AddToTaskQueue ( pr * models . PullRequest ) {
err := prQueue . PushFunc ( strconv . FormatInt ( pr . ID , 10 ) , func ( ) error {
err := prPatchChecker Queue . PushFunc ( strconv . FormatInt ( pr . ID , 10 ) , func ( ) error {
pr . Status = models . PullRequestStatusChecking
pr . Status = models . PullRequestStatusChecking
err := pr . UpdateColsIfNotMerged ( "status" )
err := pr . UpdateColsIfNotMerged ( "status" )
if err != nil {
if err != nil {
@ -93,13 +93,13 @@ func CheckPullMergable(ctx context.Context, doer *user_model.User, perm *models.
return ErrIsChecking
return ErrIsChecking
}
}
if err := CheckPRReadyToMerge ( ctx , pr , false ) ; err != nil {
if err := CheckPullBranchProtections ( ctx , pr , false ) ; err != nil {
if models . IsErrDisallowedToMerge ( err ) {
if models . IsErrDisallowedToMerge ( err ) {
if force {
if force {
if isRepoAdmin , err := models . IsUserRepoAdmin ( pr . BaseRepo , doer ) ; err != nil {
if isRepoAdmin , err2 := models . IsUserRepoAdmin ( pr . BaseRepo , doer ) ; err2 != nil {
return err
return err2
} else if ! isRepoAdmin {
} else if ! isRepoAdmin {
return ErrUs erNotAllowedToMe rge
return err
}
}
}
}
} else {
} else {
@ -144,7 +144,7 @@ func checkAndUpdateStatus(pr *models.PullRequest) {
}
}
// Make sure there is no waiting test to process before leaving the checking status.
// Make sure there is no waiting test to process before leaving the checking status.
has , err := prQueue . Has ( strconv . FormatInt ( pr . ID , 10 ) )
has , err := prPatchChecker Queue . Has ( strconv . FormatInt ( pr . ID , 10 ) )
if err != nil {
if err != nil {
log . Error ( "Unable to check if the queue is waiting to reprocess pr.ID %d. Error: %v" , pr . ID , err )
log . Error ( "Unable to check if the queue is waiting to reprocess pr.ID %d. Error: %v" , pr . ID , err )
}
}
@ -293,7 +293,7 @@ func InitializePullRequests(ctx context.Context) {
case <- ctx . Done ( ) :
case <- ctx . Done ( ) :
return
return
default :
default :
if err := prQueue . PushFunc ( strconv . FormatInt ( prID , 10 ) , func ( ) error {
if err := prPatchChecker Queue . PushFunc ( strconv . FormatInt ( prID , 10 ) , func ( ) error {
log . Trace ( "Adding PR ID: %d to the pull requests patch checking queue" , prID )
log . Trace ( "Adding PR ID: %d to the pull requests patch checking queue" , prID )
return nil
return nil
} ) ; err != nil {
} ) ; err != nil {
@ -358,13 +358,13 @@ func CheckPrsForBaseBranch(baseRepo *repo_model.Repository, baseBranchName strin
// Init runs the task queue to test all the checking status pull requests
// Init runs the task queue to test all the checking status pull requests
func Init ( ) error {
func Init ( ) error {
prQueue = queue . CreateUniqueQueue ( "pr_patch_checker" , handle , "" )
prPatchChecker Queue = queue . CreateUniqueQueue ( "pr_patch_checker" , handle , "" )
if prQueue == nil {
if prPatchChecker Queue == nil {
return fmt . Errorf ( "Unable to create pr_patch_checker Queue" )
return fmt . Errorf ( "Unable to create pr_patch_checker Queue" )
}
}
go graceful . GetManager ( ) . RunWithShutdownFns ( prQueue . Run )
go graceful . GetManager ( ) . RunWithShutdownFns ( prPatchChecker Queue . Run )
go graceful . GetManager ( ) . RunWithShutdownContext ( InitializePullRequests )
go graceful . GetManager ( ) . RunWithShutdownContext ( InitializePullRequests )
return nil
return nil
}
}