pulls: Support updating base branch#528
pulls: Support updating base branch#528dmitshur merged 5 commits intogoogle:masterfrom abhinav:pull-request-update-base
Conversation
|
|
||
| // Edit a pull request. | ||
| // | ||
| // GitHub API docs: https://developer.github.com/v3/pulls/#update-a-pull-request |
There was a problem hiding this comment.
I think we should document which fields we currently support. It's not obvious that passing github.&PullRequest{Base: &github.PullRequestBranch{Ref: "belong-to-us"}, out out of all other fields inside PullRequest struct, will update the base.
Something like:
// Edit a pull request.
//
// Fields that can be edited are: Title, Body, State, Base.Ref to edit base branch.
There was a problem hiding this comment.
Agreed. Added docs for this.
github/pulls_test.go
Outdated
| input *PullRequest | ||
| sendResponse string | ||
|
|
||
| wantUpdate *pullRequestUpdate |
There was a problem hiding this comment.
This is optional, but I think it'd be better if you made the type of wantUpdate a string and have it contain the expected JSON.
There's no need to decode the update JSON into our own struct that we used for encoding, and compare those.
What do you think?
There was a problem hiding this comment.
I was concerned that the order in which the struct fields would
be serialized is not deterministic but that doesn't appear to be
the case upon trial. Updated.
There was a problem hiding this comment.
I see.
Yeah, encoding/json encoder uses the order of fields in a struct when encoding, so it is deterministic. It even sorts map keys, so everything's always deterministic.
github/pulls_test.go
Outdated
| { | ||
| input: &PullRequest{Title: String("t")}, | ||
| sendResponse: `{"number":1}`, | ||
| wantUpdate: &pullRequestUpdate{Title: String("t")}, |
There was a problem hiding this comment.
Then, the value for wantUpdate here would be something like {"title":"t"}.
It's easier to reason about it being correct, since GitHub API deals with JSON input and we can compare its documentation with this.
dmitshur
left a comment
There was a problem hiding this comment.
LGTM. Thank you!
See line comment for another simplification opportunity.
github/pulls_test.go
Outdated
| wantUpdate := tt.wantUpdate + "\n" // json encoder adds a newline | ||
| if string(gotUpdate) != wantUpdate { | ||
| t.Errorf("Request body = %q, want %q", gotUpdate, wantUpdate) | ||
| } |
There was a problem hiding this comment.
You can use testBody helper to simplify this.
See
go-github/github/pulls_test.go
Line 478 in c9c37fd
github/pulls_test.go
Outdated
| for _, tt := range tests { | ||
| func() { | ||
| setup() | ||
| defer teardown() |
There was a problem hiding this comment.
In fact, you can use the idea from TestPullRequestsService_Merge_options to remove the need for the nested closure with per-testcase setup()/defer teardown(). The idea there is to use i as the pull request ID, so that registered routes don't overlap.
It also tests that the handler gets called (instead of not being called).
See
go-github/github/pulls_test.go
Lines 438 to 486 in c9c37fd
Optional, if you're interested in doing this.
Also test whether the request was acually made.
dmitshur
left a comment
There was a problem hiding this comment.
Looks great, thanks for doing this!
LGTM.
github/pulls_test.go
Outdated
| v := new(PullRequest) | ||
| json.NewDecoder(r.Body).Decode(v) | ||
| wantUpdate string | ||
| wantResponse *PullRequest |
There was a problem hiding this comment.
nit: I find wantResponse a bit confusing here... what if we just called it want ?
Either way is fine, though... your call.
As per the discussion in google#421, the PullRequest parameter is converted into an unexported type pullRequestUpdate which matches the shape expected by the pulls PATCH endpoint. Resolves google#421.
This adds support for changing the base branch of a PR.
As per the discussion in #421, the
PullRequestis converted into anunexported type
pullRequestUpdatewhich matches the shape expected by thepulls PATCH endpoint.
Resolves issue #421.