@@ -37,7 +37,6 @@ import (
3737 "code.gitea.io/gitea/modules/upload"
3838 "code.gitea.io/gitea/modules/util"
3939 "code.gitea.io/gitea/modules/web"
40- "code.gitea.io/gitea/modules/web/middleware"
4140 "code.gitea.io/gitea/routers/utils"
4241 asymkey_service "code.gitea.io/gitea/services/asymkey"
4342 "code.gitea.io/gitea/services/automerge"
@@ -1206,36 +1205,12 @@ func CompareAndPullRequestPost(ctx *context.Context) {
12061205 }
12071206
12081207 if ctx .HasError () {
1209- middleware .AssignForm (form , ctx .Data )
1210-
1211- // This stage is already stop creating new pull request, so it does not matter if it has
1212- // something to compare or not.
1213- PrepareCompareDiff (ctx , ci ,
1214- gitdiff .GetWhitespaceFlag (ctx .Data ["WhitespaceBehavior" ].(string )))
1215- if ctx .Written () {
1216- return
1217- }
1218-
1219- if len (form .Title ) > 255 {
1220- var trailer string
1221- form .Title , trailer = util .SplitStringAtByteN (form .Title , 255 )
1222-
1223- form .Content = trailer + "\n \n " + form .Content
1224- }
1225- middleware .AssignForm (form , ctx .Data )
1226-
1227- ctx .HTML (http .StatusOK , tplCompareDiff )
1208+ ctx .JSONError (ctx .GetErrMsg ())
12281209 return
12291210 }
12301211
12311212 if util .IsEmptyString (form .Title ) {
1232- PrepareCompareDiff (ctx , ci ,
1233- gitdiff .GetWhitespaceFlag (ctx .Data ["WhitespaceBehavior" ].(string )))
1234- if ctx .Written () {
1235- return
1236- }
1237-
1238- ctx .RenderWithErr (ctx .Tr ("repo.issues.new.title_empty" ), tplCompareDiff , form )
1213+ ctx .JSONError (ctx .Tr ("repo.issues.new.title_empty" ))
12391214 return
12401215 }
12411216
@@ -1278,28 +1253,28 @@ func CompareAndPullRequestPost(ctx *context.Context) {
12781253 pushrejErr := err .(* git.ErrPushRejected )
12791254 message := pushrejErr .Message
12801255 if len (message ) == 0 {
1281- ctx .Flash .Error (ctx .Tr ("repo.pulls.push_rejected_no_message" ))
1282- } else {
1283- flashError , err := ctx .RenderToString (tplAlertDetails , map [string ]interface {}{
1284- "Message" : ctx .Tr ("repo.pulls.push_rejected" ),
1285- "Summary" : ctx .Tr ("repo.pulls.push_rejected_summary" ),
1286- "Details" : utils .SanitizeFlashErrorString (pushrejErr .Message ),
1287- })
1288- if err != nil {
1289- ctx .ServerError ("CompareAndPullRequest.HTMLString" , err )
1290- return
1291- }
1292- ctx .Flash .Error (flashError )
1256+ ctx .JSONError (ctx .Tr ("repo.pulls.push_rejected_no_message" ))
1257+ return
12931258 }
1294- ctx .Redirect (pullIssue .Link ())
1259+ flashError , err := ctx .RenderToString (tplAlertDetails , map [string ]interface {}{
1260+ "Message" : ctx .Tr ("repo.pulls.push_rejected" ),
1261+ "Summary" : ctx .Tr ("repo.pulls.push_rejected_summary" ),
1262+ "Details" : utils .SanitizeFlashErrorString (pushrejErr .Message ),
1263+ })
1264+ if err != nil {
1265+ ctx .ServerError ("CompareAndPullRequest.HTMLString" , err )
1266+ return
1267+ }
1268+ ctx .Flash .Error (flashError )
1269+ ctx .JSONRedirect (pullIssue .Link ()) // FIXME: it's unfriendly, and will make the content lost
12951270 return
12961271 }
12971272 ctx .ServerError ("NewPullRequest" , err )
12981273 return
12991274 }
13001275
13011276 log .Trace ("Pull request created: %d/%d" , repo .ID , pullIssue .ID )
1302- ctx .Redirect (pullIssue .Link ())
1277+ ctx .JSONRedirect (pullIssue .Link ())
13031278}
13041279
13051280// CleanUpPullRequest responses for delete merged branch when PR has been merged
0 commit comments