Skip to content

PR/Issue create flow tweaks#231

Merged
vilmibm merged 13 commits intomasterfrom
create-flows
Jan 16, 2020
Merged

PR/Issue create flow tweaks#231
vilmibm merged 13 commits intomasterfrom
create-flows

Conversation

@vilmibm
Copy link
Copy Markdown
Contributor

@vilmibm vilmibm commented Jan 15, 2020

Closes #70

This PR:

  • Changes the UI for opening an editor. Instead of just enter to open editor with no way to skip,
    you now press e to open the editor and enter to skip the body prompt. This required bringing
    in some of survey's code so it could be extended and tweaked (about 150 lines).

    Creating pull request for create-flows into master in github/gh-cli
    
    ? Title cool pr
    ? Body (/usr/bin/vim) [e: launch editor][enter: skip for now] 
    
  • Tweaks the final options from Yes, Edit, and Cancel to Preview in Browser, Submit, and
    Cancel. This means that if someone wants to just get to the browser but didn't specify --web
    they can just enter through the prompts and then edit in the browser. It also means that even if
    you like drafting in the terminal/editor you can continue to the browser to set labels and
    assignees before submitting.

    Creating pull request for create-flows into master in github/gh-cli
    
    ? Title cool pr
    ? Body (/usr/bin/vim) <Received>
    ? What's next?  [Use arrows to move, type to filter]
    > Preview in browser
      Submit
      Cancel
    

A caveat is that if a user specifies --draft and then previews in browser, that info is lost. There is no way to default the PR create page to making a draft PR, unfortunately.

@ampinsk
Copy link
Copy Markdown

ampinsk commented Jan 15, 2020

Woo this looks awesome! One tiny nit question:

Creating pull request for create-flows into master in github/gh-cli

? Title cool pr
? Body [e: launch vim][enter: skip for now] 

Would it be possible to make this tweak above to the Body prompt? Instead of putting the editor in parenthesis, we could say Open in [default editor name]

@vilmibm
Copy link
Copy Markdown
Contributor Author

vilmibm commented Jan 15, 2020

@ampinsk absolutely! i actually totally meant to do this and just forgot.

Copy link
Copy Markdown
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks great! I feel an overall improvement to how we handle survey prompts.

baseRepo.RepoOwner(),
baseRepo.RepoName(),
url.QueryEscape(title),
url.QueryEscape(body),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could potentially use url.Values to construct the query string so you don't have to implement the serialization yourself:

v := url.Values{}
v.Set("title", title)
v.Set("body", body)
v.Encode() //=> "title=MYTITLE&body=HELLO"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good to know about but I don't really have a problem with the way it is now; it's more readable for me than using url.Values{}. I could see url.Values{} being great for a longer or more complicated set of query parameters, though.

url.QueryEscape(title),
url.QueryEscape(body),
)
// TODO could exceed max url length for explorer
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good forward thinking!

Not much we can do in that case, I think. Let's wait to see if this becomes a problem.

command/issue.go Outdated
url.QueryEscape(body),
)
// TODO could exceed max url length for explorer
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid printing the full URL and just print the portion without the query string, since the query string might become large?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the scheme out while I was at it since without the query string it's not a URL worth clicking on anyway.

url.QueryEscape(title),
url.QueryEscape(body),
)
// TODO maybe do something about -d being discarded when previewing
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to concede that some fields won't be possible to pass over query parameters. Since the user will be presented with the full UI to choose all this themselves, I don't think we need to support --draft (nor --labels, --assignees, etc. in the future) in this mode.

_cancel = iota
PreviewAction Action = iota
SubmitAction Action = iota
CancelAction Action = iota
Copy link
Copy Markdown
Contributor

@mislav mislav Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor syntax nit: I think that due to how iota works, you can omit = iota from all but the first line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can but I really hate that about iota ;_; as it seems to be standard Go style though I'll suck it up and do it.

"github.com/spf13/cobra"
)

type Action int
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of type alias to improve communication!

confirmed = true
case _unconfirmed:
continue
case _cancel:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job incrementally improving code style in this PR 🏆

if err != nil {
return "", err
}
if r == 'e' {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that you inlined this whole file just to be able to change a few lines such as this one. I'm guessing that Survey didn't support creating the kind of prompt that we wanted.

I wonder how we can communicate that most of the code in this file isn't written by us (so we avoid style-reviewing it), but point out the parts that we edited? My idea:

  • Extract this into its own package under pkg/ or internal/, since it doesn't seem like this technically needs to be in the command package; i.e. it doesn't access any of the other parts of command.
  • Add comments pointing out to parts that were edited.

Does that sounds reasonable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like this!

{{- else }}
{{- if and .Help (not .ShowHelp)}}{{color "cyan"}}[{{ .Config.HelpInput }} for help]{{color "reset"}} {{end}}
{{- if and .Default (not .HideDefault)}}{{color "white"}}({{.Default}}) {{color "reset"}}{{end}}
{{- color "cyan"}}[e: launch editor][enter: skip for now] {{color "reset"}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that this presentation doesn't match the design mockup: [E to launch editor, Enter to skip]

I feel that we should lean to being human-readable rather than separating mutually exclusive options in separate [...]; what do you think?

Perhaps we could also consider indicating that the E in E to launch editor is a key to be pressed? E.g. (e) or <e>

Options: []string{
"Yes",
"Edit",
"Preview in browser",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it intentional that "Preview in browser" is the first (default) option rather than 2nd like in design mockups?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we talked about it out of band.

@vilmibm vilmibm merged commit b30ea6b into master Jan 16, 2020
@mislav mislav deleted the create-flows branch January 22, 2020 23:00
mislav pushed a commit that referenced this pull request Jan 23, 2020
PR/Issue create flow tweaks
Stonre pushed a commit to Stonre/strands-fork that referenced this pull request Jul 21, 2025
Relates to cli#231

Add the HookRegistry and a small subset of events (AgentInitializedEvent, StartRequestEvent, EndRequestEvent) as a POC for how hooks will work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iterate on current pr create and issue create flows

3 participants