From c1d2f9472c3447889d38423a268effe14e32ac96 Mon Sep 17 00:00:00 2001 From: Anshul Sirur Date: Thu, 15 Oct 2020 14:45:17 +0200 Subject: [PATCH] Add PR state to resource version --- in_test.go | 18 ++++++++++++------ models.go | 10 ++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/in_test.go b/in_test.go index a335421b..3f595ee7 100644 --- a/in_test.go +++ b/in_test.go @@ -39,10 +39,11 @@ func TestGet(t *testing.T) { Commit: "commit1", CommittedDate: time.Time{}, ApprovedReviewCount: "0", + State: githubv4.PullRequestStateOpen, }, parameters: resource.GetParameters{}, pullRequest: createTestPR(1, "master", false, false, 0, nil, githubv4.PullRequestStateOpen), - versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":"0"}`, + versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":"0","state":"OPEN"}`, 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":"user@example.com"},{"name":"state","value":"OPEN"}]`, }, { @@ -57,10 +58,11 @@ func TestGet(t *testing.T) { Commit: "commit1", CommittedDate: time.Time{}, ApprovedReviewCount: "0", + State: githubv4.PullRequestStateOpen, }, parameters: resource.GetParameters{}, pullRequest: createTestPR(1, "master", false, false, 0, nil, githubv4.PullRequestStateOpen), - versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":"0"}`, + versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":"0","state":"OPEN"}`, 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":"user@example.com"},{"name":"state","value":"OPEN"}]`, }, { @@ -74,12 +76,13 @@ func TestGet(t *testing.T) { Commit: "commit1", CommittedDate: time.Time{}, ApprovedReviewCount: "0", + State: githubv4.PullRequestStateOpen, }, parameters: resource.GetParameters{ IntegrationTool: "rebase", }, pullRequest: createTestPR(1, "master", false, false, 0, nil, githubv4.PullRequestStateOpen), - versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":"0"}`, + versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":"0","state":"OPEN"}`, 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":"user@example.com"},{"name":"state","value":"OPEN"}]`, }, { @@ -93,12 +96,13 @@ func TestGet(t *testing.T) { Commit: "commit1", CommittedDate: time.Time{}, ApprovedReviewCount: "0", + State: githubv4.PullRequestStateOpen, }, parameters: resource.GetParameters{ IntegrationTool: "checkout", }, pullRequest: createTestPR(1, "master", false, false, 0, nil, githubv4.PullRequestStateOpen), - versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":"0"}`, + versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":"0","state":"OPEN"}`, 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":"user@example.com"},{"name":"state","value":"OPEN"}]`, }, { @@ -112,12 +116,13 @@ func TestGet(t *testing.T) { Commit: "commit1", CommittedDate: time.Time{}, ApprovedReviewCount: "0", + State: githubv4.PullRequestStateOpen, }, parameters: resource.GetParameters{ GitDepth: 2, }, pullRequest: createTestPR(1, "master", false, false, 0, nil, githubv4.PullRequestStateOpen), - versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":"0"}`, + versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":"0","state":"OPEN"}`, 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":"user@example.com"},{"name":"state","value":"OPEN"}]`, }, { @@ -131,6 +136,7 @@ func TestGet(t *testing.T) { Commit: "commit1", CommittedDate: time.Time{}, ApprovedReviewCount: "0", + State: githubv4.PullRequestStateOpen, }, parameters: resource.GetParameters{ ListChangedFiles: true, @@ -144,7 +150,7 @@ func TestGet(t *testing.T) { Path: "Other.md", }, }, - versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":"0"}`, + versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","approved_review_count":"0","state":"OPEN"}`, 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":"user@example.com"},{"name":"state","value":"OPEN"}]`, filesString: "README.md\nOther.md\n", }, diff --git a/models.go b/models.go index b7ddb1cd..2fafbfa3 100644 --- a/models.go +++ b/models.go @@ -73,10 +73,11 @@ type MetadataField struct { // Version communicated with Concourse. type Version struct { - PR string `json:"pr"` - Commit string `json:"commit"` - CommittedDate time.Time `json:"committed,omitempty"` - ApprovedReviewCount string `json:"approved_review_count"` + PR string `json:"pr"` + Commit string `json:"commit"` + CommittedDate time.Time `json:"committed,omitempty"` + ApprovedReviewCount string `json:"approved_review_count"` + State githubv4.PullRequestState `json:"state"` } // NewVersion constructs a new Version. @@ -86,6 +87,7 @@ func NewVersion(p *PullRequest) Version { Commit: p.Tip.OID, CommittedDate: p.Tip.CommittedDate.Time, ApprovedReviewCount: strconv.Itoa(p.ApprovedReviewCount), + State: p.State, } }