From 2f12e184940fb73dd35f5fb73e1270c4e134523a Mon Sep 17 00:00:00 2001 From: Isaac Sanders Date: Mon, 25 Oct 2021 09:50:31 -0500 Subject: [PATCH] fix: Improves pull request filtering logic --- check.go | 7 +++++-- check_test.go | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/check.go b/check.go index 64df9e24..fbf4d074 100644 --- a/check.go +++ b/check.go @@ -5,6 +5,7 @@ import ( "path/filepath" "regexp" "sort" + "strconv" "strings" "github.com/shurcooL/githubv4" @@ -44,8 +45,10 @@ Loop: continue } - // Filter out commits that are too old. - if !p.UpdatedDate().Time.After(request.Version.CommittedDate) { + // Filter out commits that are too old and don't have more approvals. + approvedReviewCount, err := strconv.Atoi(request.Version.ApprovedReviewCount) + if !(p.UpdatedDate().Time.After(request.Version.CommittedDate) || + (err != nil && p.ApprovedReviewCount > approvedReviewCount)) { continue } diff --git a/check_test.go b/check_test.go index 8c422914..d9dbd07c 100644 --- a/check_test.go +++ b/check_test.go @@ -24,6 +24,11 @@ var ( createTestPR(11, "master", false, false, 0, nil, false, githubv4.PullRequestStateMerged), createTestPR(12, "master", false, false, 0, nil, false, githubv4.PullRequestStateOpen), } + + testApprovalPullRequests = []*resource.PullRequest{ + createTestPR(1, "master", false, false, 0, nil, false, githubv4.PullRequestStateOpen), + createTestPR(1, "master", false, false, 1, nil, false, githubv4.PullRequestStateOpen), + } ) func TestCheck(t *testing.T) { @@ -262,6 +267,20 @@ func TestCheck(t *testing.T) { resource.NewVersion(testPullRequests[10]), }, }, + + { + description: "check returns versions with more approvals, even if time is the same", + source: resource.Source{ + Repository: "itsdalmo/test-repository", + AccessToken: "oauthtoken", + }, + version: resource.NewVersion(testApprovalPullRequests[0]), + pullRequests: testApprovalPullRequests, + files: [][]string{}, + expected: resource.CheckResponse{ + resource.NewVersion(testApprovalPullRequests[1]), + }, + }, } for _, tc := range tests {