@@ -13,6 +13,7 @@ import (
1313 "code.gitea.io/gitea/modules/gitrepo"
1414 "code.gitea.io/gitea/modules/json"
1515 "code.gitea.io/gitea/modules/log"
16+ git_service "code.gitea.io/gitea/services/git"
1617)
1718
1819// getCommitIDsFromRepo get commit IDs from repo in between oldCommitID and newCommitID
@@ -62,19 +63,24 @@ func CreatePushPullComment(ctx context.Context, pusher *user_model.User, pr *iss
6263 }
6364
6465 var data issues_model.PushActionContent
65- data .CommitIDs , err = getCommitIDsFromRepo (ctx , pr .BaseRepo , oldCommitID , newCommitID , pr .BaseBranch )
66- if err != nil {
67- // For force-push events, a missing/unreachable old commit should not prevent
68- // deleting stale push comments or creating the force-push timeline entry.
69- if ! isForcePush {
66+ if isForcePush {
67+ // if it's a force push, we need to get the whole pull request commits
68+ data .CommitIDs , err = git_service .GetCompareCommitIDsWithMergeBase (ctx , pr .BaseRepo , pr .BaseBranch , newCommitID )
69+ if err != nil {
70+ // For force-push events, a missing/unreachable old commit should not prevent
71+ // deleting stale push comments or creating the force-push timeline entry.
72+ log .Error ("GetCompareCommitIDsWithMergeBase: %v" , err )
73+ }
74+ } else {
75+ data .CommitIDs , err = getCommitIDsFromRepo (ctx , pr .BaseRepo , oldCommitID , newCommitID , pr .BaseBranch )
76+ if err != nil {
7077 return nil , err
7178 }
72- log .Error ("getCommitIDsFromRepo: %v" , err )
73- }
74- // It maybe an empty pull request. Only non-empty pull request need to create push comment
75- // for force push, we always need to delete the old push comment so don't return here.
76- if len (data .CommitIDs ) == 0 && ! isForcePush {
77- return nil , nil //nolint:nilnil // return nil because no comment needs to be created
79+ // It maybe an empty pull request. Only non-empty pull request need to create push comment
80+ // for force push, we always need to delete the old push comment so don't return here.
81+ if len (data .CommitIDs ) == 0 {
82+ return nil , nil //nolint:nilnil // return nil because no comment needs to be created
83+ }
7884 }
7985
8086 return db .WithTx2 (ctx , func (ctx context.Context ) (* issues_model.Comment , error ) {
0 commit comments