From 237f6e343556302e5b48c65701553f97fedc505b Mon Sep 17 00:00:00 2001 From: William Martin Date: Fri, 16 Feb 2024 16:15:19 +0100 Subject: [PATCH] Test PR create uses commit title and body when only one commit --- pkg/cmd/pr/create/create_test.go | 79 ++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/pkg/cmd/pr/create/create_test.go b/pkg/cmd/pr/create/create_test.go index bd878a8c4..72953705f 100644 --- a/pkg/cmd/pr/create/create_test.go +++ b/pkg/cmd/pr/create/create_test.go @@ -995,6 +995,85 @@ func Test_createRun(t *testing.T) { }, expectedOut: "https://github.com/OWNER/REPO/pull/12\n", }, + { + name: "single commit title and body are used", + tty: true, + setup: func(opts *CreateOptions, t *testing.T) func() { + opts.HeadBranch = "feature" + return func() {} + }, + cmdStubs: func(cs *run.CommandStubber) { + cs.Register( + "git -c log.ShowSignature=false log --pretty=format:%H,%s --cherry origin/master...feature", + 0, + "343jdfe47c9e3a30093cd17e48934ce354148e80,first commit of pr\n\nfirst commit description\n", + ) + cs.Register( + "git -c log.ShowSignature=false show -s --pretty=format:%b 343jdfe47c9e3a30093cd17e48934ce354148e80", + 0, + "first commit description", + ) + cs.Register(`git rev-parse --show-toplevel`, 0, "") + }, + promptStubs: func(pm *prompter.PrompterMock) { + pm.SelectFunc = func(p, _ string, opts []string) (int, error) { + if p == "Where should we push the 'feature' branch?" { + return 0, nil + } else { + return -1, prompter.NoSuchPromptErr(p) + } + } + + pm.InputFunc = func(p, d string) (string, error) { + if p == "Title" { + return d, nil + } else if p == "Body" { + return d, nil + } else { + return "", prompter.NoSuchPromptErr(p) + } + } + + pm.MarkdownEditorFunc = func(p, d string, ba bool) (string, error) { + if p == "Body" { + return d, nil + } else { + return "", prompter.NoSuchPromptErr(p) + } + } + + pm.SelectFunc = func(p, _ string, opts []string) (int, error) { + if p == "What's next?" { + return 0, nil + } else { + return -1, prompter.NoSuchPromptErr(p) + } + } + }, + httpStubs: func(reg *httpmock.Registry, t *testing.T) { + reg.Register( + httpmock.GraphQL(`query PullRequestTemplates\b`), + httpmock.StringResponse(`{ "data": { "repository": { "pullRequestTemplates": [] } } }`), + ) + reg.Register( + httpmock.GraphQL(`mutation PullRequestCreate\b`), + httpmock.GraphQLMutation(` + { + "data": { "createPullRequest": { "pullRequest": { + "URL": "https://github.com/OWNER/REPO/pull/12" + } } } + } + `, + func(input map[string]interface{}) { + assert.Equal(t, "first commit of pr", input["title"], "pr title should be first commit message") + assert.Equal(t, "first commit description", input["body"], "pr body should be first commit description") + }, + ), + ) + }, + expectedOut: "https://github.com/OWNER/REPO/pull/12\n", + expectedErrOut: "\nCreating pull request for feature into master in OWNER/REPO\n\n", + }, { name: "fill-first flag provided", tty: true,