Skip to content

Commit

Permalink
Add PR state to resource version
Browse files Browse the repository at this point in the history
  • Loading branch information
vixus0 committed Oct 20, 2020
1 parent 8aa1ece commit c1d2f94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
18 changes: 12 additions & 6 deletions in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":"[email protected]"},{"name":"state","value":"OPEN"}]`,
},
{
Expand All @@ -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":"[email protected]"},{"name":"state","value":"OPEN"}]`,
},
{
Expand All @@ -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":"[email protected]"},{"name":"state","value":"OPEN"}]`,
},
{
Expand All @@ -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":"[email protected]"},{"name":"state","value":"OPEN"}]`,
},
{
Expand All @@ -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":"[email protected]"},{"name":"state","value":"OPEN"}]`,
},
{
Expand All @@ -131,6 +136,7 @@ func TestGet(t *testing.T) {
Commit: "commit1",
CommittedDate: time.Time{},
ApprovedReviewCount: "0",
State: githubv4.PullRequestStateOpen,
},
parameters: resource.GetParameters{
ListChangedFiles: true,
Expand All @@ -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":"[email protected]"},{"name":"state","value":"OPEN"}]`,
filesString: "README.md\nOther.md\n",
},
Expand Down
10 changes: 6 additions & 4 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
}
}

Expand Down

0 comments on commit c1d2f94

Please sign in to comment.