Interactive template selection test for issue create
This commit is contained in:
parent
f1ea794bf1
commit
d0c2c81f2d
4 changed files with 93 additions and 3 deletions
|
|
@ -23,6 +23,8 @@ type CreateOptions struct {
|
||||||
IO *iostreams.IOStreams
|
IO *iostreams.IOStreams
|
||||||
BaseRepo func() (ghrepo.Interface, error)
|
BaseRepo func() (ghrepo.Interface, error)
|
||||||
|
|
||||||
|
RootDirOverride string
|
||||||
|
|
||||||
RepoOverride string
|
RepoOverride string
|
||||||
WebMode bool
|
WebMode bool
|
||||||
|
|
||||||
|
|
@ -94,9 +96,10 @@ func createRun(opts *CreateOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var nonLegacyTemplateFiles []string
|
var nonLegacyTemplateFiles []string
|
||||||
if opts.RepoOverride == "" {
|
if opts.RootDirOverride != "" {
|
||||||
|
nonLegacyTemplateFiles = githubtemplate.FindNonLegacy(opts.RootDirOverride, "ISSUE_TEMPLATE")
|
||||||
|
} else if opts.RepoOverride == "" {
|
||||||
if rootDir, err := git.ToplevelDir(); err == nil {
|
if rootDir, err := git.ToplevelDir(); err == nil {
|
||||||
// TODO: figure out how to stub this in tests
|
|
||||||
nonLegacyTemplateFiles = githubtemplate.FindNonLegacy(rootDir, "ISSUE_TEMPLATE")
|
nonLegacyTemplateFiles = githubtemplate.FindNonLegacy(rootDir, "ISSUE_TEMPLATE")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"github.com/cli/cli/pkg/cmdutil"
|
"github.com/cli/cli/pkg/cmdutil"
|
||||||
"github.com/cli/cli/pkg/httpmock"
|
"github.com/cli/cli/pkg/httpmock"
|
||||||
"github.com/cli/cli/pkg/iostreams"
|
"github.com/cli/cli/pkg/iostreams"
|
||||||
|
"github.com/cli/cli/pkg/prompt"
|
||||||
"github.com/cli/cli/test"
|
"github.com/cli/cli/test"
|
||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
@ -29,6 +30,10 @@ func eq(t *testing.T, got interface{}, expected interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
|
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
|
||||||
|
return runCommandWithRootDirOverridden(rt, isTTY, cli, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func runCommandWithRootDirOverridden(rt http.RoundTripper, isTTY bool, cli string, rootDir string) (*test.CmdOut, error) {
|
||||||
io, _, stdout, stderr := iostreams.Test()
|
io, _, stdout, stderr := iostreams.Test()
|
||||||
io.SetStdoutTTY(isTTY)
|
io.SetStdoutTTY(isTTY)
|
||||||
io.SetStdinTTY(isTTY)
|
io.SetStdinTTY(isTTY)
|
||||||
|
|
@ -47,7 +52,10 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := NewCmdCreate(factory, nil)
|
cmd := NewCmdCreate(factory, func(opts *CreateOptions) error {
|
||||||
|
opts.RootDirOverride = rootDir
|
||||||
|
return createRun(opts)
|
||||||
|
})
|
||||||
|
|
||||||
argv, err := shlex.Split(cli)
|
argv, err := shlex.Split(cli)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -126,6 +134,67 @@ func TestIssueCreate(t *testing.T) {
|
||||||
eq(t, output.String(), "https://github.com/OWNER/REPO/issues/12\n")
|
eq(t, output.String(), "https://github.com/OWNER/REPO/issues/12\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssueCreate_nonLegacyTemplate(t *testing.T) {
|
||||||
|
http := &httpmock.Registry{}
|
||||||
|
defer http.Verify(t)
|
||||||
|
|
||||||
|
http.StubResponse(200, bytes.NewBufferString(`
|
||||||
|
{ "data": { "repository": {
|
||||||
|
"id": "REPOID",
|
||||||
|
"hasIssuesEnabled": true
|
||||||
|
} } }
|
||||||
|
`))
|
||||||
|
http.StubResponse(200, bytes.NewBufferString(`
|
||||||
|
{ "data": { "createIssue": { "issue": {
|
||||||
|
"URL": "https://github.com/OWNER/REPO/issues/12"
|
||||||
|
} } } }
|
||||||
|
`))
|
||||||
|
|
||||||
|
as, teardown := prompt.InitAskStubber()
|
||||||
|
defer teardown()
|
||||||
|
as.Stub([]*prompt.QuestionStub{
|
||||||
|
{
|
||||||
|
Name: "index",
|
||||||
|
Value: 1,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
as.Stub([]*prompt.QuestionStub{
|
||||||
|
{
|
||||||
|
Name: "body",
|
||||||
|
Default: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
as.Stub([]*prompt.QuestionStub{
|
||||||
|
{
|
||||||
|
Name: "confirmation",
|
||||||
|
Value: 0,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
output, err := runCommandWithRootDirOverridden(http, true, `-t hello`, "./repoWithNonLegacyIssueTemplates")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("error running command `issue create`: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body)
|
||||||
|
reqBody := struct {
|
||||||
|
Variables struct {
|
||||||
|
Input struct {
|
||||||
|
RepositoryID string
|
||||||
|
Title string
|
||||||
|
Body string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}{}
|
||||||
|
_ = json.Unmarshal(bodyBytes, &reqBody)
|
||||||
|
|
||||||
|
eq(t, reqBody.Variables.Input.RepositoryID, "REPOID")
|
||||||
|
eq(t, reqBody.Variables.Input.Title, "hello")
|
||||||
|
eq(t, reqBody.Variables.Input.Body, "I have a suggestion for an enhancement")
|
||||||
|
|
||||||
|
eq(t, output.String(), "https://github.com/OWNER/REPO/issues/12\n")
|
||||||
|
}
|
||||||
|
|
||||||
func TestIssueCreate_metadata(t *testing.T) {
|
func TestIssueCreate_metadata(t *testing.T) {
|
||||||
http := &httpmock.Registry{}
|
http := &httpmock.Registry{}
|
||||||
defer http.Verify(t)
|
defer http.Verify(t)
|
||||||
|
|
|
||||||
9
pkg/cmd/issue/create/repoWithNonLegacyIssueTemplates/.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
9
pkg/cmd/issue/create/repoWithNonLegacyIssueTemplates/.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Report a bug or unexpected behavior
|
||||||
|
title: Bug Report
|
||||||
|
labels: bug
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
I wanna report a bug
|
||||||
9
pkg/cmd/issue/create/repoWithNonLegacyIssueTemplates/.github/ISSUE_TEMPLATE/enhancement.md
vendored
Normal file
9
pkg/cmd/issue/create/repoWithNonLegacyIssueTemplates/.github/ISSUE_TEMPLATE/enhancement.md
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
name: Submit a request
|
||||||
|
about: Propose an improvement
|
||||||
|
title: Enhancement Proposal
|
||||||
|
labels: enhancement
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
I have a suggestion for an enhancement
|
||||||
Loading…
Add table
Add a link
Reference in a new issue