Skip to content

Commit fb82908

Browse files
committed
fix
1 parent 4a6a260 commit fb82908

File tree

3 files changed

+14
-73
lines changed

3 files changed

+14
-73
lines changed

models/issues/issue_update.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -429,45 +429,6 @@ func UpdateIssueMentions(ctx context.Context, issueID int64, mentions []*user_mo
429429
return nil
430430
}
431431

432-
// UpdateIssueByAPI updates all allowed fields of given issue.
433-
// If the issue status is changed a statusChangeComment is returned
434-
// similarly if the title is changed the titleChanged bool is set to true
435-
func UpdateIssueByAPI(ctx context.Context, issue *Issue, doer *user_model.User) (statusChangeComment *Comment, err error) {
436-
ctx, committer, err := db.TxContext(ctx)
437-
if err != nil {
438-
return nil, err
439-
}
440-
defer committer.Close()
441-
442-
if err := issue.LoadRepo(ctx); err != nil {
443-
return nil, fmt.Errorf("loadRepo: %w", err)
444-
}
445-
446-
// Reload the issue
447-
currentIssue, err := GetIssueByID(ctx, issue.ID)
448-
if err != nil {
449-
return nil, err
450-
}
451-
452-
if _, err := db.GetEngine(ctx).ID(issue.ID).
453-
Cols("milestone_id", "priority", "deadline_unix", "updated_unix", "is_locked").
454-
Update(issue); err != nil {
455-
return nil, err
456-
}
457-
458-
if currentIssue.IsClosed != issue.IsClosed {
459-
statusChangeComment, err = doChangeIssueStatus(ctx, issue, doer, false)
460-
if err != nil {
461-
return nil, err
462-
}
463-
}
464-
465-
if err := issue.AddCrossReferences(ctx, doer, true); err != nil {
466-
return nil, err
467-
}
468-
return statusChangeComment, committer.Commit()
469-
}
470-
471432
// UpdateIssueDeadline updates an issue deadline and adds comments. Setting a deadline to 0 means deleting it.
472433
func UpdateIssueDeadline(ctx context.Context, issue *Issue, deadlineUnix timeutil.TimeStamp, doer *user_model.User) (err error) {
473434
// if the deadline hasn't changed do nothing

routers/api/v1/repo/issue.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"code.gitea.io/gitea/services/context"
3030
"code.gitea.io/gitea/services/convert"
3131
issue_service "code.gitea.io/gitea/services/issue"
32-
notify_service "code.gitea.io/gitea/services/notify"
3332
)
3433

3534
// SearchIssues searches for issues across the repositories that the user has access to
@@ -887,20 +886,14 @@ func EditIssue(ctx *context.APIContext) {
887886
return
888887
}
889888
}
890-
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
891-
}
892-
statusChangeComment, err := issues_model.UpdateIssueByAPI(ctx, issue, ctx.Doer)
893-
if err != nil {
894-
if issues_model.IsErrDependenciesLeft(err) {
895-
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
889+
if err := issue_service.ChangeStatus(ctx, issue, ctx.Doer, "", api.StateClosed == api.StateType(*form.State)); err != nil {
890+
if issues_model.IsErrDependenciesLeft(err) {
891+
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
892+
return
893+
}
894+
ctx.Error(http.StatusInternalServerError, "ChangeStatus", err)
896895
return
897896
}
898-
ctx.Error(http.StatusInternalServerError, "UpdateIssueByAPI", err)
899-
return
900-
}
901-
902-
if statusChangeComment != nil {
903-
notify_service.IssueChangeStatus(ctx, ctx.Doer, "", issue, statusChangeComment, issue.IsClosed)
904897
}
905898

906899
// Refetch from database to assign some automatic values

routers/api/v1/repo/pull.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -603,18 +603,10 @@ func EditPullRequest(ctx *context.APIContext) {
603603
}
604604

605605
if len(form.Title) > 0 {
606-
err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title)
607-
if err != nil {
608-
ctx.Error(http.StatusInternalServerError, "ChangeTitle", err)
609-
return
610-
}
606+
issue.Title = form.Title
611607
}
612608
if form.Body != nil {
613-
err = issue_service.ChangeContent(ctx, issue, ctx.Doer, *form.Body)
614-
if err != nil {
615-
ctx.Error(http.StatusInternalServerError, "ChangeContent", err)
616-
return
617-
}
609+
issue.Content = *form.Body
618610
}
619611

620612
// Update or remove deadline if set
@@ -693,19 +685,14 @@ func EditPullRequest(ctx *context.APIContext) {
693685
ctx.Error(http.StatusPreconditionFailed, "MergedPRState", "cannot change state of this pull request, it was already merged")
694686
return
695687
}
696-
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
697-
}
698-
statusChangeComment, err := issues_model.UpdateIssueByAPI(ctx, issue, ctx.Doer)
699-
if err != nil {
700-
if issues_model.IsErrDependenciesLeft(err) {
701-
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
688+
if err := issue_service.ChangeStatus(ctx, issue, ctx.Doer, "", api.StateClosed == api.StateType(*form.State)); err != nil {
689+
if issues_model.IsErrDependenciesLeft(err) {
690+
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
691+
return
692+
}
693+
ctx.Error(http.StatusInternalServerError, "ChangeStatus", err)
702694
return
703695
}
704-
ctx.Error(http.StatusInternalServerError, "UpdateIssueByAPI", err)
705-
return
706-
}
707-
if statusChangeComment != nil {
708-
notify_service.IssueChangeStatus(ctx, ctx.Doer, "", issue, statusChangeComment, issue.IsClosed)
709696
}
710697

711698
// change pull target branch

0 commit comments

Comments
 (0)