@@ -16,6 +16,7 @@ import (
1616 "github.com/cli/cli/pkg/cmdutil"
1717 "github.com/cli/cli/pkg/httpmock"
1818 "github.com/cli/cli/pkg/iostreams"
19+ "github.com/cli/cli/pkg/prompt"
1920 "github.com/cli/cli/test"
2021 "github.com/google/shlex"
2122 "github.com/stretchr/testify/assert"
@@ -29,6 +30,10 @@ func eq(t *testing.T, got interface{}, expected interface{}) {
2930}
3031
3132func runCommand (rt http.RoundTripper , isTTY bool , cli string ) (* test.CmdOut , error ) {
33+ return runCommandWithRootDirOverridden (rt , isTTY , cli , "" )
34+ }
35+
36+ func runCommandWithRootDirOverridden (rt http.RoundTripper , isTTY bool , cli string , rootDir string ) (* test.CmdOut , error ) {
3237 io , _ , stdout , stderr := iostreams .Test ()
3338 io .SetStdoutTTY (isTTY )
3439 io .SetStdinTTY (isTTY )
@@ -47,7 +52,10 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
4752 },
4853 }
4954
50- cmd := NewCmdCreate (factory , nil )
55+ cmd := NewCmdCreate (factory , func (opts * CreateOptions ) error {
56+ opts .RootDirOverride = rootDir
57+ return createRun (opts )
58+ })
5159
5260 argv , err := shlex .Split (cli )
5361 if err != nil {
@@ -126,6 +134,67 @@ func TestIssueCreate(t *testing.T) {
126134 eq (t , output .String (), "https://github.com/OWNER/REPO/issues/12\n " )
127135}
128136
137+ func TestIssueCreate_nonLegacyTemplate (t * testing.T ) {
138+ http := & httpmock.Registry {}
139+ defer http .Verify (t )
140+
141+ http .StubResponse (200 , bytes .NewBufferString (`
142+ { "data": { "repository": {
143+ "id": "REPOID",
144+ "hasIssuesEnabled": true
145+ } } }
146+ ` ))
147+ http .StubResponse (200 , bytes .NewBufferString (`
148+ { "data": { "createIssue": { "issue": {
149+ "URL": "https://github.com/OWNER/REPO/issues/12"
150+ } } } }
151+ ` ))
152+
153+ as , teardown := prompt .InitAskStubber ()
154+ defer teardown ()
155+ as .Stub ([]* prompt.QuestionStub {
156+ {
157+ Name : "index" ,
158+ Value : 1 ,
159+ },
160+ })
161+ as .Stub ([]* prompt.QuestionStub {
162+ {
163+ Name : "body" ,
164+ Default : true ,
165+ },
166+ })
167+ as .Stub ([]* prompt.QuestionStub {
168+ {
169+ Name : "confirmation" ,
170+ Value : 0 ,
171+ },
172+ })
173+
174+ output , err := runCommandWithRootDirOverridden (http , true , `-t hello` , "./repoWithNonLegacyIssueTemplates" )
175+ if err != nil {
176+ t .Errorf ("error running command `issue create`: %v" , err )
177+ }
178+
179+ bodyBytes , _ := ioutil .ReadAll (http .Requests [1 ].Body )
180+ reqBody := struct {
181+ Variables struct {
182+ Input struct {
183+ RepositoryID string
184+ Title string
185+ Body string
186+ }
187+ }
188+ }{}
189+ _ = json .Unmarshal (bodyBytes , & reqBody )
190+
191+ eq (t , reqBody .Variables .Input .RepositoryID , "REPOID" )
192+ eq (t , reqBody .Variables .Input .Title , "hello" )
193+ eq (t , reqBody .Variables .Input .Body , "I have a suggestion for an enhancement" )
194+
195+ eq (t , output .String (), "https://github.com/OWNER/REPO/issues/12\n " )
196+ }
197+
129198func TestIssueCreate_metadata (t * testing.T ) {
130199 http := & httpmock.Registry {}
131200 defer http .Verify (t )
0 commit comments