X Tutup
Skip to content

Commit 13c3c65

Browse files
castaneaimislav
authored andcommitted
Add pr create --body-file flag
1 parent 04dcb32 commit 13c3c65

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pkg/cmd/pr/create/create.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package create
33
import (
44
"errors"
55
"fmt"
6+
"io/ioutil"
67
"net/http"
78
"net/url"
89
"regexp"
@@ -81,6 +82,8 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
8182
Branch: f.Branch,
8283
}
8384

85+
var bodyFile string
86+
8487
cmd := &cobra.Command{
8588
Use: "create",
8689
Short: "Create a pull request",
@@ -133,6 +136,21 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
133136
return errors.New("the `--no-maintainer-edit` flag is not supported with `--web`")
134137
}
135138

139+
if bodyFile != "" {
140+
var b []byte
141+
var err error
142+
if bodyFile == "-" {
143+
b, err = ioutil.ReadAll(opts.IO.In)
144+
} else {
145+
b, err = ioutil.ReadFile(bodyFile)
146+
}
147+
if err != nil {
148+
return err
149+
}
150+
opts.Body = string(b)
151+
opts.BodyProvided = true
152+
}
153+
136154
if runF != nil {
137155
return runF(opts)
138156
}
@@ -144,6 +162,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
144162
fl.BoolVarP(&opts.IsDraft, "draft", "d", false, "Mark pull request as a draft")
145163
fl.StringVarP(&opts.Title, "title", "t", "", "Title for the pull request")
146164
fl.StringVarP(&opts.Body, "body", "b", "", "Body for the pull request")
165+
fl.StringVarP(&bodyFile, "body-file", "F", "", "Read body from file. Use - to read the body from the standard input.")
147166
fl.StringVarP(&opts.BaseBranch, "base", "B", "", "The `branch` into which you want your code merged")
148167
fl.StringVarP(&opts.HeadBranch, "head", "H", "", "The `branch` that contains commits for your pull request (default: current branch)")
149168
fl.BoolVarP(&opts.WebMode, "web", "w", false, "Open the web browser to create a pull request")

0 commit comments

Comments
 (0)
X Tutup