@@ -215,13 +215,33 @@ func (svc GithubService) GetComments(prNumber int) ([]ci.Comment, error) {
215215
216216func (svc GithubService ) GetApprovals (prNumber int ) ([]string , error ) {
217217 reviews , _ , err := svc .Client .PullRequests .ListReviews (context .Background (), svc .Owner , svc .RepoName , prNumber , & github.ListOptions {})
218- approvals := make ([]string , 0 )
218+ if err != nil {
219+ return nil , err
220+ }
221+
222+ // Track the latest review state per user
223+ // GitHub returns reviews in chronological order, so later entries are more recent
224+ // We need to consider the latest review state, not just any APPROVED review
225+ latestReviewState := make (map [string ]string )
219226 for _ , review := range reviews {
220- if * review .State == "APPROVED" {
221- approvals = append (approvals , * review .User .Login )
227+ if review .User == nil || review .User .Login == nil || review .State == nil {
228+ continue
229+ }
230+ // Skip COMMENTED reviews as they don't change approval status
231+ if * review .State == "COMMENTED" {
232+ continue
233+ }
234+ latestReviewState [* review .User .Login ] = * review .State
235+ }
236+
237+ // Collect users whose latest review state is APPROVED
238+ approvals := make ([]string , 0 )
239+ for user , state := range latestReviewState {
240+ if state == "APPROVED" {
241+ approvals = append (approvals , user )
222242 }
223243 }
224- return approvals , err
244+ return approvals , nil
225245}
226246
227247func (svc GithubService ) EditComment (prNumber int , id string , comment string ) error {
0 commit comments