mirror of
https://github.com/go-gitea/gitea
synced 2024-11-25 02:22:46 +01:00
Backport #31880 by @yp05327 A quick fix for #31871 Co-authored-by: yp05327 <576951401@qq.com>
This commit is contained in:
parent
0de69c26ec
commit
b5500cded1
3 changed files with 41 additions and 10 deletions
|
@ -886,7 +886,20 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := issue_service.ChangeStatus(ctx, issue, ctx.Doer, "", api.StateClosed == api.StateType(*form.State)); err != nil {
|
|
||||||
|
var isClosed bool
|
||||||
|
switch state := api.StateType(*form.State); state {
|
||||||
|
case api.StateOpen:
|
||||||
|
isClosed = false
|
||||||
|
case api.StateClosed:
|
||||||
|
isClosed = true
|
||||||
|
default:
|
||||||
|
ctx.Error(http.StatusPreconditionFailed, "UnknownIssueStateError", fmt.Sprintf("unknown state: %s", state))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if issue.IsClosed != isClosed {
|
||||||
|
if err := issue_service.ChangeStatus(ctx, issue, ctx.Doer, "", isClosed); err != nil {
|
||||||
if issues_model.IsErrDependenciesLeft(err) {
|
if issues_model.IsErrDependenciesLeft(err) {
|
||||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
|
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
|
||||||
return
|
return
|
||||||
|
@ -895,6 +908,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Refetch from database to assign some automatic values
|
// Refetch from database to assign some automatic values
|
||||||
issue, err = issues_model.GetIssueByID(ctx, issue.ID)
|
issue, err = issues_model.GetIssueByID(ctx, issue.ID)
|
||||||
|
|
|
@ -695,7 +695,20 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusPreconditionFailed, "MergedPRState", "cannot change state of this pull request, it was already merged")
|
ctx.Error(http.StatusPreconditionFailed, "MergedPRState", "cannot change state of this pull request, it was already merged")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := issue_service.ChangeStatus(ctx, issue, ctx.Doer, "", api.StateClosed == api.StateType(*form.State)); err != nil {
|
|
||||||
|
var isClosed bool
|
||||||
|
switch state := api.StateType(*form.State); state {
|
||||||
|
case api.StateOpen:
|
||||||
|
isClosed = false
|
||||||
|
case api.StateClosed:
|
||||||
|
isClosed = true
|
||||||
|
default:
|
||||||
|
ctx.Error(http.StatusPreconditionFailed, "UnknownPRStateError", fmt.Sprintf("unknown state: %s", state))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if issue.IsClosed != isClosed {
|
||||||
|
if err := issue_service.ChangeStatus(ctx, issue, ctx.Doer, "", isClosed); err != nil {
|
||||||
if issues_model.IsErrDependenciesLeft(err) {
|
if issues_model.IsErrDependenciesLeft(err) {
|
||||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
|
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
|
||||||
return
|
return
|
||||||
|
@ -704,6 +717,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// change pull target branch
|
// change pull target branch
|
||||||
if !pr.HasMerged && len(form.Base) != 0 && form.Base != pr.BaseBranch {
|
if !pr.HasMerged && len(form.Base) != 0 && form.Base != pr.BaseBranch {
|
||||||
|
|
|
@ -13,6 +13,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ChangeStatus changes issue status to open or closed.
|
// ChangeStatus changes issue status to open or closed.
|
||||||
|
// closed means the target status
|
||||||
|
// Fix me: you should check whether the current issue status is same to the target status before call this function
|
||||||
|
// as in function changeIssueStatus we will return WasClosedError, even the issue status and target status are both open
|
||||||
func ChangeStatus(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, commitID string, closed bool) error {
|
func ChangeStatus(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, commitID string, closed bool) error {
|
||||||
comment, err := issues_model.ChangeIssueStatus(ctx, issue, doer, closed)
|
comment, err := issues_model.ChangeIssueStatus(ctx, issue, doer, closed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue