support preview in browser for issue create
This commit is contained in:
parent
d8cbb6a6a7
commit
3468a46521
1 changed files with 34 additions and 11 deletions
|
|
@ -3,6 +3,7 @@ package command
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -308,6 +309,8 @@ func issueCreate(cmd *cobra.Command, args []string) error {
|
|||
return fmt.Errorf("the '%s/%s' repository has disabled issues", baseRepo.RepoOwner(), baseRepo.RepoName())
|
||||
}
|
||||
|
||||
action := SubmitAction
|
||||
|
||||
title, err := cmd.Flags().GetString("title")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not parse title")
|
||||
|
|
@ -320,13 +323,16 @@ func issueCreate(cmd *cobra.Command, args []string) error {
|
|||
interactive := title == "" || body == ""
|
||||
|
||||
if interactive {
|
||||
// TODO handle tb.Action
|
||||
tb, err := titleBodySurvey(cmd, title, body, templateFiles)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not collect title and/or body")
|
||||
}
|
||||
|
||||
if tb == nil {
|
||||
// editing was canceled, we can just leave
|
||||
action = tb.Action
|
||||
|
||||
if tb.Action == CancelAction {
|
||||
// TODO print something
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -337,17 +343,34 @@ func issueCreate(cmd *cobra.Command, args []string) error {
|
|||
body = tb.Body
|
||||
}
|
||||
}
|
||||
params := map[string]interface{}{
|
||||
"title": title,
|
||||
"body": body,
|
||||
|
||||
if action == PreviewAction {
|
||||
openURL := fmt.Sprintf(
|
||||
"https://github.com/%s/%s/issues/new/?title=%s&body=%s",
|
||||
baseRepo.RepoOwner(),
|
||||
baseRepo.RepoName(),
|
||||
url.QueryEscape(title),
|
||||
url.QueryEscape(body),
|
||||
)
|
||||
// TODO could exceed max url length for explorer
|
||||
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL)
|
||||
return utils.OpenInBrowser(openURL)
|
||||
} else if action == SubmitAction {
|
||||
params := map[string]interface{}{
|
||||
"title": title,
|
||||
"body": body,
|
||||
}
|
||||
|
||||
newIssue, err := api.IssueCreate(apiClient, repo, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintln(cmd.OutOrStdout(), newIssue.URL)
|
||||
} else {
|
||||
panic("Unreachable state")
|
||||
}
|
||||
|
||||
newIssue, err := api.IssueCreate(apiClient, repo, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintln(cmd.OutOrStdout(), newIssue.URL)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue