diff --git a/internal/app/pull_review.go b/internal/app/pull_review.go index 7ce6049e..d9bcb4b2 100644 --- a/internal/app/pull_review.go +++ b/internal/app/pull_review.go @@ -218,7 +218,19 @@ func (a *application) reviewCreateCommand(use, short string) *cobra.Command { if body = draft.Body; needsBody && strings.TrimSpace(body) == "" { return missingBody } - item, err := (services.Reviews{Client: t.client, Repository: t.Repo}).Create(cmd.Context(), n, services.ReviewOptions{Event: state, Body: body, Commit: commit, Comments: comments}) + service := services.Reviews{Client: t.client, Repository: t.Repo} + if strings.TrimSpace(body) == "" && !explicit && !useEditor { + // Gitea adds a new review to the caller's oldest pending review and replaces its body, + // so keep the pending body when none was given, as tea pr review submit does. + pending, err := service.Pending(cmd.Context(), n, t.login()) + if err != nil { + return err + } + if len(pending) > 0 { + body = pending[0].Body + } + } + item, err := service.Create(cmd.Context(), n, services.ReviewOptions{Event: state, Body: body, Commit: commit, Comments: comments}) if err != nil { return err } diff --git a/internal/app/pull_review_test.go b/internal/app/pull_review_test.go index 9375cf95..03728135 100644 --- a/internal/app/pull_review_test.go +++ b/internal/app/pull_review_test.go @@ -94,6 +94,10 @@ func TestReviewTypeFlags(t *testing.T) { t.Run(strings.Join(tc.args, " "), func(t *testing.T) { var payload map[string]any server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodGet && r.URL.Path == "/api/v1/repos/alice/x/pulls/13/reviews" { + _, _ = w.Write([]byte(`[]`)) + return + } if r.Method == http.MethodGet { require.Equal(t, "/api/v1/repos/alice/x/pulls/13", r.URL.Path) _, _ = w.Write([]byte(pullJSON("bob"))) @@ -119,6 +123,10 @@ func TestReviewTypeFlags(t *testing.T) { func TestReviewCreateIsTheReviewCommand(t *testing.T) { var event any server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodGet && r.URL.Path == "/api/v1/repos/alice/x/pulls/13/reviews" { + _, _ = w.Write([]byte(`[]`)) + return + } if r.Method == http.MethodGet { _, _ = w.Write([]byte(pullJSON("bob"))) return