@@ -28,7 +28,6 @@ import (
28
28
"code.gitea.io/gitea/modules/gitrepo"
29
29
"code.gitea.io/gitea/modules/globallock"
30
30
"code.gitea.io/gitea/modules/graceful"
31
- "code.gitea.io/gitea/modules/json"
32
31
"code.gitea.io/gitea/modules/log"
33
32
repo_module "code.gitea.io/gitea/modules/repository"
34
33
"code.gitea.io/gitea/modules/setting"
@@ -141,36 +140,7 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
141
140
return err
142
141
}
143
142
144
- compareInfo , err := GetCompareInfo (ctx , pr .BaseRepo , pr .BaseRepo , baseGitRepo ,
145
- git .BranchPrefix + pr .BaseBranch , pr .GetGitHeadRefName (), false , false )
146
- if err != nil {
147
- return err
148
- }
149
- if len (compareInfo .Commits ) == 0 {
150
- return nil
151
- }
152
-
153
- data := issues_model.PushActionContent {IsForcePush : false }
154
- data .CommitIDs = make ([]string , 0 , len (compareInfo .Commits ))
155
- for i := len (compareInfo .Commits ) - 1 ; i >= 0 ; i -- {
156
- data .CommitIDs = append (data .CommitIDs , compareInfo .Commits [i ].ID .String ())
157
- }
158
-
159
- dataJSON , err := json .Marshal (data )
160
- if err != nil {
161
- return err
162
- }
163
-
164
- ops := & issues_model.CreateCommentOptions {
165
- Type : issues_model .CommentTypePullRequestPush ,
166
- Doer : issue .Poster ,
167
- Repo : repo ,
168
- Issue : pr .Issue ,
169
- IsForcePush : false ,
170
- Content : string (dataJSON ),
171
- }
172
-
173
- if _ , err = issues_model .CreateComment (ctx , ops ); err != nil {
143
+ if _ , err := CreatePushPullComment (ctx , issue .Poster , pr , git .BranchPrefix + pr .BaseBranch , pr .GetGitHeadRefName (), false ); err != nil {
174
144
return err
175
145
}
176
146
@@ -331,24 +301,42 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer
331
301
pr .CommitsAhead = divergence .Ahead
332
302
pr .CommitsBehind = divergence .Behind
333
303
334
- if err := pr .UpdateColsIfNotMerged (ctx , "merge_base" , "status" , "conflicted_files" , "changed_protected_files" , "base_branch" , "commits_ahead" , "commits_behind" ); err != nil {
304
+ // add first push codes comment
305
+ baseGitRepo , err := gitrepo .OpenRepository (ctx , pr .BaseRepo )
306
+ if err != nil {
335
307
return err
336
308
}
309
+ defer baseGitRepo .Close ()
337
310
338
- // Create comment
339
- options := & issues_model.CreateCommentOptions {
340
- Type : issues_model .CommentTypeChangeTargetBranch ,
341
- Doer : doer ,
342
- Repo : pr .Issue .Repo ,
343
- Issue : pr .Issue ,
344
- OldRef : oldBranch ,
345
- NewRef : targetBranch ,
346
- }
347
- if _ , err = issues_model .CreateComment (ctx , options ); err != nil {
348
- return fmt .Errorf ("CreateChangeTargetBranchComment: %w" , err )
349
- }
311
+ return db .WithTx (ctx , func (ctx context.Context ) error {
312
+ if err := pr .UpdateColsIfNotMerged (ctx , "merge_base" , "status" , "conflicted_files" , "changed_protected_files" , "base_branch" , "commits_ahead" , "commits_behind" ); err != nil {
313
+ return err
314
+ }
350
315
351
- return nil
316
+ // Create comment
317
+ options := & issues_model.CreateCommentOptions {
318
+ Type : issues_model .CommentTypeChangeTargetBranch ,
319
+ Doer : doer ,
320
+ Repo : pr .Issue .Repo ,
321
+ Issue : pr .Issue ,
322
+ OldRef : oldBranch ,
323
+ NewRef : targetBranch ,
324
+ }
325
+ if _ , err = issues_model .CreateComment (ctx , options ); err != nil {
326
+ return fmt .Errorf ("CreateChangeTargetBranchComment: %w" , err )
327
+ }
328
+
329
+ // Delete all old push comments and insert new push comments
330
+ if _ , err := db .GetEngine (ctx ).Where ("issue_id = ?" , pr .IssueID ).
331
+ And ("type = ?" , issues_model .CommentTypePullRequestPush ).
332
+ NoAutoCondition ().
333
+ Delete (new (issues_model.Comment )); err != nil {
334
+ return err
335
+ }
336
+
337
+ _ , err = CreatePushPullComment (ctx , doer , pr , git .BranchPrefix + pr .BaseBranch , pr .GetGitHeadRefName (), false )
338
+ return err
339
+ })
352
340
}
353
341
354
342
func checkForInvalidation (ctx context.Context , requests issues_model.PullRequestList , repoID int64 , doer * user_model.User , branch string ) error {
@@ -409,7 +397,7 @@ func AddTestPullRequestTask(opts TestPullRequestOptions) {
409
397
}
410
398
411
399
StartPullRequestCheckImmediately (ctx , pr )
412
- comment , err := CreatePushPullComment (ctx , opts .Doer , pr , opts .OldCommitID , opts .NewCommitID )
400
+ comment , err := CreatePushPullComment (ctx , opts .Doer , pr , opts .OldCommitID , opts .NewCommitID , opts . IsForcePush )
413
401
if err == nil && comment != nil {
414
402
notify_service .PullRequestPushCommits (ctx , opts .Doer , pr , comment )
415
403
}
0 commit comments