8000 Respect title & body from arguments to `pr create -w` by mislav · Pull Request #523 · cli/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Respect title & body from arguments to pr create -w #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
47 changes: 26 additions & 21 deletions command/pr_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,21 @@ func prCreate(cmd *cobra.Command, _ []string) error {
headBranchLabel = fmt.Sprintf("%s:%s", headRepo.RepoOwner(), headBranch)
}

compareURL := fmt.Sprintf(
"https://github.com/%s/compare/%s...%s?expand=1",
ghrepo.FullName(baseRepo),
baseBranch,
headBranchLabel,
)
title, err := cmd.Flags().GetString("title")
if err != nil {
return fmt.Errorf("could not parse title: %w", err)
}
body, err := cmd.Flags().GetString("body")
if err != nil {
return fmt.Errorf("could not parse body: %w", err)
}

isWeb, err := cmd.Flags().GetBool("web")
if err != nil {
return fmt.Errorf("could not parse web: %q", err)
}
if isWeb {
compareURL := generateCompareURL(baseRepo, baseBranch, headBranchLabel, title, body)
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", displayURL(compareURL))
return utils.OpenInBrowser(compareURL)
}
Expand All @@ -133,15 +136,6 @@ func prCreate(cmd *cobra.Command, _ []string) error {
utils.Cyan(baseBranch),
ghrepo.FullName(baseRepo))

title, err := cmd.Flags().GetString("title")
if err != nil {
return fmt.Errorf("could not parse title: %w", err)
}
body, err := cmd.Flags().GetString("body")
if err != nil {
return fmt.Errorf("could not parse body: %w", err)
}

action := SubmitAction

interactive := title == "" || body == ""
Expand Down Expand Up @@ -203,12 +197,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {

fmt.Fprintln(cmd.OutOrStdout(), pr.URL)
} else if action == PreviewAction {
openURL := fmt.Sprintf(
"%s&title=%s&body=%s",
compareURL,
url.QueryEscape(title),
url.QueryEscape(body),
)
openURL := generateCompareURL(baseRepo, baseBranch, headBranchLabel, title, body)
// TODO could exceed max url length for explorer
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", displayURL(openURL))
return utils.OpenInBrowser(openURL)
Expand All @@ -220,6 +209,22 @@ func prCreate(cmd *cobra.Command, _ []string) error {

}

func generateCompareURL(r ghrepo.Interface, base, head, title, body string) string {
u := fmt.Sprintf(
"https://github.com/%s/compare/%s...%s?expand=1",
ghrepo.FullName(r),
base,
head,
)
if title != "" {
u += "&title=" + url.QueryEscape(title)
}
if body != "" {
u += "&body=" + url.QueryEscape(body)
}
return u
}

var prCreateCmd = &cobra.Command{
Use: "create",
Short: "Create a pull request",
Expand Down
0