Skip to content

Commit 2f12e18

Browse files
committed
fix: Improves pull request filtering logic
1 parent 9ec47e2 commit 2f12e18

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

check.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"path/filepath"
66
"regexp"
77
"sort"
8+
"strconv"
89
"strings"
910

1011
"github.com/shurcooL/githubv4"
@@ -44,8 +45,10 @@ Loop:
4445
continue
4546
}
4647

47-
// Filter out commits that are too old.
48-
if !p.UpdatedDate().Time.After(request.Version.CommittedDate) {
48+
// Filter out commits that are too old and don't have more approvals.
49+
approvedReviewCount, err := strconv.Atoi(request.Version.ApprovedReviewCount)
50+
if !(p.UpdatedDate().Time.After(request.Version.CommittedDate) ||
51+
(err != nil && p.ApprovedReviewCount > approvedReviewCount)) {
4952
continue
5053
}
5154

check_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ var (
2424
createTestPR(11, "master", false, false, 0, nil, false, githubv4.PullRequestStateMerged),
2525
createTestPR(12, "master", false, false, 0, nil, false, githubv4.PullRequestStateOpen),
2626
}
27+
28+
testApprovalPullRequests = []*resource.PullRequest{
29+
createTestPR(1, "master", false, false, 0, nil, false, githubv4.PullRequestStateOpen),
30+
createTestPR(1, "master", false, false, 1, nil, false, githubv4.PullRequestStateOpen),
31+
}
2732
)
2833

2934
func TestCheck(t *testing.T) {
@@ -262,6 +267,20 @@ func TestCheck(t *testing.T) {
262267
resource.NewVersion(testPullRequests[10]),
263268
},
264269
},
270+
271+
{
272+
description: "check returns versions with more approvals, even if time is the same",
273+
source: resource.Source{
274+
Repository: "itsdalmo/test-repository",
275+
AccessToken: "oauthtoken",
276+
},
277+
version: resource.NewVersion(testApprovalPullRequests[0]),
278+
pullRequests: testApprovalPullRequests,
279+
files: [][]string{},
280+
expected: resource.CheckResponse{
281+
resource.NewVersion(testApprovalPullRequests[1]),
282+
},
283+
},
265284
}
266285

267286
for _, tc := range tests {

0 commit comments

Comments
 (0)