@@ -48,10 +48,6 @@ func IsCodeOwnerFile(f string) bool {
48
48
}
49
49
50
50
func PullRequestCodeOwnersReview (ctx context.Context , pr * issues_model.PullRequest ) ([]* ReviewRequestNotifier , error ) {
51
- return PullRequestCodeOwnersReviewSpecialCommits (ctx , pr , "" , "" ) // no commit is provided, then it uses PR's base&head branch
52
- }
53
-
54
- func PullRequestCodeOwnersReviewSpecialCommits (ctx context.Context , pr * issues_model.PullRequest , startCommitID , endCommitID string ) ([]* ReviewRequestNotifier , error ) {
55
51
if err := pr .LoadIssue (ctx ); err != nil {
56
52
return nil , err
57
53
}
@@ -100,19 +96,15 @@ func PullRequestCodeOwnersReviewSpecialCommits(ctx context.Context, pr *issues_m
100
96
return nil , nil
101
97
}
102
98
103
- if startCommitID == "" && endCommitID == "" {
104
- // get the mergebase
105
- mergeBase , err := getMergeBase (repo , pr , git .BranchPrefix + pr .BaseBranch , pr .GetGitRefName ())
106
- if err != nil {
107
- return nil , err
108
- }
109
- startCommitID = mergeBase
110
- endCommitID = pr .GetGitRefName ()
99
+ // get the mergebase
100
+ mergeBase , err := getMergeBase (repo , pr , git .BranchPrefix + pr .BaseBranch , pr .GetGitRefName ())
101
+ if err != nil {
102
+ return nil , err
111
103
}
112
104
113
105
// https://github.com/go-gitea/gitea/issues/29763, we need to get the files changed
114
106
// between the merge base and the head commit but not the base branch and the head commit
115
- changedFiles , err := repo .GetFilesChangedBetween (startCommitID , endCommitID )
107
+ changedFiles , err := repo .GetFilesChangedBetween (mergeBase , pr . GetGitRefName () )
116
108
if err != nil {
117
109
return nil , err
118
110
}
@@ -138,8 +130,23 @@ func PullRequestCodeOwnersReviewSpecialCommits(ctx context.Context, pr *issues_m
138
130
return nil , err
139
131
}
140
132
133
+ // load all reviews from database
134
+ latestReivews , _ , err := issues_model .GetReviewsByIssueID (ctx , pr .IssueID )
135
+ if err != nil {
136
+ return nil , err
137
+ }
138
+
139
+ contain := func (list issues_model.ReviewList , u * user_model.User ) bool {
140
+ for _ , review := range list {
141
+ if review .ReviewerTeamID == 0 && review .ReviewerID == u .ID {
142
+ return true
143
+ }
144
+ }
145
+ return false
146
+ }
147
+
141
148
for _ , u := range uniqUsers {
142
- if u .ID != issue .Poster .ID {
149
+ if u .ID != issue .Poster .ID && ! contain ( latestReivews , u ) {
143
150
comment , err := issues_model .AddReviewRequest (ctx , issue , u , issue .Poster )
144
151
if err != nil {
145
152
log .Warn ("Failed add assignee user: %s to PR review: %s#%d, error: %s" , u .Name , pr .BaseRepo .Name , pr .ID , err )
@@ -155,6 +162,7 @@ func PullRequestCodeOwnersReviewSpecialCommits(ctx context.Context, pr *issues_m
155
162
})
156
163
}
157
164
}
165
+
158
166
for _ , t := range uniqTeams {
159
167
comment , err := issues_model .AddTeamReviewRequest (ctx , issue , t , issue .Poster )
160
168
if err != nil {
0 commit comments