Skip to content

Commit

Permalink
Merge branch 'master' into add-github-actions-ci-cd
Browse files Browse the repository at this point in the history
  • Loading branch information
rickardl authored Oct 20, 2020
2 parents 940551a + 2ab0f31 commit fc3b6ae
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 53 deletions.
45 changes: 22 additions & 23 deletions in.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,6 @@ func Get(request GetRequest, github Github, git Git, outputDir string) (*GetResp
return nil, err
}

switch tool := request.Params.IntegrationTool; tool {
case "rebase":
if err := git.Rebase(pull.BaseRefName, pull.Tip.OID, request.Params.Submodules); err != nil {
return nil, err
}
case "merge", "":
if err := git.Merge(pull.Tip.OID, request.Params.Submodules); err != nil {
return nil, err
}
case "checkout":
if err := git.Checkout(pull.HeadRefName, pull.Tip.OID, request.Params.Submodules); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("invalid integration tool specified: %s", tool)
}

if request.Source.GitCryptKey != "" {
if err := git.GitCryptUnlock(request.Source.GitCryptKey); err != nil {
return nil, err
}
}

// Create the metadata
var metadata Metadata
metadata.Add("pr", strconv.Itoa(pull.Number))
Expand Down Expand Up @@ -101,7 +78,29 @@ func Get(request GetRequest, github Github, git Git, outputDir string) (*GetResp
if err := ioutil.WriteFile(filepath.Join(path, filename), content, 0644); err != nil {
return nil, fmt.Errorf("failed to write metadata file %s: %s", filename, err)
}
}

switch tool := request.Params.IntegrationTool; tool {
case "rebase":
if err := git.Rebase(pull.BaseRefName, pull.Tip.OID, request.Params.Submodules); err != nil {
return nil, err
}
case "merge", "":
if err := git.Merge(pull.Tip.OID, request.Params.Submodules); err != nil {
return nil, err
}
case "checkout":
if err := git.Checkout(pull.HeadRefName, pull.Tip.OID, request.Params.Submodules); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("invalid integration tool specified: %s", tool)
}

if request.Source.GitCryptKey != "" {
if err := git.GitCryptUnlock(request.Source.GitCryptKey); err != nil {
return nil, err
}
}

if request.Params.ListChangedFiles {
Expand Down
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 string `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: strconv.Itoa(p.ApprovedReviewCount),
}
}

Expand Down

0 comments on commit fc3b6ae

Please sign in to comment.