Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(create_prs): check whether PR description file has been updated #145

Merged
merged 7 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test title and body separately
  • Loading branch information
Danny Ranson committed Aug 14, 2024
commit 877b5f0b2fc343d3456f5159e0eef7fe0a7003e2
47 changes: 45 additions & 2 deletions cmd/create_prs/create_prs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/skyscanner/turbolift/internal/prompt"
"github.com/skyscanner/turbolift/internal/testsupport"
"github.com/stretchr/testify/assert"
"path/filepath"
"testing"
)

Expand All @@ -33,8 +34,50 @@ func TestItWarnsIfDescriptionFileTemplateIsUnchanged(t *testing.T) {
fakePrompt := prompt.NewFakePromptNo()
p = fakePrompt

dir := testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2")
testsupport.UseDefaultPrDescription(dir)
dirName := testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2")
testsupport.UseDefaultPrDescription(dirName)

out, err := runCommand()
assert.NoError(t, err)
assert.NotContains(t, out, "Creating PR in org/repo1")
assert.NotContains(t, out, "Creating PR in org/repo2")
assert.NotContains(t, out, "turbolift create-prs completed")
assert.NotContains(t, out, "2 OK, 0 skipped")

fakePrompt.AssertCalledWith(t, "It looks like the PR title and/or description may not have been updated in README.md. Are you sure you want to proceed?")
}

func TestItWarnsIfOnlyPrTitleIsUnchanged(t *testing.T) {
fakeGitHub := github.NewAlwaysFailsFakeGitHub()
gh = fakeGitHub
fakeGit := git.NewAlwaysSucceedsFakeGit()
g = fakeGit
fakePrompt := prompt.NewFakePromptNo()
p = fakePrompt

dirName := testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2")
testsupport.UsePrTitleTodoOnly(filepath.Base(dirName))

out, err := runCommand()
assert.NoError(t, err)
assert.NotContains(t, out, "Creating PR in org/repo1")
assert.NotContains(t, out, "Creating PR in org/repo2")
assert.NotContains(t, out, "turbolift create-prs completed")
assert.NotContains(t, out, "2 OK, 0 skipped")

fakePrompt.AssertCalledWith(t, "It looks like the PR title and/or description may not have been updated in README.md. Are you sure you want to proceed?")
}

func TestItWarnsIfOnlyPrBodyIsUnchanged(t *testing.T) {
fakeGitHub := github.NewAlwaysFailsFakeGitHub()
gh = fakeGitHub
fakeGit := git.NewAlwaysSucceedsFakeGit()
g = fakeGit
fakePrompt := prompt.NewFakePromptNo()
p = fakePrompt

testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2")
testsupport.UsePrBodyTodoOnly()

out, err := runCommand()
assert.NoError(t, err)
Expand Down
8 changes: 8 additions & 0 deletions internal/testsupport/testsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ func UseDefaultPrDescription(dirName string) {
originalPrBodyTodo := "TODO: This file will serve as both a README and the description of the PR."
CreateOrUpdatePrDescriptionFile("README.md", originalPrTitleTodo, originalPrBodyTodo)
}

func UsePrTitleTodoOnly(dirName string) {
CreateOrUpdatePrDescriptionFile("README.md", fmt.Sprintf("TODO: Title of Pull Request (%s)", dirName), "updated PR body")
}

func UsePrBodyTodoOnly() {
CreateOrUpdatePrDescriptionFile("README.md", "updated PR title", "TODO: This file will serve as both a README and the description of the PR.")
}
Loading