-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
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: 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! |
There was a problem hiding this 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"` |
There was a problem hiding this comment.
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"`
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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/):
It doesn't look like we're setting that application/vnd.github.luke-cage-preview+json
custom Accept header, are we?
github/repos_test.go
Outdated
@@ -555,7 +555,8 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) { | |||
{Slug: String("t"), ID: Int64(4)}, | |||
}, | |||
}, | |||
RequireCodeOwnerReviews: true, | |||
RequireCodeOwnerReviews: true, | |||
RequiredApprovingReviewCount: 0, |
There was a problem hiding this comment.
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?
github/repos_test.go
Outdated
@@ -629,7 +630,8 @@ func TestRepositoriesService_UpdateBranchProtection(t *testing.T) { | |||
{Slug: String("tt"), ID: Int64(4)}, | |||
}, | |||
}, | |||
RequireCodeOwnerReviews: true, | |||
RequireCodeOwnerReviews: true, | |||
RequiredApprovingReviewCount: 0, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
github/repos_test.go
Outdated
@@ -776,7 +778,8 @@ func TestRepositoriesService_GetPullRequestReviewEnforcement(t *testing.T) { | |||
{Slug: String("t"), ID: Int64(2)}, | |||
}, | |||
}, | |||
RequireCodeOwnerReviews: true, | |||
RequireCodeOwnerReviews: true, | |||
RequiredApprovingReviewCount: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here.
github/repos_test.go
Outdated
@@ -851,7 +855,8 @@ func TestRepositoriesService_DisableDismissalRestrictions(t *testing.T) { | |||
Users: []*User{}, | |||
Teams: []*Team{}, | |||
}, | |||
RequireCodeOwnerReviews: true, | |||
RequireCodeOwnerReviews: true, | |||
RequiredApprovingReviewCount: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here.
github/repos_test.go
Outdated
@@ -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}`) |
There was a problem hiding this comment.
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.
…removed old repo protection header. Updated tests with new headers and valid values
@@ -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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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"` |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: *int
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
@gmlewis I tested this on github, and it worked! What kind of logs would you like to see? |
Thanks for testing it, @victoryNap! I don't need to see the logs. |
github/repos_test.go
Outdated
// TODO: remove custom Accept header when this API fully launches | ||
testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) | ||
fmt.Fprintf(w, `{ | ||
"required_status_checks":{ |
There was a problem hiding this comment.
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":{
...
?
There was a problem hiding this 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"` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and this one too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also Updated
@gmlewis I don't know that having the block totally unindented looks makes sense, but I agree, I was overly aggressive with the tabs... |
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! |
There was a problem hiding this 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.
It looks like we have a CI failure and some tests need updating:
Can you please look into this, @victoryNap? |
@gmlewis I'll take a look. Probably a result of my indentation changes |
@gmlewis who else can approve this PR before it can be merged? |
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 @willnorris can correct me if my understanding is incorrect. |
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 https://developer.github.com/v3/repos/branches/#parameters-1 EDIT: looking through the tests it looks like its covered. |
@willnorris @dmitshur Can I get another review on this? |
@gmlewis I really need this feature added in. Any thoughts on getting another review? |
Sorry about that... Let's see if @juliaferraioli has time. |
I'm hearing no objections. |
Fixes #876. |
I think this also Fixes #905. |
Added
RequiredApprovingReviewCount
toPullRequestReviewsEnforcement
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