Skip to content

Commit

Permalink
Merge pull request #4 from opendoor-labs/bm/fix-telia-oss-26
Browse files Browse the repository at this point in the history
Return all open PRs instead of filtering by date
  • Loading branch information
bmalehorn authored Dec 8, 2021
2 parents f819803 + e7c80e8 commit b992455
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 19 deletions.
5 changes: 0 additions & 5 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ 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
Expand Down
65 changes: 64 additions & 1 deletion check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestCheck(t *testing.T) {
},

{
description: "check returns the previous version when its still latest",
description: "check returns all open PRs if there is a previous",
source: resource.Source{
Repository: "itsdalmo/test-repository",
AccessToken: "oauthtoken",
Expand All @@ -73,6 +73,17 @@ 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),
},
},
Expand All @@ -87,6 +98,16 @@ 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),
},
Expand All @@ -107,6 +128,7 @@ 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),
},
},
Expand All @@ -126,6 +148,7 @@ 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),
},
},
Expand All @@ -140,6 +163,18 @@ 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),
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),
},
},
Expand All @@ -154,6 +189,16 @@ 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),
},
},
Expand All @@ -168,6 +213,16 @@ 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),
},
Expand All @@ -183,6 +238,14 @@ 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),
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),
Expand Down
19 changes: 6 additions & 13 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ 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)
Expand Down Expand Up @@ -55,25 +58,15 @@ func TestCheckE2E(t *testing.T) {
},

{
description: "check returns the previous version when its still latest",
description: "check returns all open PRs if there is a previous version",
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: 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: firstPullRequestID, Commit: firstCommitID, CommittedDate: firstDateTime},
resource.Version{PR: targetPullRequestID, Commit: targetCommitID, CommittedDate: targetDateTime},
resource.Version{PR: latestPullRequestID, Commit: latestCommitID, CommittedDate: latestDateTime},
},
},
Expand Down

0 comments on commit b992455

Please sign in to comment.