From 96f2dc5eb25dca99eb6fa2cc87d9f2f88deae504 Mon Sep 17 00:00:00 2001 From: Brian Malehorn Date: Thu, 9 Dec 2021 15:42:29 -0800 Subject: [PATCH 1/2] Revert "fix up cherry-pick to pass tests" This reverts commit e7c80e82a0ae57f19a416231d95051f5ab677c57. --- check_test.go | 43 +------------------------------------------ 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/check_test.go b/check_test.go index 5761ebf9..a795348d 100644 --- a/check_test.go +++ b/check_test.go @@ -73,10 +73,6 @@ func TestCheck(t *testing.T) { pullRequests: testPullRequests, files: [][]string{}, expected: resource.CheckResponse{ - resource.NewVersion(testPullRequests[14], testPullRequests[14].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[13], testPullRequests[13].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[12], testPullRequests[12].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[11], testPullRequests[11].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[8], testPullRequests[8].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[7], testPullRequests[7].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[6], testPullRequests[6].Tip.CommittedDate.Time), @@ -85,6 +81,7 @@ func TestCheck(t *testing.T) { resource.NewVersion(testPullRequests[3], testPullRequests[3].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[2], testPullRequests[2].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[1], testPullRequests[1].Tip.CommittedDate.Time), + }, }, @@ -98,16 +95,6 @@ func TestCheck(t *testing.T) { pullRequests: testPullRequests, files: [][]string{}, expected: resource.CheckResponse{ - resource.NewVersion(testPullRequests[14], testPullRequests[14].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[13], testPullRequests[13].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[12], testPullRequests[12].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[11], testPullRequests[11].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[8], testPullRequests[8].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[7], testPullRequests[7].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[6], testPullRequests[6].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[5], testPullRequests[5].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[4], testPullRequests[4].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[3], testPullRequests[3].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[2], testPullRequests[2].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[1], testPullRequests[1].Tip.CommittedDate.Time), }, @@ -163,10 +150,6 @@ func TestCheck(t *testing.T) { version: resource.NewVersion(testPullRequests[1], testPullRequests[1].Tip.CommittedDate.Time), pullRequests: testPullRequests, expected: resource.CheckResponse{ - resource.NewVersion(testPullRequests[14], testPullRequests[14].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[13], testPullRequests[13].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[12], testPullRequests[12].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[11], testPullRequests[11].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[8], testPullRequests[8].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[7], testPullRequests[7].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[6], testPullRequests[6].Tip.CommittedDate.Time), @@ -189,16 +172,6 @@ func TestCheck(t *testing.T) { version: resource.NewVersion(testPullRequests[3], testPullRequests[3].Tip.CommittedDate.Time), pullRequests: testPullRequests, expected: resource.CheckResponse{ - resource.NewVersion(testPullRequests[14], testPullRequests[14].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[13], testPullRequests[13].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[12], testPullRequests[12].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[11], testPullRequests[11].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[8], testPullRequests[8].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[7], testPullRequests[7].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[6], testPullRequests[6].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[5], testPullRequests[5].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[4], testPullRequests[4].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[3], testPullRequests[3].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[1], testPullRequests[1].Tip.CommittedDate.Time), }, }, @@ -213,16 +186,6 @@ func TestCheck(t *testing.T) { version: resource.NewVersion(testPullRequests[3], testPullRequests[3].Tip.CommittedDate.Time), pullRequests: testPullRequests, expected: resource.CheckResponse{ - resource.NewVersion(testPullRequests[14], testPullRequests[14].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[13], testPullRequests[13].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[12], testPullRequests[12].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[11], testPullRequests[11].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[8], testPullRequests[8].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[7], testPullRequests[7].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[6], testPullRequests[6].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[5], testPullRequests[5].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[4], testPullRequests[4].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[3], testPullRequests[3].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[2], testPullRequests[2].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[1], testPullRequests[1].Tip.CommittedDate.Time), }, @@ -238,10 +201,6 @@ func TestCheck(t *testing.T) { version: resource.NewVersion(testPullRequests[5], testPullRequests[5].Tip.CommittedDate.Time), pullRequests: testPullRequests, expected: resource.CheckResponse{ - resource.NewVersion(testPullRequests[14], testPullRequests[14].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[13], testPullRequests[13].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[12], testPullRequests[12].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[11], testPullRequests[11].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[8], testPullRequests[8].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[7], testPullRequests[7].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[6], testPullRequests[6].Tip.CommittedDate.Time), From 17ec752da92cf95bcb4e7da5db8b8a623597cb3a Mon Sep 17 00:00:00 2001 From: Brian Malehorn Date: Thu, 9 Dec 2021 15:42:37 -0800 Subject: [PATCH 2/2] Revert "Close #26: Return all open PRs instead of filtering by date" This reverts commit fd89b794ef67997a27b1eed17f3525f288a10eaa. --- check.go | 5 +++++ check_test.go | 24 +----------------------- e2e/e2e_test.go | 19 +++++++++++++------ 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/check.go b/check.go index 112779bd..4df41d04 100644 --- a/check.go +++ b/check.go @@ -69,6 +69,11 @@ Loop: } } + // Filter out commits that are too old. + if !versionTime.After(request.Version.CommittedDate) { + continue + } + // Filter out pull request if it does not contain at least one of the desired labels if len(request.Source.Labels) > 0 { labelFound := false diff --git a/check_test.go b/check_test.go index a795348d..86b7b540 100644 --- a/check_test.go +++ b/check_test.go @@ -64,7 +64,7 @@ func TestCheck(t *testing.T) { }, { - description: "check returns all open PRs if there is a previous", + description: "check returns the previous version when its still latest", source: resource.Source{ Repository: "itsdalmo/test-repository", AccessToken: "oauthtoken", @@ -73,15 +73,7 @@ func TestCheck(t *testing.T) { pullRequests: testPullRequests, files: [][]string{}, expected: resource.CheckResponse{ - resource.NewVersion(testPullRequests[8], testPullRequests[8].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[7], testPullRequests[7].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[6], testPullRequests[6].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[5], testPullRequests[5].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[4], testPullRequests[4].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[3], testPullRequests[3].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[2], testPullRequests[2].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[1], testPullRequests[1].Tip.CommittedDate.Time), - }, }, @@ -115,7 +107,6 @@ func TestCheck(t *testing.T) { {"terraform/modules/variables.tf", "travis.yml"}, }, expected: resource.CheckResponse{ - resource.NewVersion(testPullRequests[3], testPullRequests[3].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[2], testPullRequests[2].Tip.CommittedDate.Time), }, }, @@ -135,7 +126,6 @@ func TestCheck(t *testing.T) { {"terraform/modules/variables.tf", "travis.yml"}, }, expected: resource.CheckResponse{ - resource.NewVersion(testPullRequests[3], testPullRequests[3].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[2], testPullRequests[2].Tip.CommittedDate.Time), }, }, @@ -150,14 +140,6 @@ func TestCheck(t *testing.T) { version: resource.NewVersion(testPullRequests[1], testPullRequests[1].Tip.CommittedDate.Time), pullRequests: testPullRequests, expected: resource.CheckResponse{ - resource.NewVersion(testPullRequests[8], testPullRequests[8].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[7], testPullRequests[7].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[6], testPullRequests[6].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[5], testPullRequests[5].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[4], testPullRequests[4].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[3], testPullRequests[3].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[2], testPullRequests[2].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[1], testPullRequests[1].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[0], testPullRequests[0].Tip.CommittedDate.Time), }, }, @@ -201,10 +183,6 @@ func TestCheck(t *testing.T) { version: resource.NewVersion(testPullRequests[5], testPullRequests[5].Tip.CommittedDate.Time), pullRequests: testPullRequests, expected: resource.CheckResponse{ - resource.NewVersion(testPullRequests[8], testPullRequests[8].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[7], testPullRequests[7].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[6], testPullRequests[6].Tip.CommittedDate.Time), - resource.NewVersion(testPullRequests[5], testPullRequests[5].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[3], testPullRequests[3].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[2], testPullRequests[2].Tip.CommittedDate.Time), resource.NewVersion(testPullRequests[1], testPullRequests[1].Tip.CommittedDate.Time), diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 51701798..660410a2 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -24,9 +24,6 @@ import ( ) var ( - firstCommitID = "23dc9f552bf989d1a4aeb65ce23351dee0ec9019" - firstPullRequestID = "3" - firstDateTime = time.Date(2018, time.May, 11, 7, 28, 56, 0, time.UTC) targetCommitID = "a5114f6ab89f4b736655642a11e8d15ce363d882" targetPullRequestID = "4" targetDateTime = time.Date(2018, time.May, 11, 8, 43, 48, 0, time.UTC) @@ -58,15 +55,25 @@ func TestCheckE2E(t *testing.T) { }, { - description: "check returns all open PRs if there is a previous version", + description: "check returns the previous version when its still latest", source: resource.Source{ Repository: "itsdalmo/test-repository", AccessToken: os.Getenv("GITHUB_ACCESS_TOKEN"), }, version: resource.Version{PR: latestPullRequestID, Commit: latestCommitID, CommittedDate: latestDateTime}, expected: resource.CheckResponse{ - resource.Version{PR: firstPullRequestID, Commit: firstCommitID, CommittedDate: firstDateTime}, - resource.Version{PR: targetPullRequestID, Commit: targetCommitID, CommittedDate: targetDateTime}, + resource.Version{PR: latestPullRequestID, Commit: latestCommitID, CommittedDate: latestDateTime}, + }, + }, + + { + description: "check returns all new versions since the last", + source: resource.Source{ + Repository: "itsdalmo/test-repository", + AccessToken: os.Getenv("GITHUB_ACCESS_TOKEN"), + }, + version: resource.Version{PR: targetPullRequestID, Commit: targetCommitID, CommittedDate: targetDateTime}, + expected: resource.CheckResponse{ resource.Version{PR: latestPullRequestID, Commit: latestCommitID, CommittedDate: latestDateTime}, }, },