diff --git a/.travis.yml b/.travis.yml index b7f0a2af..4bb4326a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,4 @@ matrix: notifications: email: false script: -- go get -u -v github.com/go-task/task/cmd/task && task build +- go get -u -v github.com/go-task/task/cmd/task && task ci diff --git a/Taskfile.yml b/Taskfile.yml index 4022a733..64480f09 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -60,3 +60,10 @@ tasks: CGO_ENABLED: '0' GOOS: '{{OS}}' GOARCH: '{{ARCH}}' + + ci: + desc: CI build and tests + cmds: + - task: build + - if [ -n "$(git status --porcelain)" ];then echo "Diff in generated files and/or formatting" && exit 1; fi + silent: true diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index adec379a..02c6b981 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -153,6 +153,7 @@ func TestGetAndPutE2E(t *testing.T) { putParameters resource.PutParameters versionString string metadataString string + filesString string metadataFiles map[string]string expectedCommitCount int expectedCommits []string @@ -308,6 +309,27 @@ func TestGetAndPutE2E(t *testing.T) { "Add comment after creating first pull request.", }, }, + { + description: "get works with list_changed_files", + source: resource.Source{ + Repository: "itsdalmo/test-repository", + AccessToken: os.Getenv("GITHUB_ACCESS_TOKEN"), + }, + version: resource.Version{ + PR: targetPullRequestID, + Commit: targetCommitID, + CommittedDate: time.Time{}, + }, + getParameters: resource.GetParameters{ + ListChangedFiles: true, + }, + putParameters: resource.PutParameters{}, + versionString: `{"pr":"4","commit":"a5114f6ab89f4b736655642a11e8d15ce363d882","committed":"0001-01-01T00:00:00Z"}`, + metadataString: `[{"name":"pr","value":"4"},{"name":"url","value":"https://github.com/itsdalmo/test-repository/pull/4"},{"name":"head_name","value":"my_second_pull"},{"name":"head_sha","value":"a5114f6ab89f4b736655642a11e8d15ce363d882"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"93eeeedb8a16e6662062d1eca5655108977cc59a"},{"name":"message","value":"Push 2."},{"name":"author","value":"itsdalmo"}]`, + filesString: "README.md\ntest.txt\n", + expectedCommitCount: 10, + expectedCommits: []string{"Merge commit 'a5114f6ab89f4b736655642a11e8d15ce363d882'"}, + }, } for _, tc := range tests { @@ -336,6 +358,11 @@ func TestGetAndPutE2E(t *testing.T) { metadata := readTestFile(t, filepath.Join(dir, ".git", "resource", "metadata.json")) assert.Equal(t, tc.metadataString, metadata) + if tc.getParameters.ListChangedFiles { + changedFiles := readTestFile(t, filepath.Join(dir, ".git", "resource", "changed_files")) + assert.Equal(t, tc.filesString, changedFiles) + } + for filename, expected := range tc.metadataFiles { actual := readTestFile(t, filepath.Join(dir, ".git", "resource", filename)) assert.Equal(t, expected, actual) diff --git a/in_test.go b/in_test.go index e493ce09..77807990 100644 --- a/in_test.go +++ b/in_test.go @@ -39,21 +39,10 @@ func TestGet(t *testing.T) { Commit: "commit1", CommittedDate: time.Time{}, }, - parameters: resource.GetParameters{ - ListChangedFiles: true, - }, + parameters: resource.GetParameters{}, pullRequest: createTestPR(1, "master", false, false), versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`, metadataString: `[{"name":"pr","value":"1"},{"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"}]`, - files: []resource.ChangedFileObject{ - { - Path: "README.md", - }, - { - Path: "Other.md", - }, - }, - filesString: "README.md\nOther.md\n", }, { description: "get supports unlocking with git crypt", @@ -67,21 +56,10 @@ func TestGet(t *testing.T) { Commit: "commit1", CommittedDate: time.Time{}, }, - parameters: resource.GetParameters{ - ListChangedFiles: true, - }, + parameters: resource.GetParameters{}, pullRequest: createTestPR(1, "master", false, false), versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`, metadataString: `[{"name":"pr","value":"1"},{"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"}]`, - files: []resource.ChangedFileObject{ - { - Path: "README.md", - }, - { - Path: "Other.md", - }, - }, - filesString: "README.md\nOther.md\n", }, { description: "get supports rebasing", @@ -95,21 +73,11 @@ func TestGet(t *testing.T) { CommittedDate: time.Time{}, }, parameters: resource.GetParameters{ - IntegrationTool: "rebase", - ListChangedFiles: true, + IntegrationTool: "rebase", }, pullRequest: createTestPR(1, "master", false, false), versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`, metadataString: `[{"name":"pr","value":"1"},{"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"}]`, - files: []resource.ChangedFileObject{ - { - Path: "README.md", - }, - { - Path: "Other.md", - }, - }, - filesString: "README.md\nOther.md\n", }, { description: "get supports checkout", @@ -123,21 +91,11 @@ func TestGet(t *testing.T) { CommittedDate: time.Time{}, }, parameters: resource.GetParameters{ - IntegrationTool: "checkout", - ListChangedFiles: true, + IntegrationTool: "checkout", }, pullRequest: createTestPR(1, "master", false, false), versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`, metadataString: `[{"name":"pr","value":"1"},{"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"}]`, - files: []resource.ChangedFileObject{ - { - Path: "README.md", - }, - { - Path: "Other.md", - }, - }, - filesString: "README.md\nOther.md\n", }, { description: "get supports git_depth", @@ -150,25 +108,15 @@ func TestGet(t *testing.T) { Commit: "commit1", CommittedDate: time.Time{}, }, - parameters: resource.GetParameters{ - GitDepth: 2, - ListChangedFiles: true, + parameters: resource.GetParameters{ + GitDepth: 2, }, pullRequest: createTestPR(1, "master", false, false), versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`, metadataString: `[{"name":"pr","value":"1"},{"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"}]`, - files: []resource.ChangedFileObject{ - { - Path: "README.md", - }, - { - Path: "Other.md", - }, - }, - filesString: "README.md\nOther.md\n", }, { - description: "get works no file list", + description: "get supports list_changed_files", source: resource.Source{ Repository: "itsdalmo/test-repository", AccessToken: "oauthtoken", @@ -178,12 +126,21 @@ func TestGet(t *testing.T) { Commit: "commit1", CommittedDate: time.Time{}, }, - parameters: resource.GetParameters{ - ListChangedFiles: false, + parameters: resource.GetParameters{ + ListChangedFiles: true, + }, + pullRequest: createTestPR(1, "master", false, false), + files: []resource.ChangedFileObject{ + { + Path: "README.md", + }, + { + Path: "Other.md", + }, }, - pullRequest: createTestPR(1, "master", false, false), versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`, metadataString: `[{"name":"pr","value":"1"},{"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"}]`, + filesString: "README.md\nOther.md\n", }, }