Conversation
|
Woo this looks awesome! One tiny nit question: Would it be possible to make this tweak above to the Body prompt? Instead of putting the editor in parenthesis, we could say |
|
@ampinsk absolutely! i actually totally meant to do this and just forgot. |
mislav
left a comment
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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"There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Could we avoid printing the full URL and just print the portion without the query string, since the query string might become large?
There was a problem hiding this comment.
I left the scheme out while I was at it since without the query string it's not a URL worth clicking on anyway.
command/pr_create.go
Outdated
| url.QueryEscape(title), | ||
| url.QueryEscape(body), | ||
| ) | ||
| // TODO maybe do something about -d being discarded when previewing |
There was a problem hiding this comment.
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.
command/title_body_survey.go
Outdated
| _cancel = iota | ||
| PreviewAction Action = iota | ||
| SubmitAction Action = iota | ||
| CancelAction Action = iota |
There was a problem hiding this comment.
Minor syntax nit: I think that due to how iota works, you can omit = iota from all but the first line?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Nice use of type alias to improve communication!
| confirmed = true | ||
| case _unconfirmed: | ||
| continue | ||
| case _cancel: |
There was a problem hiding this comment.
Great job incrementally improving code style in this PR 🏆
| if err != nil { | ||
| return "", err | ||
| } | ||
| if r == 'e' { |
There was a problem hiding this comment.
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/orinternal/, since it doesn't seem like this technically needs to be in thecommandpackage; i.e. it doesn't access any of the other parts ofcommand. - Add comments pointing out to parts that were edited.
Does that sounds reasonable?
command/editor.go
Outdated
| {{- 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"}} |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Was it intentional that "Preview in browser" is the first (default) option rather than 2nd like in design mockups?
There was a problem hiding this comment.
yeah, we talked about it out of band.
Relates to cli#231 Add the HookRegistry and a small subset of events (AgentInitializedEvent, StartRequestEvent, EndRequestEvent) as a POC for how hooks will work.
Closes #70
This PR:
Changes the UI for opening an editor. Instead of just
enter to open editorwith no way to skip,you now press
eto open the editor andenterto skip the body prompt. This required bringingin some of
survey's code so it could be extended and tweaked (about 150 lines).Tweaks the final options from
Yes,Edit, andCanceltoPreview in Browser,Submit, andCancel. This means that if someone wants to just get to the browser but didn't specify--webthey 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.
A caveat is that if a user specifies
--draftand then previews in browser, that info is lost. There is no way to default the PR create page to making a draft PR, unfortunately.