summaryrefslogtreecommitdiffstats
path: root/routers/api/v1
diff options
context:
space:
mode:
authorGiteabot <teabot@gitea.io>2024-05-03 22:43:16 +0800
committerGitHub <noreply@github.com>2024-05-03 14:43:16 +0000
commita82e6301f77d3dce95e7945a05429e3d594bd246 (patch)
treeeabfb11273f16ae9c20fd9b61295a98d59502529 /routers/api/v1
parent1f9a9fab5fbd48a634918f64bb579ae05405ff56 (diff)
downloadgitea-a82e6301f77d3dce95e7945a05429e3d594bd246.tar.gz
gitea-a82e6301f77d3dce95e7945a05429e3d594bd246.zip
Fix no edit history after editing issue's title and content (#30814) (#30845)
Backport #30814 by @yp05327 Fix #30807 reuse functions in services Co-authored-by: yp05327 <576951401@qq.com>
Diffstat (limited to 'routers/api/v1')
-rw-r--r--routers/api/v1/repo/issue.go36
-rw-r--r--routers/api/v1/repo/pull.go37
2 files changed, 33 insertions, 40 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
index dfe6d31f74..b91fbc33bf 100644
--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -29,7 +29,6 @@ import (
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/convert"
issue_service "code.gitea.io/gitea/services/issue"
- notify_service "code.gitea.io/gitea/services/notify"
)
// SearchIssues searches for issues across the repositories that the user has access to
@@ -803,12 +802,19 @@ func EditIssue(ctx *context.APIContext) {
return
}
- oldTitle := issue.Title
if len(form.Title) > 0 {
- issue.Title = form.Title
+ err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title)
+ if err != nil {
+ ctx.Error(http.StatusInternalServerError, "ChangeTitle", err)
+ return
+ }
}
if form.Body != nil {
- issue.Content = *form.Body
+ err = issue_service.ChangeContent(ctx, issue, ctx.Doer, *form.Body)
+ if err != nil {
+ ctx.Error(http.StatusInternalServerError, "ChangeContent", err)
+ return
+ }
}
if form.Ref != nil {
err = issue_service.ChangeIssueRef(ctx, issue, ctx.Doer, *form.Ref)
@@ -880,24 +886,14 @@ func EditIssue(ctx *context.APIContext) {
return
}
}
- issue.IsClosed = api.StateClosed == api.StateType(*form.State)
- }
- statusChangeComment, titleChanged, err := issues_model.UpdateIssueByAPI(ctx, issue, ctx.Doer)
- if err != nil {
- if issues_model.IsErrDependenciesLeft(err) {
- ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
+ if err := issue_service.ChangeStatus(ctx, issue, ctx.Doer, "", api.StateClosed == api.StateType(*form.State)); 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, "ChangeStatus", err)
return
}
- ctx.Error(http.StatusInternalServerError, "UpdateIssueByAPI", err)
- return
- }
-
- if titleChanged {
- notify_service.IssueChangeTitle(ctx, ctx.Doer, issue, oldTitle)
- }
-
- if statusChangeComment != nil {
- notify_service.IssueChangeStatus(ctx, ctx.Doer, "", issue, statusChangeComment, issue.IsClosed)
}
// Refetch from database to assign some automatic values
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 4129f94ac3..8bd4ddf64b 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -602,12 +602,19 @@ func EditPullRequest(ctx *context.APIContext) {
return
}
- oldTitle := issue.Title
if len(form.Title) > 0 {
- issue.Title = form.Title
+ err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title)
+ if err != nil {
+ ctx.Error(http.StatusInternalServerError, "ChangeTitle", err)
+ return
+ }
}
- if len(form.Body) > 0 {
- issue.Content = form.Body
+ if form.Body != nil {
+ err = issue_service.ChangeContent(ctx, issue, ctx.Doer, *form.Body)
+ if err != nil {
+ ctx.Error(http.StatusInternalServerError, "ChangeContent", err)
+ return
+ }
}
// Update or remove deadline if set
@@ -686,24 +693,14 @@ func EditPullRequest(ctx *context.APIContext) {
ctx.Error(http.StatusPreconditionFailed, "MergedPRState", "cannot change state of this pull request, it was already merged")
return
}
- issue.IsClosed = api.StateClosed == api.StateType(*form.State)
- }
- statusChangeComment, titleChanged, err := issues_model.UpdateIssueByAPI(ctx, issue, ctx.Doer)
- if err != nil {
- if issues_model.IsErrDependenciesLeft(err) {
- ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
+ if err := issue_service.ChangeStatus(ctx, issue, ctx.Doer, "", api.StateClosed == api.StateType(*form.State)); 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, "ChangeStatus", err)
return
}
- ctx.Error(http.StatusInternalServerError, "UpdateIssueByAPI", err)
- return
- }
-
- if titleChanged {
- notify_service.IssueChangeTitle(ctx, ctx.Doer, issue, oldTitle)
- }
-
- if statusChangeComment != nil {
- notify_service.IssueChangeStatus(ctx, ctx.Doer, "", issue, statusChangeComment, issue.IsClosed)
}
// change pull target branch