Skip to content

Add new branch protection values - #1393

Merged
gmlewis merged 2 commits into
google:masterfrom
tjamet:branch-protection
Jan 24, 2020
Merged

gmlewis merged 2 commits into
google:masterfrom
tjamet:branch-protection

Conversation

@tjamet

@tjamet tjamet commented Jan 23, 2020

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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

tjamet commented Jan 23, 2020

Copy link
Copy Markdown
Contributor Author

@googlebot I signed it!

@googlebot

Copy link
Copy Markdown

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

@gmlewis gmlewis left a comment

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.

Thank you, @tjamet.
This is a good start, but please address the comments below and we can then proceed with the PR.

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

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

Comment thread github/repos.go Outdated
Restrictions *BranchRestrictions `json:"restrictions"`
RequireLinearHistory *LinearHistoryEnforcement `json:"required_linear_history"`
AllowForcePushes *ForcePushTolerance `json:"allow_force_pushes"`
AllowDeletions *DeletionTolerance `json:"allow_deletions"`

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.

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

gmlewis commented Jan 24, 2020

Copy link
Copy Markdown
Collaborator

Fixes #1345.
Closes #1354.

@tjamet
tjamet force-pushed the branch-protection branch from 371e8b8 to 0f042d8 Compare January 24, 2020 09:10
@tjamet

tjamet commented Jan 24, 2020

Copy link
Copy Markdown
Contributor Author

Thanks for the fast feedback, request changes addressed

@gmlewis gmlewis left a comment

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.

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
jlaportebot added a commit to jlaportebot/go-github that referenced this pull request Jun 28, 2026
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