Repository navigation
Add support for gh pr merge - #873
Conversation
| initWithStubs("master", | ||
| stubResponse{200, bytes.NewBufferString(`{ "data": { "repository": { | ||
| "pullRequest": { "number": 1, "closed": false, "state": "OPEN"} | ||
| } } }`)}, | ||
| stubResponse{200, bytes.NewBufferString(`{"id": "THE-ID"}`)}, | ||
| ) |
There was a problem hiding this comment.
I'm wondering what people think about this. Creating the blank context and the fake http instance seemed like it was getting very repetitive in tests with not much added benefit. Are helpers like this helpful?
There was a problem hiding this comment.
Indeed, it's getting really repetitive, especially because we are forced to copy-paste JSON response stubs for API calls that are not even being exercised in the current test. I think that initWithStubs, but not that we might be moving away from sequential stubs to those that match specific requests based on their contents #874 which means we might need access to additional apis other than just http.StubResponse
| } | ||
|
|
||
| var prMergeCmd = &cobra.Command{ | ||
| Use: "merge [number | url] [--rebase | --merge | --squash]", |
There was a problem hiding this comment.
I wasn't sure how to document the idea of a mutually exclusive optional variable.
[{number | url}] seems like it might be correct, but [number | url] is easier to read and still seems unambiguous to me. It's hard to tell from command line docs what the correct syntax is.
There was a problem hiding this comment.
The 1st argument is the same as the optional argument to view and checkout, right? So it would be
[{<number> | <url> | <branch>}]
what follows are flags that are optional & mutually exclusive:
[{--rebase | --merge | --squash}]
however, if all this is getting unwieldy, I don't think we strictly need to document these flags in command synopsis line. Users will read about the available flags in the FLAGS section.
| } | ||
|
|
||
| var prMergeCmd = &cobra.Command{ | ||
| Use: "merge [number | url] [--rebase | --merge | --squash]", |
There was a problem hiding this comment.
The 1st argument is the same as the optional argument to view and checkout, right? So it would be
[{<number> | <url> | <branch>}]
what follows are flags that are optional & mutually exclusive:
[{--rebase | --merge | --squash}]
however, if all this is getting unwieldy, I don't think we strictly need to document these flags in command synopsis line. Users will read about the available flags in the FLAGS section.
| initWithStubs("master", | ||
| stubResponse{200, bytes.NewBufferString(`{ "data": { "repository": { | ||
| "pullRequest": { "number": 1, "closed": false, "state": "OPEN"} | ||
| } } }`)}, | ||
| stubResponse{200, bytes.NewBufferString(`{"id": "THE-ID"}`)}, | ||
| ) |
There was a problem hiding this comment.
Indeed, it's getting really repetitive, especially because we are forced to copy-paste JSON response stubs for API calls that are not even being exercised in the current test. I think that initWithStubs, but not that we might be moving away from sequential stubs to those that match specific requests based on their contents #874 which means we might need access to additional apis other than just http.StubResponse
|
|
||
| func merge(client *Client, repo ghrepo.Interface, pr *PullRequest, mergeMethod githubv4.PullRequestMergeMethod) error { | ||
| var mutation struct { | ||
| ReopenPullRequest struct { |
There was a problem hiding this comment.
A little scary that everything worked fine with that error!
There was a problem hiding this comment.
Ah, well, you can name your struct fields anything you like, and the GraphQL library will either request a field/connection/mutation based on that field name or based on the graphql:"..." struct tag. Since this field has a tag graphql:"mergePullRequest(input: $input)", the mutation that is requested is always mergePullRequest and technically your overall query is correct regardless of the struct field name you choose.
|
This should be good to go now. |
| } | ||
|
|
||
| var prMergeCmd = &cobra.Command{ | ||
| Use: "merge [{<number> | <url>}] [<flags>]", |
There was a problem hiding this comment.
- PR commands generally also accept
<branch>value as alternative to<number>and<url>, so it should be listed here for consistency - Should we ever note
[<flags>]explicitly? It used to be added automatically for us by Cobra output for any command that supports flags, but not anymore it seems due to Help output for individual commands is broken #883
There was a problem hiding this comment.
I guess we don't need to add flag to the usage string. I'll add branch and get rid of flag.
| return merge(client, repo, pr, githubv4.PullRequestMergeMethodRebase) | ||
| } | ||
|
|
||
| func PullRequestSquash(client *Client, repo ghrepo.Interface, pr *PullRequest) error { |
There was a problem hiding this comment.
Instead of having a separate method for each of the merge options, could we pass a constant as an argument to a single method called e.g. PullRequestMerge()? We'd define 3 constants in the api package and then inside the method we would translate them to appropriate githubv4 constants. This is the approach @vilmibm took in pr review and I dig it!
There was a problem hiding this comment.
I originally tried something like this but ended up having lots of type conversion issues. I'll try this switch statement idea
There was a problem hiding this comment.
Ahhh... this worked great. Thanks for the example link.
|
This is ready to go. But I'm going to hold off on merging it until after we release on monday |
|
I missed this for so long! Thank you for adding it 👍 |
This adds the
gh pr mergecommand and it works like this.gh pr mergemerges the current PRgh pr merge 54merges PR #54It has three mutually exclusive flags
--rebase,--merge, and--squash. The default flag is--mergeHere is what it looks like:
What will be in follow up PRs
gh pr merge [number | url]interactive if there are no flagsPart 1 of closing #373