Skip to content

Commit

Permalink
Merge pull request #219 from isaacsanders/feat/add-approved-review-co…
Browse files Browse the repository at this point in the history
…unt-to-the-version

Adds approved review count to the version
  • Loading branch information
rickardl authored Oct 20, 2020
2 parents 43c9bd9 + c4b5c6d commit 06364c8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
54 changes: 30 additions & 24 deletions in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ func TestGet(t *testing.T) {
AccessToken: "oauthtoken",
},
version: resource.Version{
PR: "pr1",
Commit: "commit1",
CommittedDate: time.Time{},
PR: "pr1",
Commit: "commit1",
CommittedDate: time.Time{},
ApprovedReviewCount: 0,
},
parameters: resource.GetParameters{},
pullRequest: createTestPR(1, "master", false, false, 0, nil),
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`,
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":0}`,
metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"[email protected]"}]`,
},
{
Expand All @@ -52,13 +53,14 @@ func TestGet(t *testing.T) {
GitCryptKey: "gitcryptkey",
},
version: resource.Version{
PR: "pr1",
Commit: "commit1",
CommittedDate: time.Time{},
PR: "pr1",
Commit: "commit1",
CommittedDate: time.Time{},
ApprovedReviewCount: 0,
},
parameters: resource.GetParameters{},
pullRequest: createTestPR(1, "master", false, false, 0, nil),
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`,
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":0}`,
metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"[email protected]"}]`,
},
{
Expand All @@ -68,15 +70,16 @@ func TestGet(t *testing.T) {
AccessToken: "oauthtoken",
},
version: resource.Version{
PR: "pr1",
Commit: "commit1",
CommittedDate: time.Time{},
PR: "pr1",
Commit: "commit1",
CommittedDate: time.Time{},
ApprovedReviewCount: 0,
},
parameters: resource.GetParameters{
IntegrationTool: "rebase",
},
pullRequest: createTestPR(1, "master", false, false, 0, nil),
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`,
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":0}`,
metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"[email protected]"}]`,
},
{
Expand All @@ -86,15 +89,16 @@ func TestGet(t *testing.T) {
AccessToken: "oauthtoken",
},
version: resource.Version{
PR: "pr1",
Commit: "commit1",
CommittedDate: time.Time{},
PR: "pr1",
Commit: "commit1",
CommittedDate: time.Time{},
ApprovedReviewCount: 0,
},
parameters: resource.GetParameters{
IntegrationTool: "checkout",
},
pullRequest: createTestPR(1, "master", false, false, 0, nil),
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`,
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":0}`,
metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"[email protected]"}]`,
},
{
Expand All @@ -104,15 +108,16 @@ func TestGet(t *testing.T) {
AccessToken: "oauthtoken",
},
version: resource.Version{
PR: "pr1",
Commit: "commit1",
CommittedDate: time.Time{},
PR: "pr1",
Commit: "commit1",
CommittedDate: time.Time{},
ApprovedReviewCount: 0,
},
parameters: resource.GetParameters{
GitDepth: 2,
},
pullRequest: createTestPR(1, "master", false, false, 0, nil),
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`,
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":0}`,
metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"[email protected]"}]`,
},
{
Expand All @@ -122,9 +127,10 @@ func TestGet(t *testing.T) {
AccessToken: "oauthtoken",
},
version: resource.Version{
PR: "pr1",
Commit: "commit1",
CommittedDate: time.Time{},
PR: "pr1",
Commit: "commit1",
CommittedDate: time.Time{},
ApprovedReviewCount: 0,
},
parameters: resource.GetParameters{
ListChangedFiles: true,
Expand All @@ -138,7 +144,7 @@ func TestGet(t *testing.T) {
Path: "Other.md",
},
},
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`,
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":0}`,
metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"[email protected]"}]`,
filesString: "README.md\nOther.md\n",
},
Expand Down
14 changes: 8 additions & 6 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,19 @@ type MetadataField struct {

// Version communicated with Concourse.
type Version struct {
PR string `json:"pr"`
Commit string `json:"commit"`
CommittedDate time.Time `json:"committed,omitempty"`
PR string `json:"pr"`
Commit string `json:"commit"`
CommittedDate time.Time `json:"committed,omitempty"`
ApprovedReviewCount int `json:"approved_review_count"`
}

// NewVersion constructs a new Version.
func NewVersion(p *PullRequest) Version {
return Version{
PR: strconv.Itoa(p.Number),
Commit: p.Tip.OID,
CommittedDate: p.Tip.CommittedDate.Time,
PR: strconv.Itoa(p.Number),
Commit: p.Tip.OID,
CommittedDate: p.Tip.CommittedDate.Time,
ApprovedReviewCount: p.ApprovedReviewCount,
}
}

Expand Down

0 comments on commit 06364c8

Please sign in to comment.