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 new branch protection values #1393

Merged
merged 2 commits into from
Jan 24, 2020
Merged

Conversation

tjamet
Copy link
Contributor

@tjamet tjamet commented Jan 23, 2020

GitHub has been adding some new fields in the branch protections
as documented:
https://developer.github.com/v3/repos/branches/#get-branch-protection

the documentation references the new fields in the branch protection as:

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

  "required_linear_history": {
    "enabled": true
  },
  "allow_force_pushes": {
    "enabled": true
  },
  "allow_deletions": {
    "enabled": true
  }

https://developer.github.com/v3/repos/branches/#update-branch-protection:
PUT /repos/:owner/:repo/branches/:branch/protection

field type required?
required_linear_history boolean optional
allow_force_pushes boolean optional
allow_deletions boolean optional

This PR achieves a similar goal as #1354, addressing comments.
Unlike suggestion in #1354 comment, the EnabledType is not defined as is, instead individual types are declared to prevent interface change if ever the field type changes.

Fixes #1345

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@tjamet
Copy link
Contributor Author

tjamet commented Jan 23, 2020

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Indication that the PR author has signed a Google Contributor License Agreement. and removed cla: no labels Jan 23, 2020
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, @tjamet.
This is a good start, but please address the comments below and we can then proceed with the PR.

github/repos.go Outdated
@@ -735,6 +738,12 @@ type ProtectionRequest struct {
RequiredPullRequestReviews *PullRequestReviewsEnforcementRequest `json:"required_pull_request_reviews"`
EnforceAdmins bool `json:"enforce_admins"`
Restrictions *BranchRestrictionsRequest `json:"restrictions"`
// Enforces a linear commit Git history, which prevents anyone from pushing merge commits to a branch.
RequireLinearHistory *bool `json:"required_linear_history,omiteempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

omitempty is spelled incorrectly each time. Please fix all three.

github/repos.go Outdated
@@ -735,6 +738,12 @@ type ProtectionRequest struct {
RequiredPullRequestReviews *PullRequestReviewsEnforcementRequest `json:"required_pull_request_reviews"`
EnforceAdmins bool `json:"enforce_admins"`
Restrictions *BranchRestrictionsRequest `json:"restrictions"`
// Enforces a linear commit Git history, which prevents anyone from pushing merge commits to a branch.
RequireLinearHistory *bool `json:"required_linear_history,omiteempty"`
// Permits force pushes to the protected branch by anyone with write access to the repository
Copy link
Collaborator

Choose a reason for hiding this comment

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

Every new comment in this PR needs to be a complete sentence ending in a period (".") so that the auto-generated Godocs will read nicely, and to be consistent with the rest of the repo. Please check each comment and fix as needed.

github/repos.go Outdated
@@ -727,6 +727,9 @@ type Protection struct {
RequiredPullRequestReviews *PullRequestReviewsEnforcement `json:"required_pull_request_reviews"`
EnforceAdmins *AdminEnforcement `json:"enforce_admins"`
Restrictions *BranchRestrictions `json:"restrictions"`
RequireLinearHistory *LinearHistoryEnforcement `json:"required_linear_history"`
AllowForcePushes *ForcePushTolerance `json:"allow_force_pushes"`
AllowDeletions *DeletionTolerance `json:"allow_deletions"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although these three new struct names are good choices on their own, let's please rename them to match the name of the field, for two reasons... first, to be more consistent with the rest of the repo, and second to reduce confusion when searching for the struct or the field. So to be clear, let's please rename these structs to RequireLinearHistory, AllowForcePushes, and AllowDeletions, respectively.

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 24, 2020

Fixes #1345.
Closes #1354.

GitHub has been adding some new fields in the branch protections
as documented:
https://developer.github.com/v3/repos/branches/#get-branch-protection
Run go generate
@tjamet tjamet force-pushed the branch-protection branch from 371e8b8 to 0f042d8 Compare January 24, 2020 09:10
@tjamet
Copy link
Contributor Author

tjamet commented Jan 24, 2020

Thanks for the fast feedback, request changes addressed

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, @tjamet. LGTM. Merging.

(In the future, please try to remember not to force push commits to PRs for this repo, as it makes it more difficult for reviewers to see what changed since the last code review... not a big deal in this case, but if you make bigger PRs in the future, it is tremendously appreciated. Thanks. 😄)

@gmlewis gmlewis merged commit 8f818bc into google:master Jan 24, 2020
n1lesh pushed a commit to n1lesh/go-github that referenced this pull request Oct 2, 2020
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.

Feature Request > New branch protection features support
3 participants