-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add admin enforcement to protected branches API (#606) #610
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
Changes from all commits
c00eead
02a1f4d
62a5b3a
9237137
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -511,19 +511,22 @@ type Branch struct { | |
type Protection struct { | ||
RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"` | ||
RequiredPullRequestReviews *RequiredPullRequestReviews `json:"required_pull_request_reviews"` | ||
EnforceAdmins *AdminEnforcement `json:"enforce_admins"` | ||
Restrictions *BranchRestrictions `json:"restrictions"` | ||
} | ||
|
||
// ProtectionRequest represents a request to create/edit a branch's protection. | ||
type ProtectionRequest struct { | ||
RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"` | ||
RequiredPullRequestReviews *RequiredPullRequestReviews `json:"required_pull_request_reviews"` | ||
EnforceAdmins bool `json:"enforce_admins"` | ||
Restrictions *BranchRestrictionsRequest `json:"restrictions"` | ||
} | ||
|
||
// RequiredStatusChecks represents the protection status of a individual branch. | ||
type RequiredStatusChecks struct { | ||
// Enforce required status checks for repository administrators. (Required.) | ||
// Deprecated: Use EnforceAdmins instead. | ||
IncludeAdmins bool `json:"include_admins"` | ||
// Require branches to be up to date before merging. (Required.) | ||
Strict bool `json:"strict"` | ||
|
@@ -535,9 +538,16 @@ type RequiredStatusChecks struct { | |
// RequiredPullRequestReviews represents the protection configuration for pull requests. | ||
type RequiredPullRequestReviews struct { | ||
// Enforce pull request reviews for repository administrators. (Required.) | ||
// Deprecated: Use EnforceAdmins instead. | ||
IncludeAdmins bool `json:"include_admins"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to fully resolve #606, I think you should mark Same for If you deprecate it, then change PR description to "Helps #606.", so it won't be closed. We want to use that issue to track the entire change for https://developer.github.com/changes/2017-03-22-protected-branches-admin-improvements/, which includes removing the old way of setting admin. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shurcooL I'm not sure about deprecation, seems like an overhead, maybe it's better just to remove old fields. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to go for it and make that a part of this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shurcooL struct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I understand, we want to remove I would suspect that yes, we want to remove
I'm not sure if that's out of date or a typo... For next step, I'd recommend either settling by marking
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll contact support and try out how API behaves currently if no value is set for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shurcooL No reply from support yet, but here are test results:
So, it's safe to remove required_pull_request_reviews from the request completely. For required_status_checks:
So, required_status_checks has to include include_admins field. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The It's pretty puzzling to me how to use the new API. There are two There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shurcooL I've checked how it works. When setting either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think this is confusing Go API for go-github users. But, this falls on GitHub, and it's temporary. According to https://developer.github.com/changes/2017-03-22-protected-branches-admin-improvements/, they'll remove the deprecated So, this is okay by me, I won't request further improvements (I can think of some, but I don't think it's worth the overhead). |
||
} | ||
|
||
// AdminEnforcement represents the configuration to enforce required status checks for repository administrators. | ||
type AdminEnforcement struct { | ||
URL *string `json:"url,omitempty"` | ||
Enabled bool `json:"enabled"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason I think I get the reason, but it seems a bit arbitrary. I don't have any suggestions for improvement, so this is okay with me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @amirilovic, I'm trying to understand your approach here. If you won't mind, could you response to shurcooL question? I'm new in Go world I'm still trying to figure it out what is the best use-case for pointers fields and type fields in structs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @navarrano See #537 and the issues it mentions for background information on this. The TLDR is that this is a style choice, both ways work. Using pointers allows users to know whether the value was actually present in the GitHub response or not, but they have to deal with a pointer. Using values means you can't know if it's a zero value or it was present in GH response, but no pointers to deal with. My understanding is that It also has to do with consistency with other similar structs for this API. But it could've gone in another way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
// BranchRestrictions represents the restriction that only certain users or | ||
// teams may push to a branch. | ||
type BranchRestrictions struct { | ||
|
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 names of other structs here take pretty closely after the field name itself.
Have you considered naming this struct something like
EnforceAdmins
? If so, what made you pickAdminEnforcement
instead?It seems like the latter sounds better, but I'm a little unsure about the deviation from the pattern. Do you have any comments on this?
I'm on the fence about this, that's why I want to ask for your thoughts.
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 choose AdminEnforcement because of: https://developer.github.com/v3/repos/branches/#get-admin-enforcement-of-protected-branch
The GET request states: Get admin enforcement of protected branch, which makes sense because it is actually a nested resource, not just a flag.
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.
Sounds good, that's convincing rationale, thanks for providing it.