X Tutup
Skip to content

Commit af46fcb

Browse files
committed
--fill for pr create
1 parent 2d90c09 commit af46fcb

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

command/pr_create.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,18 @@ func prCreate(cmd *cobra.Command, _ []string) error {
111111
return fmt.Errorf("could not parse web: %q", err)
112112
}
113113

114+
autofill, err := cmd.Flags().GetBool("fill")
115+
if err != nil {
116+
return fmt.Errorf("could not parse fill: %q", err)
117+
}
118+
114119
action := SubmitAction
115120
if isWeb {
116121
action = PreviewAction
122+
} else if autofill {
123+
action = SubmitAction
124+
title = defs.Title
125+
body = defs.Body
117126
} else {
118127
fmt.Fprintf(colorableErr(cmd), "\nCreating pull request for %s into %s in %s\n\n",
119128
utils.Cyan(headBranch),
@@ -122,7 +131,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
122131
}
123132

124133
// TODO: only drop into interactive mode if stdin & stdout are a tty
125-
if !isWeb && (title == "" || body == "") {
134+
if !isWeb && !autofill && (title == "" || body == "") {
126135
var templateFiles []string
127136
if rootDir, err := git.ToplevelDir(); err == nil {
128137
// TODO: figure out how to stub this in tests
@@ -276,4 +285,5 @@ func init() {
276285
prCreateCmd.Flags().StringP("base", "B", "",
277286
"The branch into which you want your code merged")
278287
prCreateCmd.Flags().BoolP("web", "w", false, "Open the web browser to create a pull request")
288+
prCreateCmd.Flags().BoolP("fill", "f", false, "Do not prompt for title/body and just use commit info")
279289
}

command/pr_create_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,51 @@ func TestPRCreate_survey_defaults_monocommit(t *testing.T) {
322322

323323
eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n")
324324
}
325+
326+
func TestPRCreate_survey_autofill(t *testing.T) {
327+
initBlankContext("OWNER/REPO", "feature")
328+
http := initFakeHTTP()
329+
http.StubRepoResponse("OWNER", "REPO")
330+
http.StubResponse(200, bytes.NewBufferString(`
331+
{ "data": { "createPullRequest": { "pullRequest": {
332+
"URL": "https://github.com/OWNER/REPO/pull/12"
333+
} } } }
334+
`))
335+
336+
cs, cmdTeardown := initCmdStubber()
337+
defer cmdTeardown()
338+
339+
cs.Stub("") // git status
340+
cs.Stub("1234567890,the sky above the port") // git log
341+
cs.Stub("was the color of a television, turned to a dead channel") // git show
342+
cs.Stub("") // git rev-parse
343+
cs.Stub("") // git push
344+
cs.Stub("") // browser open
345+
346+
output, err := RunCommand(prCreateCmd, `pr create -f`)
347+
eq(t, err, nil)
348+
349+
bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body)
350+
reqBody := struct {
351+
Variables struct {
352+
Input struct {
353+
RepositoryID string
354+
Title string
355+
Body string
356+
BaseRefName string
357+
HeadRefName string
358+
}
359+
}
360+
}{}
361+
json.Unmarshal(bodyBytes, &reqBody)
362+
363+
expectedBody := "was the color of a television, turned to a dead channel"
364+
365+
eq(t, reqBody.Variables.Input.RepositoryID, "REPOID")
366+
eq(t, reqBody.Variables.Input.Title, "the sky above the port")
367+
eq(t, reqBody.Variables.Input.Body, expectedBody)
368+
eq(t, reqBody.Variables.Input.BaseRefName, "master")
369+
eq(t, reqBody.Variables.Input.HeadRefName, "feature")
370+
371+
eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n")
372+
}

0 commit comments

Comments
 (0)
X Tutup