mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 09:07:19 +00:00
Use CloseIssue
and ReopenIssue
instead of ChangeStatus
(#32467)
The behaviors of closing issues and reopening issues are very different. So splitting it into two different functions makes it easier to maintain. - [x] Split ChangeIssueStatus into CloseIssue and ReopenIssue both at the service layer and model layer - [x] Rename `isClosed` to `CloseOrReopen` to make it more readable. - [x] Add transactions for ReopenIssue and CloseIssue --------- Co-authored-by: Zettat123 <zettat123@gmail.com>
This commit is contained in:
@ -154,25 +154,28 @@ func NewComment(ctx *context.Context) {
|
||||
if pr != nil {
|
||||
ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
|
||||
} else {
|
||||
isClosed := form.Status == "close"
|
||||
if err := issue_service.ChangeStatus(ctx, issue, ctx.Doer, "", isClosed); err != nil {
|
||||
log.Error("ChangeStatus: %v", err)
|
||||
|
||||
if issues_model.IsErrDependenciesLeft(err) {
|
||||
if issue.IsPull {
|
||||
ctx.JSONError(ctx.Tr("repo.issues.dependency.pr_close_blocked"))
|
||||
} else {
|
||||
ctx.JSONError(ctx.Tr("repo.issues.dependency.issue_close_blocked"))
|
||||
if form.Status == "close" && !issue.IsClosed {
|
||||
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||
log.Error("CloseIssue: %v", err)
|
||||
if issues_model.IsErrDependenciesLeft(err) {
|
||||
if issue.IsPull {
|
||||
ctx.JSONError(ctx.Tr("repo.issues.dependency.pr_close_blocked"))
|
||||
} else {
|
||||
ctx.JSONError(ctx.Tr("repo.issues.dependency.issue_close_blocked"))
|
||||
}
|
||||
return
|
||||
}
|
||||
return
|
||||
} else {
|
||||
if err := stopTimerIfAvailable(ctx, ctx.Doer, issue); err != nil {
|
||||
ctx.ServerError("stopTimerIfAvailable", err)
|
||||
return
|
||||
}
|
||||
log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
|
||||
}
|
||||
} else {
|
||||
if err := stopTimerIfAvailable(ctx, ctx.Doer, issue); err != nil {
|
||||
ctx.ServerError("CreateOrStopIssueStopwatch", err)
|
||||
return
|
||||
} else if form.Status == "reopen" && issue.IsClosed {
|
||||
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||
log.Error("ReopenIssue: %v", err)
|
||||
}
|
||||
|
||||
log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -418,14 +418,11 @@ func UpdateIssueStatus(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var isClosed bool
|
||||
switch action := ctx.FormString("action"); action {
|
||||
case "open":
|
||||
isClosed = false
|
||||
case "close":
|
||||
isClosed = true
|
||||
default:
|
||||
action := ctx.FormString("action")
|
||||
if action != "open" && action != "close" {
|
||||
log.Warn("Unrecognized action: %s", action)
|
||||
ctx.JSONOK()
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := issues.LoadRepositories(ctx); err != nil {
|
||||
@ -441,15 +438,20 @@ func UpdateIssueStatus(ctx *context.Context) {
|
||||
if issue.IsPull && issue.PullRequest.HasMerged {
|
||||
continue
|
||||
}
|
||||
if issue.IsClosed != isClosed {
|
||||
if err := issue_service.ChangeStatus(ctx, issue, ctx.Doer, "", isClosed); err != nil {
|
||||
if action == "close" && !issue.IsClosed {
|
||||
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||
if issues_model.IsErrDependenciesLeft(err) {
|
||||
ctx.JSON(http.StatusPreconditionFailed, map[string]any{
|
||||
"error": ctx.Tr("repo.issues.dependency.issue_batch_close_blocked", issue.Index),
|
||||
})
|
||||
return
|
||||
}
|
||||
ctx.ServerError("ChangeStatus", err)
|
||||
ctx.ServerError("CloseIssue", err)
|
||||
return
|
||||
}
|
||||
} else if action == "open" && issue.IsClosed {
|
||||
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||
ctx.ServerError("ReopenIssue", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user