Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RequiredApprovingReviewCount to PullRequestReviewsEnforcement #880

Merged
merged 15 commits into from
Aug 10, 2018

Conversation

victoryNap
Copy link
Contributor

Added RequiredApprovingReviewCount to PullRequestReviewsEnforcement

Related to the following issue - #879

This count represents the number of approvals required on a pull request before it can be merged.

This will complete the model for the required_pull_request_reviews object which is returned by the GitHub API.

https://developer.github.com/v3/repos/branches/#get-branch-protection

@googlebot googlebot added the cla: yes Indication that the PR author has signed a Google Contributor License Agreement. label Mar 28, 2018
@gmlewis gmlewis changed the title Added RequiredApprovingReviewCount to PullRequestReviewsEnforcement Add RequiredApprovingReviewCount to PullRequestReviewsEnforcement Mar 28, 2018
@gmlewis
Copy link
Collaborator

gmlewis commented Mar 28, 2018

Thanks, @victoryNap. Some general feedback before a full review.

First, we have to be very careful with "omitempty" and also with the documentation here. In the GitHub Developer API documentation, there is one place where the field "must be" provided and another place where the field "can be" provided. The latter case needs to have "omitempty" and must be a pointer to an int so that the field can intentionally not be sent.

Also, the documentation needs to state here that the field must be a value between 1 and 6 for it to be valid.

Finally, all comments should be complete sentences with a period at the end so that the resulting Godocs read correctly. For example, see:
https://godoc.org/github.com/google/go-github/github

I don't have time for a full review at the moment, but saw these issues at a quick glance. Please address these first and make sure your documentation also specifies when the field is required and when it is optional... then please ping me and I'll do a full review.

Thanks again!

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

This is looking better. I've posted some comments and questions inline.

