Move issue change status from models to service (#8691)
This commit is contained in:
parent
495d5e4329
commit
c66c9dabc7
6 changed files with 68 additions and 54 deletions
|
@ -254,7 +254,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
|||
notification.NotifyNewIssue(issue)
|
||||
|
||||
if form.Closed {
|
||||
if err := issue.ChangeStatus(ctx.User, true); err != nil {
|
||||
if err := issue_service.ChangeStatus(issue, ctx.User, true); err != nil {
|
||||
if models.IsErrDependenciesLeft(err) {
|
||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
|
||||
return
|
||||
|
@ -381,7 +381,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
|||
return
|
||||
}
|
||||
if form.State != nil {
|
||||
if err = issue.ChangeStatus(ctx.User, api.StateClosed == api.StateType(*form.State)); err != nil {
|
||||
if err = issue_service.ChangeStatus(issue, ctx.User, api.StateClosed == api.StateType(*form.State)); err != nil {
|
||||
if models.IsErrDependenciesLeft(err) {
|
||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
|
||||
return
|
||||
|
@ -389,8 +389,6 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
|||
ctx.Error(500, "ChangeStatus", err)
|
||||
return
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeStatus(ctx.User, issue, api.StateClosed == api.StateType(*form.State))
|
||||
}
|
||||
|
||||
// Refetch from database to assign some automatic values
|
||||
|
|
|
@ -448,7 +448,7 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
|
|||
return
|
||||
}
|
||||
if form.State != nil {
|
||||
if err = issue.ChangeStatus(ctx.User, api.StateClosed == api.StateType(*form.State)); err != nil {
|
||||
if err = issue_service.ChangeStatus(issue, ctx.User, api.StateClosed == api.StateType(*form.State)); err != nil {
|
||||
if models.IsErrDependenciesLeft(err) {
|
||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
|
||||
return
|
||||
|
@ -456,8 +456,6 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
|
|||
ctx.Error(500, "ChangeStatus", err)
|
||||
return
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeStatus(ctx.User, issue, api.StateClosed == api.StateType(*form.State))
|
||||
}
|
||||
|
||||
// Refetch from database
|
||||
|
|
|
@ -1185,7 +1185,7 @@ func UpdateIssueStatus(ctx *context.Context) {
|
|||
}
|
||||
for _, issue := range issues {
|
||||
if issue.IsClosed != isClosed {
|
||||
if err := issue.ChangeStatus(ctx.User, isClosed); err != nil {
|
||||
if err := issue_service.ChangeStatus(issue, ctx.User, isClosed); err != nil {
|
||||
if models.IsErrDependenciesLeft(err) {
|
||||
ctx.JSON(http.StatusPreconditionFailed, map[string]interface{}{
|
||||
"error": "cannot close this issue because it still has open dependencies",
|
||||
|
@ -1195,8 +1195,6 @@ func UpdateIssueStatus(ctx *context.Context) {
|
|||
ctx.ServerError("ChangeStatus", err)
|
||||
return
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeStatus(ctx.User, issue, isClosed)
|
||||
}
|
||||
}
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
|
@ -1286,7 +1284,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
|
|||
ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
|
||||
} else {
|
||||
isClosed := form.Status == "close"
|
||||
if err := issue.ChangeStatus(ctx.User, isClosed); err != nil {
|
||||
if err := issue_service.ChangeStatus(issue, ctx.User, isClosed); err != nil {
|
||||
log.Error("ChangeStatus: %v", err)
|
||||
|
||||
if models.IsErrDependenciesLeft(err) {
|
||||
|
@ -1300,15 +1298,12 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
|
|||
return
|
||||
}
|
||||
} else {
|
||||
|
||||
if err := stopTimerIfAvailable(ctx.User, issue); err != nil {
|
||||
ctx.ServerError("CreateOrStopIssueStopwatch", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
|
||||
|
||||
notification.NotifyIssueChangeStatus(ctx.User, issue, isClosed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue