X Tutup
Skip to content

Commit ef52376

Browse files
author
vilmibm
committed
fix survey invocation
1 parent 9a20719 commit ef52376

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

pkg/cmd/issue/create/create_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ func TestIssueCreate_nonLegacyTemplate(t *testing.T) {
153153
},
154154
})
155155
// body
156-
as.StubOneDefault()
156+
as.Stub([]*prompt.QuestionStub{
157+
{
158+
Name: "Body",
159+
Default: true,
160+
},
161+
}) // body
157162
// confirm
158163
as.Stub([]*prompt.QuestionStub{
159164
{

pkg/cmd/pr/create/create_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,12 @@ func TestPRCreate_nonLegacyTemplate(t *testing.T) {
433433
Value: 0,
434434
},
435435
}) // template
436-
as.StubOneDefault() // body
436+
as.Stub([]*prompt.QuestionStub{
437+
{
438+
Name: "Body",
439+
Default: true,
440+
},
441+
}) // body
437442
as.Stub([]*prompt.QuestionStub{
438443
{
439444
Name: "confirmation",

pkg/cmd/pr/shared/survey.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,25 @@ func BodySurvey(state *IssueMetadataState, templateContent, editorCommand string
170170
state.Body += templateContent
171171
}
172172

173-
p := &surveyext.GhEditor{
174-
BlankAllowed: true,
175-
EditorCommand: editorCommand,
176-
Editor: &survey.Editor{
177-
Message: "Body",
178-
FileName: "*.md",
179-
Default: state.Body,
180-
HideDefault: true,
181-
AppendDefault: true,
173+
// TODO should just be an AskOne but ran into problems with the stubber
174+
qs := []*survey.Question{
175+
{
176+
Name: "Body",
177+
Prompt: &surveyext.GhEditor{
178+
BlankAllowed: true,
179+
EditorCommand: editorCommand,
180+
Editor: &survey.Editor{
181+
Message: "Body",
182+
FileName: "*.md",
183+
Default: state.Body,
184+
HideDefault: true,
185+
AppendDefault: true,
186+
},
187+
},
182188
},
183189
}
184190

185-
err := prompt.SurveyAskOne(p, state)
191+
err := prompt.SurveyAsk(qs, state)
186192
if err != nil {
187193
return err
188194
}
@@ -191,12 +197,18 @@ func BodySurvey(state *IssueMetadataState, templateContent, editorCommand string
191197
}
192198

193199
func TitleSurvey(state *IssueMetadataState) error {
194-
p := &survey.Input{
195-
Message: "Title",
196-
Default: state.Title,
200+
// TODO should just be an AskOne but ran into problems with the stubber
201+
qs := []*survey.Question{
202+
{
203+
Name: "Title",
204+
Prompt: &survey.Input{
205+
Message: "Title",
206+
Default: state.Title,
207+
},
208+
},
197209
}
198210

199-
err := prompt.SurveyAskOne(p, state)
211+
err := prompt.SurveyAsk(qs, state)
200212
if err != nil {
201213
return err
202214
}

pkg/prompt/stubber.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func InitAskStubber() (*AskStubber, func()) {
3131
}
3232
stubbedPrompt := as.StubOnes[count]
3333
if stubbedPrompt.Default {
34+
// TODO this is failing for basic AskOne invocations with a string result.
3435
defaultValue := reflect.ValueOf(p).Elem().FieldByName("Default")
3536
_ = core.WriteAnswer(response, "", defaultValue)
3637
} else {

0 commit comments

Comments
 (0)
X Tutup