github/repos.go Outdated
@@ -579,6 +581,9 @@ type PullRequestReviewsEnforcementRequest struct {
DismissStaleReviews bool `json:"dismiss_stale_reviews"`
// RequireCodeOwnerReviews specifies if an approved review is required in pull requests including files with a designated code owner.
RequireCodeOwnerReviews bool `json:"require_code_owner_reviews"`
// RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged.
// Can be omitted.
RequiredApprovingReviewCount *int `json:"required_approving_review_count,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

This parameter appears to be mandatory, not optional, here.

https://developer.github.com/v3/repos/branches/#update-branch-protection lists required_approving_review_count in a table labeled as:

The required_pull_request_reviews object must have the following keys

Emphasis on must.

So, it should be:

RequiredApprovingReviewCount int `json:"required_approving_review_count"`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my initial thought as well, according to the docs its required. That said, the request has worked thus far without having it?

Copy link
Member

Choose a reason for hiding this comment

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

The documentation at https://developer.github.com/v3/repos/branches/#update-branch-protection has this note (which links to https://developer.github.com/changes/2018-03-16-protected-branches-required-approving-reviews/):

image

It doesn't look like we're setting that application/vnd.github.luke-cage-preview+json custom Accept header, are we?

@@ -555,7 +555,8 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
{Slug: String("t"), ID: Int64(4)},
},
},
RequireCodeOwnerReviews: true,
RequireCodeOwnerReviews: true,
RequiredApprovingReviewCount: 0,
Copy link
Member

Choose a reason for hiding this comment

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

Why is the value 3 in the JSON above:

"required_approving_review_count":3

But RequiredApprovingReviewCount is 0 here?

@@ -629,7 +630,8 @@ func TestRepositoriesService_UpdateBranchProtection(t *testing.T) {
{Slug: String("tt"), ID: Int64(4)},
},
},
RequireCodeOwnerReviews: true,
RequireCodeOwnerReviews: true,
RequiredApprovingReviewCount: 0,
Copy link
Member

Choose a reason for hiding this comment

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

Let's give it a value in the valid 1-6 range, since it's documented that way:

Use a number between 1 and 6.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the value hasn't been set, by default, it comes back as 0. I'll update the documents.

@@ -776,7 +778,8 @@ func TestRepositoriesService_GetPullRequestReviewEnforcement(t *testing.T) {
{Slug: String("t"), ID: Int64(2)},
},
},
RequireCodeOwnerReviews: true,
RequireCodeOwnerReviews: true,
RequiredApprovingReviewCount: 0,
Copy link
Member

Choose a reason for hiding this comment

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

Also here.

@@ -851,7 +855,8 @@ func TestRepositoriesService_DisableDismissalRestrictions(t *testing.T) {
Users: []*User{},
Teams: []*Team{},
},
RequireCodeOwnerReviews: true,
RequireCodeOwnerReviews: true,
RequiredApprovingReviewCount: 0,
Copy link
Member

Choose a reason for hiding this comment

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

Also here.

@@ -532,7 +532,7 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {

testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview)
fmt.Fprintf(w, `{"required_status_checks":{"strict":true,"contexts":["continuous-integration"]},"required_pull_request_reviews":{"dismissal_restrictions":{"users":[{"id":3,"login":"u"}],"teams":[{"id":4,"slug":"t"}]},"dismiss_stale_reviews":true,"require_code_owner_reviews":true},"enforce_admins":{"url":"/repos/o/r/branches/b/protection/enforce_admins","enabled":true},"restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]}}`)
fmt.Fprintf(w, `{"required_status_checks":{"strict":true,"contexts":["continuous-integration"]},"required_pull_request_reviews":{"dismissal_restrictions":{"users":[{"id":3,"login":"u"}],"teams":[{"id":4,"slug":"t"}]},"dismiss_stale_reviews":true,"require_code_owner_reviews":true},"enforce_admins":{"url":"/repos/o/r/branches/b/protection/enforce_admins","enabled":true},"restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]},"required_approving_review_count":3}`)
Copy link
Member

@dmitshur dmitshur Mar 30, 2018

Choose a reason for hiding this comment

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

I see why it's 0 below. It's because the "required_approving_review_count":3 entry is added in the wrong place here. It should be added inside the "required_pull_request_reviews":{...} object.

Perhaps it's a good idea to make the JSON multi-line and nicely formatted, so it's easier to read and modify.

@victoryNap
Copy link
Contributor Author

@shurcooL @gmlewis When you get a minute, would you take a look at this?

@@ -51,9 +51,6 @@ const (
// https://developer.github.com/changes/2014-12-09-new-attributes-for-stars-api/
mediaTypeStarringPreview = "application/vnd.github.v3.star+json"

// https://developer.github.com/changes/2015-11-11-protected-branches-api/
mediaTypeProtectedBranchesPreview = "application/vnd.github.loki-preview+json"
Copy link
Collaborator

Choose a reason for hiding this comment

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

That seems odd that there wasn't a GitHub Developer API announcement revoking this custom media type. (Unless maybe I missed it?)
The last one I see was: https://developer.github.com/changes/2016-06-27-protected-branches-api-update/
and the new docs only mention the new custom media type, so maybe this one silently went away?
I'm guessing that's how you interpret the current situation, @victoryNap, judging from the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also didn't see an update saying it was no longer a preview, but thats the assumption that I made, their documentation makes no reference to the previous preview header, only to the new one that I've added.

screen shot 2018-05-10 at 7 58 52 pm

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Just a couple tweaks needed.
Thank you, @victoryNap!
Have you been able to test these changes out on GitHub?

github/repos.go Outdated
// RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged.
// Valid values are 1-6.
// Can be omitted.
RequiredApprovingReviewCount int `json:"required_approving_review_count,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

If it can be omitted, then I think we need to make this type *int instead of int.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue with the comment, I forgot to update it. Its a required field.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then in that case, should we get rid of the ,omitempty here and below?

github/repos.go Outdated
// RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged.
// Valid values are 1 - 6.
// Can be omitted.
RequiredApprovingReviewCount int `json:"required_approving_review_count,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here: *int.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label May 11, 2018
@victoryNap
Copy link
Contributor Author

victoryNap commented May 30, 2018

@gmlewis I tested this on github, and it worked! What kind of logs would you like to see?

@gmlewis
Copy link
Collaborator

gmlewis commented May 31, 2018

Thanks for testing it, @victoryNap! I don't need to see the logs.

// TODO: remove custom Accept header when this API fully launches
testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview)
fmt.Fprintf(w, `{
"required_status_checks":{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking we don't need the large amount of indentation here (and below).
What about un-indenting this entire region? Something like:

		fmt.Fprintf(w, `{
"required_status_checks":{
	"strict":true,
	"contexts":["continuous-integration"]
},
"required_pull_request_reviews":{
...

?

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @victoryNap! I'm thinking this is almost ready to merge. One question about the required params, and then we will want a second LGTM before merging.

github/repos.go Outdated
@@ -579,6 +582,9 @@ type PullRequestReviewsEnforcementRequest struct {
DismissStaleReviews bool `json:"dismiss_stale_reviews"`
// RequireCodeOwnerReviews specifies if an approved review is required in pull requests including files with a designated code owner.
RequireCodeOwnerReviews bool `json:"require_code_owner_reviews"`
// RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged.
// Valid values are 1-6.
RequiredApprovingReviewCount int `json:"required_approving_review_count,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are your thoughts, @victoryNap on this ,omitempty?
I'm thinking it should be removed since it is a required parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call.

github/repos.go Outdated
@@ -591,6 +597,9 @@ type PullRequestReviewsEnforcementUpdate struct {
DismissStaleReviews *bool `json:"dismiss_stale_reviews,omitempty"`
// RequireCodeOwnerReviews specifies if an approved review is required in pull requests including files with a designated code owner.
RequireCodeOwnerReviews bool `json:"require_code_owner_reviews,omitempty"`
// RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged.
// Valid values are 1 - 6.
RequiredApprovingReviewCount int `json:"required_approving_review_count,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

...and this one too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also Updated

@victoryNap
Copy link
Contributor Author

@gmlewis I don't know that having the block totally unindented looks makes sense, but I agree, I was overly aggressive with the tabs...

@gmlewis
Copy link
Collaborator

gmlewis commented Jun 1, 2018

OK, @victoryNap, that's fine with me. In my own code, I like to left-justify the included JSON, but this looks much better now and I'm happy with that... thanks!

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @victoryNap!
This LGTM... awaiting second LGTM before merging.

@gmlewis
Copy link
Collaborator

gmlewis commented Jun 1, 2018

It looks like we have a CI failure and some tests need updating:

--- FAIL: TestPullRequestReviewsEnforcementRequest_MarshalJSON_nilDismissalRestirctions (0.00s)
	repos_test.go:1034: PullRequestReviewsEnforcementRequest.MarshalJSON returned {"dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":0}, want {"dismiss_stale_reviews":false,"require_code_owner_reviews":false}
	repos_test.go:1048: PullRequestReviewsEnforcementRequest.MarshalJSON returned {"dismissal_restrictions":{},"dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":0}, want {"dismissal_restrictions":{},"dismiss_stale_reviews":false,"require_code_owner_reviews":false}
	repos_test.go:1065: PullRequestReviewsEnforcementRequest.MarshalJSON returned {"dismissal_restrictions":{"users":[],"teams":[]},"dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":0}, want {"dismissal_restrictions":{"users":[],"teams":[]},"dismiss_stale_reviews":false,"require_code_owner_reviews":false}

Can you please look into this, @victoryNap?

@victoryNap
Copy link
Contributor Author

@gmlewis I'll take a look. Probably a result of my indentation changes

@victoryNap
Copy link
Contributor Author

@gmlewis Fixed :)

@shurcooL Mind taking a look when you get a chance?

@victoryNap
Copy link
Contributor Author

victoryNap commented Jun 20, 2018

@gmlewis who else can approve this PR before it can be merged?

@gmlewis
Copy link
Collaborator

gmlewis commented Jun 21, 2018

I don't believe that there is any strict rule for code reviewers for this repo... we have typically relied on active contributors but I know we lost some people when the repo required two-factor auth to be enabled, unfortunately.

For non-trivial changes, we like to have a second set of eyes review the code and check that things look good with respect to the GitHub Developer API docs.

So I believe we welcome all contributors to check for the NeedsReview label and provide any feedback, including full reviews and LGTMs.

@willnorris can correct me if my understanding is incorrect.

@majormoses
Copy link

majormoses commented Jul 9, 2018

I will try to crawl through but golang is not exactly something I am comfortable with. One thing that I noticed in the documentation is that if the object is null then that means turning it off.

https://developer.github.com/v3/repos/branches/#parameters-1

EDIT: looking through the tests it looks like its covered.

@victoryNap
Copy link
Contributor Author

@willnorris @dmitshur Can I get another review on this?

@victoryNap
Copy link
Contributor Author

@gmlewis I really need this feature added in. Any thoughts on getting another review?

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 1, 2018

Sorry about that... Let's see if @juliaferraioli has time.

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 10, 2018

I'm hearing no objections.
Merging.

@gmlewis gmlewis merged commit 8292762 into google:master Aug 10, 2018
gmlewis pushed a commit to gmlewis/go-github that referenced this pull request Aug 10, 2018
@gmlewis
Copy link
Collaborator

gmlewis commented Aug 10, 2018

Fixes #876.

@tadityar
Copy link
Contributor

tadityar commented Oct 8, 2018

I think this also Fixes #905.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indication that the PR author has signed a Google Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants