Skip to content

Add support for merge method and repository squash settings.#446

Closed
gsquire wants to merge 1 commit into
google:masterfrom
gsquire:api-updates
Closed

Add support for merge method and repository squash settings.#446
gsquire wants to merge 1 commit into
google:masterfrom
gsquire:api-updates

Conversation

@gsquire
Copy link
Copy Markdown
Contributor

@gsquire gsquire commented Oct 10, 2016

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.

Comment thread github/pulls.go Outdated
// PullRequestOptions lets you define how a pull request will be merged.
type PullRequestOptions struct {
Squash bool
Squash bool
Copy link
Copy Markdown
Collaborator

@gmlewis gmlewis Oct 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it looks to be deprecated.

Comment thread github/pulls.go
type PullRequestOptions struct {
Squash bool
Squash bool
MergeMethod string
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please document this field?
e.g.: Merge method to use. Possible values are: "merge", "squash", "rebase". Default is "merge".

Comment thread github/pulls.go
@@ -251,12 +251,14 @@ type PullRequestMergeResult struct {

// PullRequestOptions lets you define how a pull request will be merged.
type PullRequestOptions struct {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add CommitTitle to this struct?
https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I certainly missed that in the blog post.

Comment thread github/pulls.go Outdated

type pullRequestMergeRequest struct {
CommitMessage *string `json:"commit_message"`
Squash *bool `json:"squash,omitempty"`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to remove Squash here, too.

Comment thread github/pulls.go
MergeMethod string
}

type pullRequestMergeRequest struct {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to add CommitTitle here too.

Comment thread github/pulls.go
@@ -268,10 +270,12 @@ func (s *PullRequestsService) Merge(owner string, repo string, number int, commi
pullRequestBody := &pullRequestMergeRequest{CommitMessage: &commitMessage}
if options != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And update this section too.

Comment thread github/repos.go Outdated

// 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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The blog posts are usually referenced in the github.go file with the preview tags - you could add this to the polaris one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do.

Copy link
Copy Markdown
Contributor Author

@gsquire gsquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the CR.

Comment thread github/pulls.go
@@ -251,12 +251,14 @@ type PullRequestMergeResult struct {

// PullRequestOptions lets you define how a pull request will be merged.
type PullRequestOptions struct {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I certainly missed that in the blog post.

Comment thread github/pulls.go Outdated
// PullRequestOptions lets you define how a pull request will be merged.
type PullRequestOptions struct {
Squash bool
Squash bool
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it looks to be deprecated.

Comment thread github/repos.go Outdated

// 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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do.

Comment thread github/pulls.go Outdated
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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, should have caught that.

@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Oct 10, 2016

LGTM after a minor godoc tweak.
Awaiting secondary LGTM before merging.

@gsquire
Copy link
Copy Markdown
Contributor Author

gsquire commented Oct 10, 2016

Thank you, I will collapse my commits when it gets signed off on.

@gsquire
Copy link
Copy Markdown
Contributor Author

gsquire commented Oct 12, 2016

I rebased onto master and squashed.

@dmitshur dmitshur changed the title Issue 437 Add support for merge method and repository squash settings. Oct 12, 2016
@dmitshur
Copy link
Copy Markdown
Member

We should add a "Resolves #437." or equivalent message to the commit message, so that issue gets closed when this is merged. But @gmlewis can do that when merging, so it's not a big deal.

Copy link
Copy Markdown
Member

@dmitshur dmitshur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See question about multiple preview API accept headers in inline comments.

Comment thread github/repos.go Outdated
// 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)
Copy link
Copy Markdown
Member

@dmitshur dmitshur Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=json

Only 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. I will ask GitHub support and see what they recommend.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's no rush, I didn't know what the course of action was for this. Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I will update it and do some manual tests and see if the unit test can be changed too.

Comment thread github/github.go Outdated
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but the missing trailing slash is inconsistent.

@gsquire
Copy link
Copy Markdown
Contributor Author

gsquire commented Oct 12, 2016

@shurcooL I have a "Closes" line in my commit message already.

@gsquire
Copy link
Copy Markdown
Contributor Author

gsquire commented Oct 19, 2016

Rebased onto master again.

@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Oct 20, 2016

Hmmm... it looks like I dropped the ball on this one... I'm sorry about that... Merging.

@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Oct 20, 2016

Ah, yes... thanks, @shurcooL for the reminder. This was held up on the header issue.
I haven't had a chance to test the comma-separated header yet. Hopefully today.
I'll test before I merge.

@eparis
Copy link
Copy Markdown
Contributor

eparis commented Oct 20, 2016

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!

@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Oct 20, 2016

SGTM. Yes, "squash" is still supported in the GitHub API via the MergeMethod.
Thank you, @eparis!

@eparis
Copy link
Copy Markdown
Contributor

eparis commented Oct 20, 2016

@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.

@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Oct 20, 2016

Ah! I didn't understand that, @eparis. Can you please copy/paste the error message(s)?

Comment thread github/pulls.go
// PullRequestOptions lets you define how a pull request will be merged.
type PullRequestOptions struct {
Squash bool
CommitTitle string
Copy link
Copy Markdown
Contributor

@eparis eparis Oct 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 "")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread github/pulls.go

// PullRequestOptions lets you define how a pull request will be merged.
type PullRequestOptions struct {
Squash bool
Copy link
Copy Markdown
Contributor

@eparis eparis Oct 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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....

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, GitHub is changing their API.
Please read: https://developer.github.com/changes/2016-04-01-squash-api-preview/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating new issue for discussion, now that GitHub no longer appears to be under DDOS attack.

@gsquire
Copy link
Copy Markdown
Contributor Author

gsquire commented Nov 9, 2016

@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.

@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Nov 9, 2016

Thanks for the ping, @gsquire, and I apologize for the delay!
AFAICT, this PR is ready to be merged, and I'll go ahead and do that now.

@gmlewis gmlewis closed this in 575b0b3 Nov 9, 2016
@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Nov 9, 2016

Integrated in 575b0b3.

@gsquire gsquire deleted the api-updates branch November 9, 2016 20:14
@gsquire
Copy link
Copy Markdown
Contributor Author

gsquire commented Nov 9, 2016

@gmlewis It's no problem, thanks for your patience. 👍

bubg-dev pushed a commit to bubg-dev/go-github that referenced this pull request Jun 16, 2017
Closes google#437.
Closes google#446.

Change-Id: I7a9bd0717310ef016b2695fe0e5cffb8e8b86ff8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants