mirror of
https://github.com/go-gitea/gitea
synced 2025-01-10 09:44: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
|
state := api.StateType(*form.State)
|
||||||
switch state := api.StateType(*form.State); state {
|
closeOrReopenIssue(ctx, issue, state)
|
||||||
case api.StateOpen:
|
if ctx.Written() {
|
||||||
closeOrReopen = false
|
|
||||||
case api.StateClosed:
|
|
||||||
closeOrReopen = true
|
|
||||||
default:
|
|
||||||
ctx.Error(http.StatusPreconditionFailed, "UnknownIssueStateError", fmt.Sprintf("unknown state: %s", state))
|
|
||||||
return
|
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
|
// 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()})
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var closeOrReopen bool
|
state := api.StateType(*form.State)
|
||||||
switch state := api.StateType(*form.State); state {
|
closeOrReopenIssue(ctx, issue, state)
|
||||||
case api.StateOpen:
|
if ctx.Written() {
|
||||||
closeOrReopen = false
|
|
||||||
case api.StateClosed:
|
|
||||||
closeOrReopen = true
|
|
||||||
default:
|
|
||||||
ctx.Error(http.StatusPreconditionFailed, "UnknownPRStateError", fmt.Sprintf("unknown state: %s", state))
|
|
||||||
return
|
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
|
// change pull target branch
|
||||||
|
@ -154,8 +154,7 @@ func NewComment(ctx *context.Context) {
|
|||||||
if pr != nil {
|
if pr != nil {
|
||||||
ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
|
ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
|
||||||
} else {
|
} else {
|
||||||
closeOrReopen := form.Status == "close"
|
if form.Status == "close" && !issue.IsClosed {
|
||||||
if closeOrReopen && !issue.IsClosed {
|
|
||||||
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||||
log.Error("CloseIssue: %v", err)
|
log.Error("CloseIssue: %v", err)
|
||||||
if issues_model.IsErrDependenciesLeft(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)
|
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 {
|
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||||
log.Error("ReopenIssue: %v", err)
|
log.Error("ReopenIssue: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -435,13 +435,8 @@ func UpdateIssueStatus(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var closeOrReopen bool // true: close, false: reopen
|
action := ctx.FormString("action")
|
||||||
switch action := ctx.FormString("action"); action {
|
if action != "open" && action != "close" {
|
||||||
case "open":
|
|
||||||
closeOrReopen = false
|
|
||||||
case "close":
|
|
||||||
closeOrReopen = true
|
|
||||||
default:
|
|
||||||
log.Warn("Unrecognized action: %s", action)
|
log.Warn("Unrecognized action: %s", action)
|
||||||
ctx.JSONOK()
|
ctx.JSONOK()
|
||||||
return
|
return
|
||||||
@ -460,7 +455,7 @@ func UpdateIssueStatus(ctx *context.Context) {
|
|||||||
if issue.IsPull && issue.PullRequest.HasMerged {
|
if issue.IsPull && issue.PullRequest.HasMerged {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if closeOrReopen && !issue.IsClosed {
|
if action == "close" && !issue.IsClosed {
|
||||||
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||||
if issues_model.IsErrDependenciesLeft(err) {
|
if issues_model.IsErrDependenciesLeft(err) {
|
||||||
ctx.JSON(http.StatusPreconditionFailed, map[string]any{
|
ctx.JSON(http.StatusPreconditionFailed, map[string]any{
|
||||||
@ -471,7 +466,7 @@ func UpdateIssueStatus(ctx *context.Context) {
|
|||||||
ctx.ServerError("CloseIssue", err)
|
ctx.ServerError("CloseIssue", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if !closeOrReopen && issue.IsClosed {
|
} else if action == "open" && issue.IsClosed {
|
||||||
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||||
ctx.ServerError("ReopenIssue", err)
|
ctx.ServerError("ReopenIssue", err)
|
||||||
return
|
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
|
refIssue.Repo = refRepo
|
||||||
if closeOrReopen && !refIssue.IsClosed {
|
if ref.Action == references.XRefActionCloses && !refIssue.IsClosed {
|
||||||
if len(ref.TimeLog) > 0 {
|
if len(ref.TimeLog) > 0 {
|
||||||
if err := issueAddTime(ctx, refIssue, doer, c.Timestamp, ref.TimeLog); err != nil {
|
if err := issueAddTime(ctx, refIssue, doer, c.Timestamp, ref.TimeLog); err != nil {
|
||||||
return err
|
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 {
|
if err := CloseIssue(ctx, refIssue, doer, c.Sha1); err != nil {
|
||||||
return err
|
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 {
|
if err := ReopenIssue(ctx, refIssue, doer, c.Sha1); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -242,15 +242,14 @@ func handleCloseCrossReferences(ctx context.Context, pr *issues_model.PullReques
|
|||||||
if err = ref.Issue.LoadRepo(ctx); err != nil {
|
if err = ref.Issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
closeOrReopen := ref.RefAction == references.XRefActionCloses
|
if ref.RefAction == references.XRefActionCloses && !ref.Issue.IsClosed {
|
||||||
if closeOrReopen && !ref.Issue.IsClosed {
|
|
||||||
if err = issue_service.CloseIssue(ctx, ref.Issue, doer, pr.MergedCommitID); err != nil {
|
if err = issue_service.CloseIssue(ctx, ref.Issue, doer, pr.MergedCommitID); err != nil {
|
||||||
// Allow ErrDependenciesLeft
|
// Allow ErrDependenciesLeft
|
||||||
if !issues_model.IsErrDependenciesLeft(err) {
|
if !issues_model.IsErrDependenciesLeft(err) {
|
||||||
return 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 {
|
if err = issue_service.ReopenIssue(ctx, ref.Issue, doer, pr.MergedCommitID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user