Add support for merge method and repository squash settings.#446
Add support for merge method and repository squash settings.#446gsquire wants to merge 1 commit into
Conversation
| // PullRequestOptions lets you define how a pull request will be merged. | ||
| type PullRequestOptions struct { | ||
| Squash bool | ||
| Squash bool |
There was a problem hiding this comment.
It looks to me like Squash is no longer supported and can be removed..
https://developer.github.com/changes/2016-04-01-squash-api-preview/ seems to confirm, although it is not explicit.
There was a problem hiding this comment.
I agree, it looks to be deprecated.
| type PullRequestOptions struct { | ||
| Squash bool | ||
| Squash bool | ||
| MergeMethod string |
There was a problem hiding this comment.
Can you please document this field?
e.g.: Merge method to use. Possible values are: "merge", "squash", "rebase". Default is "merge".
| @@ -251,12 +251,14 @@ type PullRequestMergeResult struct { | |||
|
|
|||
| // PullRequestOptions lets you define how a pull request will be merged. | |||
| type PullRequestOptions struct { | |||
There was a problem hiding this comment.
Could you please add CommitTitle to this struct?
https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
There was a problem hiding this comment.
Yes, I certainly missed that in the blog post.
|
|
||
| type pullRequestMergeRequest struct { | ||
| CommitMessage *string `json:"commit_message"` | ||
| Squash *bool `json:"squash,omitempty"` |
There was a problem hiding this comment.
You will need to remove Squash here, too.
| MergeMethod string | ||
| } | ||
|
|
||
| type pullRequestMergeRequest struct { |
There was a problem hiding this comment.
You will need to add CommitTitle here too.
| @@ -268,10 +270,12 @@ func (s *PullRequestsService) Merge(owner string, repo string, number int, commi | |||
| pullRequestBody := &pullRequestMergeRequest{CommitMessage: &commitMessage} | |||
| if options != nil { | |||
There was a problem hiding this comment.
And update this section too.
|
|
||
| // TODO: remove custom Accept header when the license support fully launches | ||
| // https://developer.github.com/v3/licenses/#get-a-repositorys-license | ||
| // https://developer.github.com/changes/2016-09-26-pull-request-merge-api-update |
There was a problem hiding this comment.
The blog posts are usually referenced in the github.go file with the preview tags - you could add this to the polaris one.
gsquire
left a comment
There was a problem hiding this comment.
Thanks for the CR.
| @@ -251,12 +251,14 @@ type PullRequestMergeResult struct { | |||
|
|
|||
| // PullRequestOptions lets you define how a pull request will be merged. | |||
| type PullRequestOptions struct { | |||
There was a problem hiding this comment.
Yes, I certainly missed that in the blog post.
| // PullRequestOptions lets you define how a pull request will be merged. | ||
| type PullRequestOptions struct { | ||
| Squash bool | ||
| Squash bool |
There was a problem hiding this comment.
I agree, it looks to be deprecated.
|
|
||
| // TODO: remove custom Accept header when the license support fully launches | ||
| // https://developer.github.com/v3/licenses/#get-a-repositorys-license | ||
| // https://developer.github.com/changes/2016-09-26-pull-request-merge-api-update |
| Squash *bool `json:"squash,omitempty"` | ||
| CommitTitle *string `json:"commit_title,omitempty"` | ||
|
|
||
| // The merge method to use. Possible values include: "merge", "squash", and "rebase" with the default being merge. |
There was a problem hiding this comment.
While this is good, I think it would be much better to move this to the exported struct above (PullRequestOptions) so that the auto-generated godocs will read better.
There was a problem hiding this comment.
No problem, should have caught that.
|
LGTM after a minor |
|
Thank you, I will collapse my commits when it gets signed off on. |
|
I rebased onto master and squashed. |
dmitshur
left a comment
There was a problem hiding this comment.
See question about multiple preview API accept headers in inline comments.
| // TODO: remove custom Accept header when the license support fully launches | ||
| // https://developer.github.com/v3/licenses/#get-a-repositorys-license | ||
| req.Header.Set("Accept", mediaTypeLicensesPreview) | ||
| req.Header.Add("Accept", mediaTypeSquashPreview) |
There was a problem hiding this comment.
Has anyone tested that multiple Accept headers actually work by combining both preview APIs, instead of only one being used?
I'm asking because this is the very first time I see it done in this library, it has never been done before as far as I know.
I tried reading https://developer.github.com/v3/media/ and it doesn't seem to say that multiple Accept headers are the way to go (neither does it say it shouldn't be done).
There was a problem hiding this comment.
Yeah, pretty sure that 2 accept headers don't work:
$ curl https://api.github.com/users/technoweenie -I -s -H "Accept: application/vnd.github.drax-preview+json" -H "Accept: application/vnd.github.polaris-preview+json" | grep X-GitHub-Media-Type
X-GitHub-Media-Type: github.drax-preview; format=jsonOnly one seems to have an effect.
I'm not sure if it's even possible to opt into two preview APIs in the same request... Any thoughts on this?
There was a problem hiding this comment.
I didn't know if that would matter or not. I assumed that you would need both since this API request now has two preview features. What should happen here then?
There was a problem hiding this comment.
Sorry for the delay. I will ask GitHub support and see what they recommend.
There was a problem hiding this comment.
It's no rush, I didn't know what the course of action was for this. Thanks!
There was a problem hiding this comment.
I will ask GitHub support and see what they recommend.
Good idea, thanks for doing that!
If it turns out that it's not possible to combine multiple beta APIs in same request, we might have to make 2 requests (each with a different beta API), or just pick 1 beta that's more important and remove the other. Or wait until at least one of them is merged into main v3 API, then use the remaining beta header.
There was a problem hiding this comment.
It turns out that my hunch for using comma-separated values was correct:
https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
From GitHub support:
Example:
Accept: application/vnd.github.mockingbird-preview, application/vnd.github.polaris-preview
Of course, this will need to be tested.
There was a problem hiding this comment.
Great, I will update it and do some manual tests and see if the unit test can be changed too.
| mediaTypeReactionsPreview = "application/vnd.github.squirrel-girl-preview" | ||
|
|
||
| // https://developer.github.com/changes/2016-04-01-squash-api-preview/ | ||
| // https://developer.github.com/changes/2016-09-26-pull-request-merge-api-update |
There was a problem hiding this comment.
Nitpick, but the missing trailing slash is inconsistent.
|
@shurcooL I have a "Closes" line in my commit message already. |
|
Rebased onto master again. |
|
Hmmm... it looks like I dropped the ball on this one... I'm sorry about that... Merging. |
|
Ah, yes... thanks, @shurcooL for the reminder. This was held up on the header issue. |
|
This breaks the existing 'squash' support. Our API is changing. I don't even know if squash is still in the github API though. Or if we care (I don't). I'll rebase my work to support SHA on top of this. Great! |
|
SGTM. Yes, "squash" is still supported in the GitHub API via the |
|
@gmlewis but our API is breaking in this PR is what I was trying to say, not that I care, just pointing it out in case anyone else wanted to complain that we know this will cause code to be unable to compile. |
|
Ah! I didn't understand that, @eparis. Can you please copy/paste the error message(s)? |
| // PullRequestOptions lets you define how a pull request will be merged. | ||
| type PullRequestOptions struct { | ||
| Squash bool | ||
| CommitTitle string |
There was a problem hiding this comment.
Shouldn't these be *string? Or should we check for != "" before we assign to pullRequestMergeRequest? Otherwise setting any PullRequestOptions will result in all options be set (to explicit "")
There was a problem hiding this comment.
As far as I can tell from https://developer.github.com/changes/2016-09-26-pull-request-merge-api-update/ and https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
this field is mandatory, although below we make it omitempty.
Yes, I'm thinking that if we just test for != "" before assigning to pullRequestMergeRequest below, that this would be safe.
|
|
||
| // PullRequestOptions lets you define how a pull request will be merged. | ||
| type PullRequestOptions struct { | ||
| Squash bool |
There was a problem hiding this comment.
by removing this any user of our library who is doing
ops := &PullRequestOptions {
Squash: true,
}
will be unable to compile. We "could" keep supporting them by automatically turning Squash into a MergeMethod = "squash" if we so chose. We don't have to. If github breaks the API I don't know if we really need to be forward compatible with our users....
There was a problem hiding this comment.
Yes, GitHub is changing their API.
Please read: https://developer.github.com/changes/2016-04-01-squash-api-preview/
There was a problem hiding this comment.
But we don't have to. We may decide we want to, and that's fine. But it is easy to write:
type PullRequestOptions struct {
Squash bool
MergeMethod string
}
And then inside https://github.com/google/go-github/pull/446/files#diff-aafac035cce1f6a65b02566c5345b805R276
if options.Squash {
mm := "squash"
pullRequestBody.MergeMethod = &mm
}
Just pointing it out. I'm actually ok dropping OUR legacy API and break compile for our users. But its also pretty easy to be a friendly library if that's the path we wish to take.
There was a problem hiding this comment.
Hmmm... @willnorris and @shurcooL - what are your thoughts about breaking the current (preview) API involving "squashes" when the GitHub Preview API itself is changing? Do we match the GitHub API or do we attempt to retain a "more friendly" API toward squashes?
See: https://developer.github.com/changes/2016-04-01-squash-api-preview/ for more info.
To remain consistent with the rest of this package, I'm leaning toward matching the GitHub API as close as possible to not create any surprises for users. But if you feel we should depart from this consistency and make the API friendlier for squashing, I'm not adverse to that either.
There was a problem hiding this comment.
I just caught up on this thread. I'll standby until we settle on what this API should have. Please feel free to ping me so I can make the appropriate changes.
Thanks for all of the comments!
There was a problem hiding this comment.
Hmmm... @willnorris and @shurcooL - what are your thoughts about breaking the current (preview) API involving "squashes" when the GitHub Preview API itself is changing? Do we match the GitHub API or do we attempt to retain a "more friendly" API toward squashes?
We've had this discussion in the past. Let me try to find it.
I think it's this comment and its thread that I had in mind.
Basically, my POV is that we're welcome to make breaking API changes to endpoints that are in preview. We absolutely should, that's the whole point of API preview period, it lets GitHub iterate on the API and this library should follow. Using the very first iteration is going to be counter-productive for users after the API exits preview period.
@gmlewis I'm not sure if your question is about whether it's okay to break go-github APIs for preview endpoints (IMO it is), or if it's about whether we should deviate from GitHub API in what go-github provides (IMO we should try to stay close, but still be idiomatic Go, no need to compromise on usability/friendliness).
To remain consistent with the rest of this package, I'm leaning toward matching the GitHub API as close as possible to not create any surprises for users. But if you feel we should depart from this consistency and make the API friendlier for squashing, I'm not adverse to that either.
I think your question is about the latter. Can you elaborate on what 2 alternatives you're considering here?
Also, we should open an issue that this PR resolves and continue the discussion there. It's hard to see this "outdated comment" in this PR.
There was a problem hiding this comment.
Creating new issue for discussion, now that GitHub no longer appears to be under DDOS attack.
|
@gmlewis I hope this PR hasn't gone stale. Based on the issue you wrote discussing how we should handle the merge method, the code is already set up to do that. Please let me know if there are any more items I should address in the meantime. |
|
Thanks for the ping, @gsquire, and I apologize for the delay! |
|
Integrated in 575b0b3. |
|
@gmlewis It's no problem, thanks for your patience. 👍 |
Closes google#437. Closes google#446. Change-Id: I7a9bd0717310ef016b2695fe0e5cffb8e8b86ff8
This PR adds merge method support and squash API options for repository get and update.
I'm unsure of what a good unit test might be, so I can update this if need be.