|
5 | 5 | "encoding/json" |
6 | 6 | "io/ioutil" |
7 | 7 | "net/http" |
| 8 | + "os" |
| 9 | + "path" |
8 | 10 | "reflect" |
9 | 11 | "strings" |
10 | 12 | "testing" |
@@ -314,7 +316,7 @@ func TestPRCreate_nonLegacyTemplate(t *testing.T) { |
314 | 316 |
|
315 | 317 | eq(t, reqBody.Variables.Input.RepositoryID, "REPOID") |
316 | 318 | eq(t, reqBody.Variables.Input.Title, "my title") |
317 | | - eq(t, reqBody.Variables.Input.Body, "Fixes a bug and Closes an issue") |
| 319 | + eq(t, reqBody.Variables.Input.Body, "- commit 1\n- commit 0\n\nFixes a bug and Closes an issue") |
318 | 320 | eq(t, reqBody.Variables.Input.BaseRefName, "master") |
319 | 321 | eq(t, reqBody.Variables.Input.HeadRefName, "feature") |
320 | 322 |
|
@@ -851,6 +853,77 @@ func TestPRCreate_survey_defaults_monocommit(t *testing.T) { |
851 | 853 | eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n") |
852 | 854 | } |
853 | 855 |
|
| 856 | +func TestPRCreate_survey_defaults_monocommit_template(t *testing.T) { |
| 857 | + http := initFakeHTTP() |
| 858 | + defer http.Verify(t) |
| 859 | + |
| 860 | + http.Register(httpmock.GraphQL(`query RepositoryNetwork\b`), httpmock.StringResponse(httpmock.RepoNetworkStubResponse("OWNER", "REPO", "master", "WRITE"))) |
| 861 | + http.Register(httpmock.GraphQL(`query RepositoryFindFork\b`), httpmock.StringResponse(` |
| 862 | + { "data": { "repository": { "forks": { "nodes": [ |
| 863 | + ] } } } } |
| 864 | + `)) |
| 865 | + http.Register(httpmock.GraphQL(`query PullRequestForBranch\b`), httpmock.StringResponse(` |
| 866 | + { "data": { "repository": { "pullRequests": { "nodes" : [ |
| 867 | + ] } } } } |
| 868 | + `)) |
| 869 | + http.Register(httpmock.GraphQL(`mutation PullRequestCreate\b`), httpmock.GraphQLMutation(` |
| 870 | + { "data": { "createPullRequest": { "pullRequest": { |
| 871 | + "URL": "https://github.com/OWNER/REPO/pull/12" |
| 872 | + } } } } |
| 873 | + `, func(inputs map[string]interface{}) { |
| 874 | + eq(t, inputs["repositoryId"], "REPOID") |
| 875 | + eq(t, inputs["title"], "the sky above the port") |
| 876 | + eq(t, inputs["body"], "was the color of a television\n\n... turned to a dead channel") |
| 877 | + eq(t, inputs["baseRefName"], "master") |
| 878 | + eq(t, inputs["headRefName"], "feature") |
| 879 | + })) |
| 880 | + |
| 881 | + cs, cmdTeardown := test.InitCmdStubber() |
| 882 | + defer cmdTeardown() |
| 883 | + |
| 884 | + tmpdir, err := ioutil.TempDir("", "gh-cli") |
| 885 | + if err != nil { |
| 886 | + t.Fatal(err) |
| 887 | + } |
| 888 | + defer os.RemoveAll(tmpdir) |
| 889 | + |
| 890 | + templateFp := path.Join(tmpdir, ".github/PULL_REQUEST_TEMPLATE.md") |
| 891 | + _ = os.MkdirAll(path.Dir(templateFp), 0700) |
| 892 | + _ = ioutil.WriteFile(templateFp, []byte("... turned to a dead channel"), 0700) |
| 893 | + |
| 894 | + cs.Stub("") // git config --get-regexp (determineTrackingBranch) |
| 895 | + cs.Stub("") // git show-ref --verify (determineTrackingBranch) |
| 896 | + cs.Stub("") // git status |
| 897 | + cs.Stub("1234567890,the sky above the port") // git log |
| 898 | + cs.Stub("was the color of a television") // git show |
| 899 | + cs.Stub(tmpdir) // git rev-parse |
| 900 | + cs.Stub("") // git push |
| 901 | + |
| 902 | + as, surveyTeardown := prompt.InitAskStubber() |
| 903 | + defer surveyTeardown() |
| 904 | + |
| 905 | + as.Stub([]*prompt.QuestionStub{ |
| 906 | + { |
| 907 | + Name: "title", |
| 908 | + Default: true, |
| 909 | + }, |
| 910 | + { |
| 911 | + Name: "body", |
| 912 | + Default: true, |
| 913 | + }, |
| 914 | + }) |
| 915 | + as.Stub([]*prompt.QuestionStub{ |
| 916 | + { |
| 917 | + Name: "confirmation", |
| 918 | + Value: 0, |
| 919 | + }, |
| 920 | + }) |
| 921 | + |
| 922 | + output, err := runCommand(http, nil, "feature", true, ``) |
| 923 | + eq(t, err, nil) |
| 924 | + eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n") |
| 925 | +} |
| 926 | + |
854 | 927 | func TestPRCreate_survey_autofill_nontty(t *testing.T) { |
855 | 928 | http := initFakeHTTP() |
856 | 929 | defer http.Verify(t) |
|
0 commit comments