Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions services/pull/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
asymkey_service "code.gitea.io/gitea/services/asymkey"
)

// prQueue represents a queue to handle update pull request tests
var prQueue queue.UniqueQueue
// prPatchCheckerQueue represents a queue to handle update pull request tests
var prPatchCheckerQueue queue.UniqueQueue

var (
ErrIsClosed = errors.New("pull is cosed")
Expand All @@ -43,7 +43,7 @@ var (

// AddToTaskQueue adds itself to pull request test task queue.
func AddToTaskQueue(pr *models.PullRequest) {
err := prQueue.PushFunc(strconv.FormatInt(pr.ID, 10), func() error {
err := prPatchCheckerQueue.PushFunc(strconv.FormatInt(pr.ID, 10), func() error {
pr.Status = models.PullRequestStatusChecking
err := pr.UpdateColsIfNotMerged("status")
if err != nil {
Expand Down Expand Up @@ -81,6 +81,13 @@ func CheckPullMergable(ctx context.Context, doer *user_model.User, perm *models.
return nil
}

if pr.ProtectedBranch != nil && (!pr.ProtectedBranch.HasEnoughApprovals(pr) ||
pr.ProtectedBranch.MergeBlockedByRejectedReview(pr) ||
pr.ProtectedBranch.MergeBlockedByOfficialReviewRequests(pr) ||
pr.ProtectedBranch.MergeBlockedByOutdatedBranch(pr)) {
return ErrUserNotAllowedToMerge
}

if pr.IsWorkInProgress() {
return ErrIsWorkInProgress
}
Expand Down Expand Up @@ -144,7 +151,7 @@ func checkAndUpdateStatus(pr *models.PullRequest) {
}

// 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 := prPatchCheckerQueue.Has(strconv.FormatInt(pr.ID, 10))
if err != nil {
log.Error("Unable to check if the queue is waiting to reprocess pr.ID %d. Error: %v", pr.ID, err)
}
Expand Down Expand Up @@ -293,7 +300,7 @@ func InitializePullRequests(ctx context.Context) {
case <-ctx.Done():
return
default:
if err := prQueue.PushFunc(strconv.FormatInt(prID, 10), func() error {
if err := prPatchCheckerQueue.PushFunc(strconv.FormatInt(prID, 10), func() error {
log.Trace("Adding PR ID: %d to the pull requests patch checking queue", prID)
return nil
}); err != nil {
Expand Down Expand Up @@ -358,13 +365,13 @@ func CheckPrsForBaseBranch(baseRepo *repo_model.Repository, baseBranchName strin

// Init runs the task queue to test all the checking status pull requests
func Init() error {
prQueue = queue.CreateUniqueQueue("pr_patch_checker", handle, "")
prPatchCheckerQueue = queue.CreateUniqueQueue("pr_patch_checker", handle, "")

if prQueue == nil {
if prPatchCheckerQueue == nil {
return fmt.Errorf("Unable to create pr_patch_checker Queue")
}

go graceful.GetManager().RunWithShutdownFns(prQueue.Run)
go graceful.GetManager().RunWithShutdownFns(prPatchCheckerQueue.Run)
go graceful.GetManager().RunWithShutdownContext(InitializePullRequests)
return nil
}
10 changes: 5 additions & 5 deletions services/pull/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
queueShutdown := []func(){}
queueTerminate := []func(){}

prQueue = q.(queue.UniqueQueue)
prPatchCheckerQueue = q.(queue.UniqueQueue)

pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
AddToTaskQueue(pr)
Expand All @@ -51,11 +51,11 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
return pr.Status == models.PullRequestStatusChecking
}, 1*time.Second, 100*time.Millisecond)

has, err := prQueue.Has(strconv.FormatInt(pr.ID, 10))
has, err := prPatchCheckerQueue.Has(strconv.FormatInt(pr.ID, 10))
assert.True(t, has)
assert.NoError(t, err)

prQueue.Run(func(shutdown func()) {
prPatchCheckerQueue.Run(func(shutdown func()) {
queueShutdown = append(queueShutdown, shutdown)
}, func(terminate func()) {
queueTerminate = append(queueTerminate, terminate)
Expand All @@ -68,7 +68,7 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
assert.Fail(t, "Timeout: nothing was added to pullRequestQueue")
}

has, err = prQueue.Has(strconv.FormatInt(pr.ID, 10))
has, err = prPatchCheckerQueue.Has(strconv.FormatInt(pr.ID, 10))
assert.False(t, has)
assert.NoError(t, err)

Expand All @@ -82,5 +82,5 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
callback()
}

prQueue = nil
prPatchCheckerQueue = nil
}