@@ -179,6 +179,12 @@ func ApplySuggestion(ctx *context.Context) {
179179 return
180180 }
181181
182+ if pr .Flow == issues_model .PullRequestFlowAGit {
183+ // TODO: Support suggestions for AGit flow pull requests
184+ ctx .JSON (http .StatusBadRequest , map [string ]any {"ok" : false , "message" : ctx .Locale .Tr ("repo.diff.comment.apply_suggestion_failed" )})
185+ return
186+ }
187+
182188 canWriteToHeadRepo := false
183189 if ctx .IsSigned {
184190 permHead , err := access_model .GetUserRepoPermission (ctx , pr .HeadRepo , ctx .Doer )
@@ -189,7 +195,7 @@ func ApplySuggestion(ctx *context.Context) {
189195 if permHead .CanWrite (unit_model .TypeCode ) {
190196 canWriteToHeadRepo = true
191197 }
192- if ! canWriteToHeadRepo {
198+ if ! canWriteToHeadRepo && pr . AllowMaintainerEdit {
193199 if err := pr .LoadBaseRepo (ctx ); err != nil {
194200 ctx .ServerError ("LoadBaseRepo" , err )
195201 return
@@ -199,7 +205,7 @@ func ApplySuggestion(ctx *context.Context) {
199205 ctx .ServerError ("GetUserRepoPermission" , err )
200206 return
201207 }
202- if pr . AllowMaintainerEdit && permBase .CanWrite (unit_model .TypeCode ) {
208+ if permBase .CanWrite (unit_model .TypeCode ) {
203209 canWriteToHeadRepo = true
204210 }
205211 }
@@ -263,11 +269,22 @@ func ApplySuggestion(ctx *context.Context) {
263269 return
264270 }
265271
272+ if err := comment .LoadPoster (ctx ); err != nil {
273+ ctx .ServerError ("comment.LoadPoster" , err )
274+ return
275+ }
276+
277+ commitMessage := fmt .Sprintf ("Apply suggestion to %s\n \n Co-authored-by: %s <%s>" ,
278+ comment .TreePath ,
279+ comment .Poster .Name ,
280+ comment .Poster .GetEmail (),
281+ )
282+
266283 _ , err = files_service .ApplyDiffPatch (ctx , pr .HeadRepo , ctx .Doer , & files_service.ApplyDiffPatchOptions {
267284 LastCommitID : headCommit .ID .String (),
268285 OldBranch : pr .HeadBranch ,
269286 NewBranch : pr .HeadBranch ,
270- Message : "Apply suggestion to " + comment . TreePath ,
287+ Message : commitMessage ,
271288 Content : patch ,
272289 })
273290 if err != nil {
0 commit comments