Conversation
mislav
left a comment
There was a problem hiding this comment.
It looks like, right now, a review without comment is added like so gh pr review --approve and the review with comment is gh pr review --approve='ship it!'. Since string flags that are optional are both tricky to implement (requires some flags juggling) and tricky for our users to understand, could we consider passing the comment body in a similar manner as to issue/pr create? e.g.
gh pr review --approve- wizard offering a text editorgh pr review --approve --body 'ole'- passed body skips the wizard
|
|
||
| "github.com/cli/cli/internal/ghrepo" | ||
| "github.com/shurcooL/githubv4" | ||
|
|
There was a problem hiding this comment.
Nit: removing this blank line would probably group & sort import statements correctly again, ironing out this diff since it doesn't seem like any imports actually changed
There was a problem hiding this comment.
I did this intentionally but I guess subconsciously; it's habit from Python where you split imports into standard library, 3rd party, and internal-to-project paragraphs.
| body := githubv4.String(input.Body) | ||
|
|
||
| gqlInput := githubv4.AddPullRequestReviewInput{ | ||
| PullRequestID: pr.ID, |
There was a problem hiding this comment.
This made me realize that passing an ID as a string works in a mutation without casting it to a githubv4.ID, which is mildly surprising because githubv4 requires all other parameters be cast to a specific githubv4.* type 🤔
There was a problem hiding this comment.
it surprised me, too; I did it because we're doing it elsewhere in the codebase.
command/pr_review.go
Outdated
| } | ||
|
|
||
| if found != 1 { | ||
| return nil, errors.New("need exactly one of approve, request-changes, or comment") |
There was a problem hiding this comment.
Could we add -- so it clear that these are flags?
| return nil, errors.New("need exactly one of approve, request-changes, or comment") | |
| return nil, errors.New("need exactly one of --approve, --request-changes, or --comment") |
| state = api.ReviewComment | ||
| } | ||
|
|
||
| if found != 1 { |
There was a problem hiding this comment.
Nice way to enforce mutually-exclusive flags!
command/pr_review.go
Outdated
| prArg := "" | ||
|
|
||
| if len(args) == 0 { | ||
| prNum, _, err := prSelectorForCurrentBranch(ctx, baseRepo) |
There was a problem hiding this comment.
prNum might be zero in case the specific number for the current branch could not be detected, so then the 2nd argument will have the branch selector for lookup (e.g. mislav:patch-1) that you can then use with PullRequestForBranch
It's a bit boilerplate-y and undocumented, but you need to handle all those cases otherwise the current branch will not get resolved to a PR.
this commit add very basic non-interactive PR reviewing. You can either review the "current" or a passed PR (number or URL) as approved, changes requested, or commented via CLI flags.
There was a problem hiding this comment.
Code looks great to me!
Something that still feels off to me (and that we can perhaps consider iterating on in the PR that adds interactivity) are the flags: --approve, --request-changes, --comment.
Currently all these are registered as boolean-string flags, meaning they can be passed on their own or with a value. However, the server does not allow --request-changes or --comment without a value, so it's moot that the values for these are optional. Furthermore, the mechanism by which we mark their values as optional has them being rendered like so by Cobra, which might be confusing for our users:
Flags:
-a, --approve string[=" "] Approve pull request
-c, --comment string[=" "] Comment on a pull request
-r, --request-changes string[=" "] Request changes on a pull request
Lastly, boolean-string flags can only receive a value through the = character, e.g. --comment='cool story'. That means neither of these will work:
gh pr review --comment 'cool story'
gh pr review -c 'cool story'
They fail with this cryptic error message: accepts at most 1 arg(s), received 2. Users will have to figure out that an = sign was needed instead of the space.
This might be confusing because an equals sign is not required for any other string flags, e.g. these all work:
gh pr create --title 'cool story' -b 'let me tell you a story'
Personally, I would suggest generally avoiding using boolean-string flags and just make the flags be boolean and pass the body value as a separate string flag.
$ gh pr review 123 # interactive
$ gh pr review 123 --approve # non-interactive
$ gh pr review 123 -r # failure: body value is required
$ gh pr review 123 -r --body 'this causes a crash' # non-interactive/cc @ampinsk
command/pr_review.go
Outdated
| } | ||
|
|
||
| var prReviewCmd = &cobra.Command{ | ||
| Use: "review", |
There was a problem hiding this comment.
Should we add [{<number> | <url> | <branch>}] to the usage line like we did with other pr commands?
There was a problem hiding this comment.
yup, meant to come back to that and forgot.
command/pr_review.go
Outdated
| body = val | ||
| } | ||
|
|
||
| if flag == "comment" && (body == " " || len(body) == 0) { |
There was a problem hiding this comment.
We might consider extending this behavior to --request-changes too, since it's not possible to request changes without leaving a comment either.
Since --approve is the only option where comment body is optional, we could consider marking other flags as always requiring a value.
There was a problem hiding this comment.
Ah, good catch. I'll fix that validation during retooling the flags.
command/pr_review.go
Outdated
| Use: "review", | ||
| Short: "TODO", | ||
| Args: cobra.MaximumNArgs(1), | ||
| Long: "TODO", |
There was a problem hiding this comment.
Is documentation left to be addressed in follow-up?
There was a problem hiding this comment.
"yes" in that I forgot about it :) I can do it now and then augment to talk about the no args mode
|
I was initially in favor of the I'm going to retool for that but @ampinsk feel free to redirect me if you think there's a better path. |
|
Sounds like a good change to me! Go for it @vilmibm |
This PR implements part of the lightweight reviewing (scenario B) designed here: https://docs.google.com/document/d/1lk4C5nqNWuOHxy0CDQKLbbrl6GRm4Y3f3FU4xTXgdhI/edit specifically with using boolean flags + a
--bodystring flagFor now it's just the non-interactive component; given that this PR was getting a little long I'm doing the survey case in a follow-up.
examples:
Related to #434