@@ -16,79 +16,68 @@ import (
1616// getCommitIDsFromRepo get commit IDs from repo in between oldCommitID and newCommitID
1717// isForcePush will be true if oldCommit isn't on the branch
1818// Commit on baseBranch will skip
19- func getCommitIDsFromRepo (ctx context.Context , repo * repo_model.Repository , oldCommitID , newCommitID , baseBranch string ) (commitIDs []string , isForcePush bool , err error ) {
19+ func getCommitIDsFromRepo (ctx context.Context , repo * repo_model.Repository , oldCommitID , newCommitID , baseBranch string ) (commitIDs []string , err error ) {
2020 gitRepo , closer , err := gitrepo .RepositoryFromContextOrOpen (ctx , repo )
2121 if err != nil {
22- return nil , false , err
22+ return nil , err
2323 }
2424 defer closer .Close ()
2525
2626 oldCommit , err := gitRepo .GetCommit (oldCommitID )
2727 if err != nil {
28- return nil , false , err
28+ return nil , err
2929 }
3030
3131 newCommit , err := gitRepo .GetCommit (newCommitID )
3232 if err != nil {
33- return nil , false , err
34- }
35-
36- isForcePush , err = newCommit .IsForcePush (oldCommitID )
37- if err != nil {
38- return nil , false , err
39- }
40-
41- if isForcePush {
42- commitIDs = make ([]string , 2 )
43- commitIDs [0 ] = oldCommitID
44- commitIDs [1 ] = newCommitID
45-
46- return commitIDs , isForcePush , err
33+ return nil , err
4734 }
4835
4936 // Find commits between new and old commit excluding base branch commits
5037 commits , err := gitRepo .CommitsBetweenNotBase (newCommit , oldCommit , baseBranch )
5138 if err != nil {
52- return nil , false , err
39+ return nil , err
5340 }
5441
5542 commitIDs = make ([]string , 0 , len (commits ))
5643 for i := len (commits ) - 1 ; i >= 0 ; i -- {
5744 commitIDs = append (commitIDs , commits [i ].ID .String ())
5845 }
5946
60- return commitIDs , isForcePush , err
47+ return commitIDs , err
6148}
6249
6350// CreatePushPullComment create push code to pull base comment
64- func CreatePushPullComment (ctx context.Context , pusher * user_model.User , pr * issues_model.PullRequest , oldCommitID , newCommitID string ) (comment * issues_model.Comment , err error ) {
51+ func CreatePushPullComment (ctx context.Context , pusher * user_model.User , pr * issues_model.PullRequest , oldCommitID , newCommitID string , isForcePush bool ) (comment * issues_model.Comment , err error ) {
6552 if pr .HasMerged || oldCommitID == "" || newCommitID == "" {
6653 return nil , nil
6754 }
6855
69- ops := & issues_model.CreateCommentOptions {
70- Type : issues_model .CommentTypePullRequestPush ,
71- Doer : pusher ,
72- Repo : pr .BaseRepo ,
56+ opts := & issues_model.CreateCommentOptions {
57+ Type : issues_model .CommentTypePullRequestPush ,
58+ Doer : pusher ,
59+ Repo : pr .BaseRepo ,
60+ IsForcePush : isForcePush ,
61+ Issue : pr .Issue ,
7362 }
7463
7564 var data issues_model.PushActionContent
76-
77- data .CommitIDs , data .IsForcePush , err = getCommitIDsFromRepo (ctx , pr .BaseRepo , oldCommitID , newCommitID , pr .BaseBranch )
78- if err != nil {
79- return nil , err
65+ if opts .IsForcePush {
66+ data .CommitIDs = []string {oldCommitID , newCommitID }
67+ } else {
68+ data .CommitIDs , err = getCommitIDsFromRepo (ctx , pr .BaseRepo , oldCommitID , newCommitID , pr .BaseBranch )
69+ if err != nil {
70+ return nil , err
71+ }
8072 }
8173
82- ops .Issue = pr .Issue
83-
8474 dataJSON , err := json .Marshal (data )
8575 if err != nil {
8676 return nil , err
8777 }
8878
89- ops .Content = string (dataJSON )
90-
91- comment , err = issues_model .CreateComment (ctx , ops )
79+ opts .Content = string (dataJSON )
80+ comment , err = issues_model .CreateComment (ctx , opts )
9281
9382 return comment , err
9483}
0 commit comments