mirror of
https://github.com/go-gitea/gitea
synced 2025-01-10 01:34:43 +00:00
improve
This commit is contained in:
parent
e26a30105f
commit
6e787dfcf8
@ -912,32 +912,11 @@ func EditIssue(ctx *context.APIContext) {
|
||||
}
|
||||
}
|
||||
|
||||
var closeOrReopen bool
|
||||
switch state := api.StateType(*form.State); state {
|
||||
case api.StateOpen:
|
||||
closeOrReopen = false
|
||||
case api.StateClosed:
|
||||
closeOrReopen = true
|
||||
default:
|
||||
ctx.Error(http.StatusPreconditionFailed, "UnknownIssueStateError", fmt.Sprintf("unknown state: %s", state))
|
||||
state := api.StateType(*form.State)
|
||||
closeOrReopenIssue(ctx, issue, state)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if closeOrReopen && !issue.IsClosed {
|
||||
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||
if issues_model.IsErrDependenciesLeft(err) {
|
||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
|
||||
return
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, "CloseIssue", err)
|
||||
return
|
||||
}
|
||||
} else if !closeOrReopen && issue.IsClosed {
|
||||
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ReopenIssue", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Refetch from database to assign some automatic values
|
||||
@ -1060,3 +1039,26 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
|
||||
|
||||
ctx.JSON(http.StatusCreated, api.IssueDeadline{Deadline: deadlineUnix.AsTimePtr()})
|
||||
}
|
||||
|
||||
func closeOrReopenIssue(ctx *context.APIContext, issue *issues_model.Issue, state api.StateType) {
|
||||
if state != api.StateOpen && state != api.StateClosed {
|
||||
ctx.Error(http.StatusPreconditionFailed, "UnknownIssueStateError", fmt.Sprintf("unknown state: %s", state))
|
||||
return
|
||||
}
|
||||
|
||||
if state == api.StateClosed && !issue.IsClosed {
|
||||
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||
if issues_model.IsErrDependenciesLeft(err) {
|
||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue or pull request because it still has open dependencies")
|
||||
return
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, "CloseIssue", err)
|
||||
return
|
||||
}
|
||||
} else if state == api.StateOpen && issue.IsClosed {
|
||||
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ReopenIssue", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -753,32 +753,11 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
var closeOrReopen bool
|
||||
switch state := api.StateType(*form.State); state {
|
||||
case api.StateOpen:
|
||||
closeOrReopen = false
|
||||
case api.StateClosed:
|
||||
closeOrReopen = true
|
||||
default:
|
||||
ctx.Error(http.StatusPreconditionFailed, "UnknownPRStateError", fmt.Sprintf("unknown state: %s", state))
|
||||
state := api.StateType(*form.State)
|
||||
closeOrReopenIssue(ctx, issue, state)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if closeOrReopen && !issue.IsClosed {
|
||||
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||
if issues_model.IsErrDependenciesLeft(err) {
|
||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
|
||||
return
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, "CloseIssue", err)
|
||||
return
|
||||
}
|
||||
} else if !closeOrReopen && issue.IsClosed {
|
||||
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ReopenIssue", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// change pull target branch
|
||||
|
@ -154,8 +154,7 @@ func NewComment(ctx *context.Context) {
|
||||
if pr != nil {
|
||||
ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
|
||||
} else {
|
||||
closeOrReopen := form.Status == "close"
|
||||
if closeOrReopen && !issue.IsClosed {
|
||||
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) {
|
||||
@ -173,7 +172,7 @@ func NewComment(ctx *context.Context) {
|
||||
}
|
||||
log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
|
||||
}
|
||||
} else if !closeOrReopen && issue.IsClosed {
|
||||
} else if form.Status == "reopen" && issue.IsClosed {
|
||||
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||
log.Error("ReopenIssue: %v", err)
|
||||
}
|
||||
|
@ -435,13 +435,8 @@ func UpdateIssueStatus(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var closeOrReopen bool // true: close, false: reopen
|
||||
switch action := ctx.FormString("action"); action {
|
||||
case "open":
|
||||
closeOrReopen = false
|
||||
case "close":
|
||||
closeOrReopen = true
|
||||
default:
|
||||
action := ctx.FormString("action")
|
||||
if action != "open" && action != "close" {
|
||||
log.Warn("Unrecognized action: %s", action)
|
||||
ctx.JSONOK()
|
||||
return
|
||||
@ -460,7 +455,7 @@ func UpdateIssueStatus(ctx *context.Context) {
|
||||
if issue.IsPull && issue.PullRequest.HasMerged {
|
||||
continue
|
||||
}
|
||||
if closeOrReopen && !issue.IsClosed {
|
||||
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{
|
||||
@ -471,7 +466,7 @@ func UpdateIssueStatus(ctx *context.Context) {
|
||||
ctx.ServerError("CloseIssue", err)
|
||||
return
|
||||
}
|
||||
} else if !closeOrReopen && issue.IsClosed {
|
||||
} else if action == "open" && issue.IsClosed {
|
||||
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||
ctx.ServerError("ReopenIssue", err)
|
||||
return
|
||||
|
@ -189,9 +189,8 @@ func UpdateIssuesCommit(ctx context.Context, doer *user_model.User, repo *repo_m
|
||||
}
|
||||
}
|
||||
|
||||
closeOrReopen := ref.Action == references.XRefActionCloses
|
||||
refIssue.Repo = refRepo
|
||||
if closeOrReopen && !refIssue.IsClosed {
|
||||
if ref.Action == references.XRefActionCloses && !refIssue.IsClosed {
|
||||
if len(ref.TimeLog) > 0 {
|
||||
if err := issueAddTime(ctx, refIssue, doer, c.Timestamp, ref.TimeLog); err != nil {
|
||||
return err
|
||||
@ -200,7 +199,7 @@ func UpdateIssuesCommit(ctx context.Context, doer *user_model.User, repo *repo_m
|
||||
if err := CloseIssue(ctx, refIssue, doer, c.Sha1); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if !closeOrReopen && refIssue.IsClosed {
|
||||
} else if ref.Action == references.XRefActionReopens && refIssue.IsClosed {
|
||||
if err := ReopenIssue(ctx, refIssue, doer, c.Sha1); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -242,15 +242,14 @@ func handleCloseCrossReferences(ctx context.Context, pr *issues_model.PullReques
|
||||
if err = ref.Issue.LoadRepo(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
closeOrReopen := ref.RefAction == references.XRefActionCloses
|
||||
if closeOrReopen && !ref.Issue.IsClosed {
|
||||
if ref.RefAction == references.XRefActionCloses && !ref.Issue.IsClosed {
|
||||
if err = issue_service.CloseIssue(ctx, ref.Issue, doer, pr.MergedCommitID); err != nil {
|
||||
// Allow ErrDependenciesLeft
|
||||
if !issues_model.IsErrDependenciesLeft(err) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else if !closeOrReopen && ref.Issue.IsClosed {
|
||||
} else if ref.RefAction == references.XRefActionReopens && ref.Issue.IsClosed {
|
||||
if err = issue_service.ReopenIssue(ctx, ref.Issue, doer, pr.MergedCommitID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user