mirror of
https://github.com/go-gitea/gitea
synced 2024-11-14 14:01:34 +01:00
Backport #30896 by @yp05327 https://github.com/go-gitea/gitea/pull/25812#issuecomment-2099833692 Follow #30573 Co-authored-by: yp05327 <576951401@qq.com>
This commit is contained in:
parent
084bec89ed
commit
2f91a461f7
4 changed files with 10 additions and 10 deletions
|
@ -881,7 +881,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// start with merging by checking
|
// start with merging by checking
|
||||||
if err := pull_service.CheckPullMergable(ctx, ctx.Doer, &ctx.Repo.Permission, pr, mergeCheckType, form.ForceMerge); err != nil {
|
if err := pull_service.CheckPullMergeable(ctx, ctx.Doer, &ctx.Repo.Permission, pr, mergeCheckType, form.ForceMerge); err != nil {
|
||||||
if errors.Is(err, pull_service.ErrIsClosed) {
|
if errors.Is(err, pull_service.ErrIsClosed) {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
} else if errors.Is(err, pull_service.ErrUserNotAllowedToMerge) {
|
} else if errors.Is(err, pull_service.ErrUserNotAllowedToMerge) {
|
||||||
|
@ -890,7 +890,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "PR already merged", "")
|
ctx.Error(http.StatusMethodNotAllowed, "PR already merged", "")
|
||||||
} else if errors.Is(err, pull_service.ErrIsWorkInProgress) {
|
} else if errors.Is(err, pull_service.ErrIsWorkInProgress) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "PR is a work in progress", "Work in progress PRs cannot be merged")
|
ctx.Error(http.StatusMethodNotAllowed, "PR is a work in progress", "Work in progress PRs cannot be merged")
|
||||||
} else if errors.Is(err, pull_service.ErrNotMergableState) {
|
} else if errors.Is(err, pull_service.ErrNotMergeableState) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "PR not in mergeable state", "Please try again later")
|
ctx.Error(http.StatusMethodNotAllowed, "PR not in mergeable state", "Please try again later")
|
||||||
} else if models.IsErrDisallowedToMerge(err) {
|
} else if models.IsErrDisallowedToMerge(err) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "PR is not ready to be merged", err)
|
ctx.Error(http.StatusMethodNotAllowed, "PR is not ready to be merged", err)
|
||||||
|
|
|
@ -1007,7 +1007,7 @@ func MergePullRequest(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// start with merging by checking
|
// start with merging by checking
|
||||||
if err := pull_service.CheckPullMergable(ctx, ctx.Doer, &ctx.Repo.Permission, pr, mergeCheckType, form.ForceMerge); err != nil {
|
if err := pull_service.CheckPullMergeable(ctx, ctx.Doer, &ctx.Repo.Permission, pr, mergeCheckType, form.ForceMerge); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, pull_service.ErrIsClosed):
|
case errors.Is(err, pull_service.ErrIsClosed):
|
||||||
if issue.IsPull {
|
if issue.IsPull {
|
||||||
|
@ -1021,7 +1021,7 @@ func MergePullRequest(ctx *context.Context) {
|
||||||
ctx.JSONError(ctx.Tr("repo.pulls.has_merged"))
|
ctx.JSONError(ctx.Tr("repo.pulls.has_merged"))
|
||||||
case errors.Is(err, pull_service.ErrIsWorkInProgress):
|
case errors.Is(err, pull_service.ErrIsWorkInProgress):
|
||||||
ctx.JSONError(ctx.Tr("repo.pulls.no_merge_wip"))
|
ctx.JSONError(ctx.Tr("repo.pulls.no_merge_wip"))
|
||||||
case errors.Is(err, pull_service.ErrNotMergableState):
|
case errors.Is(err, pull_service.ErrNotMergeableState):
|
||||||
ctx.JSONError(ctx.Tr("repo.pulls.no_merge_not_ready"))
|
ctx.JSONError(ctx.Tr("repo.pulls.no_merge_not_ready"))
|
||||||
case models.IsErrDisallowedToMerge(err):
|
case models.IsErrDisallowedToMerge(err):
|
||||||
ctx.JSONError(ctx.Tr("repo.pulls.no_merge_not_ready"))
|
ctx.JSONError(ctx.Tr("repo.pulls.no_merge_not_ready"))
|
||||||
|
|
|
@ -229,12 +229,12 @@ func handlePull(pullID int64, sha string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pull_service.CheckPullMergable(ctx, doer, &perm, pr, pull_service.MergeCheckTypeGeneral, false); err != nil {
|
if err := pull_service.CheckPullMergeable(ctx, doer, &perm, pr, pull_service.MergeCheckTypeGeneral, false); err != nil {
|
||||||
if errors.Is(pull_service.ErrUserNotAllowedToMerge, err) {
|
if errors.Is(pull_service.ErrUserNotAllowedToMerge, err) {
|
||||||
log.Info("%-v was scheduled to automerge by an unauthorized user", pr)
|
log.Info("%-v was scheduled to automerge by an unauthorized user", pr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Error("%-v CheckPullMergable: %v", pr, err)
|
log.Error("%-v CheckPullMergeable: %v", pr, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ var (
|
||||||
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")
|
||||||
ErrNotMergableState = errors.New("not in mergeable state")
|
ErrNotMergeableState = errors.New("not in mergeable state")
|
||||||
ErrDependenciesLeft = errors.New("is blocked by an open dependency")
|
ErrDependenciesLeft = errors.New("is blocked by an open dependency")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,8 +66,8 @@ const (
|
||||||
MergeCheckTypeAuto // Auto Merge (Scheduled Merge) After Checks Succeed
|
MergeCheckTypeAuto // Auto Merge (Scheduled Merge) After Checks Succeed
|
||||||
)
|
)
|
||||||
|
|
||||||
// CheckPullMergable check if the pull mergeable based on all conditions (branch protection, merge options, ...)
|
// CheckPullMergeable check if the pull mergeable based on all conditions (branch protection, merge options, ...)
|
||||||
func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *access_model.Permission, pr *issues_model.PullRequest, mergeCheckType MergeCheckType, adminSkipProtectionCheck bool) error {
|
func CheckPullMergeable(stdCtx context.Context, doer *user_model.User, perm *access_model.Permission, pr *issues_model.PullRequest, mergeCheckType MergeCheckType, adminSkipProtectionCheck bool) error {
|
||||||
return db.WithTx(stdCtx, func(ctx context.Context) error {
|
return db.WithTx(stdCtx, func(ctx context.Context) error {
|
||||||
if pr.HasMerged {
|
if pr.HasMerged {
|
||||||
return ErrHasMerged
|
return ErrHasMerged
|
||||||
|
@ -97,7 +97,7 @@ func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *acce
|
||||||
}
|
}
|
||||||
|
|
||||||
if !pr.CanAutoMerge() && !pr.IsEmpty() {
|
if !pr.CanAutoMerge() && !pr.IsEmpty() {
|
||||||
return ErrNotMergableState
|
return ErrNotMergeableState
|
||||||
}
|
}
|
||||||
|
|
||||||
if pr.IsChecking() {
|
if pr.IsChecking() {
|
||||||
|
|
Loading…
Reference in a new issue