Repository: google/go-github
Pull request #2577 (2022-11-26 19:00:40)

Add LockBranch and AllowForkSyncing to repos.go
Fixes https://github.com/google/go-github/issues/2574 , and it is mostly a direct, if barebones, implementation of the plan ideated there. Adding references to `LockBranch` and `AllowForkSyncing`. References to `RequireLastPushApproval` were added in cb24cabfacd4bff06727d5b3acea48ba56e5f690 . There might be some changes left to do.

XaurDesu: I can't seem to replicate the failing test in my local environment, already ran `gofmt` and `go generate`, but it seems to have no effect on tests, i think i might have a configuration problem on my end but i can't seem to figure it out.
dtdao: From checking the workflow file. The tests didnt run.  Its failing at the
https://github.com/google/go-github/blob/621c4ba7155bee18761f308a86fa71fddf3476b4/.github/workflows/tests.yml#L64

specifically at `git diff --exit-code; ` portion of it.  
gmlewis: Yes, you are correct, @dtdao - thank you for the detailed explanation. 

This information should also be covered in our CONTRIBUTING.md guide at the top of this repo... if you feel that it can be made clearer, we welcome PRs for it as well.
XaurDesu: I agree that `CONTRIBUTING.md` could (and probably should) be clearer about some things, but as it should be evident by now, I'm pretty new to this kind of workflow, and i would rather solve a few more issues to get accustomed to the codebase before messing with any documentation we have, especially kind that regards new contributors. Maybe @dtdao could check that out.
codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/2577?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2577](https://codecov.io/gh/google/go-github/pull/2577?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (bc17062) into [master](https://codecov.io/gh/google/go-github/commit/621c4ba7155bee18761f308a86fa71fddf3476b4?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (621c4ba) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #2577   +/-   ##
=======================================
  Coverage   97.98%   97.98%           
=======================================
  Files         125      125           
  Lines       10875    10875           
=======================================
  Hits        10656    10656           
  Misses        150      150           
  Partials       69       69           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/2577?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/repos.go](https://codecov.io/gh/google/go-github/pull/2577/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL3JlcG9zLmdv) | `98.67% <ø> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)


Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 2cc8ce0d..33de4b7e 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -12254,6 +12254,14 @@ func (p *Protection) GetAllowForcePushes() *AllowForcePushes {
 	return p.AllowForcePushes
 }
 
+// GetAllowForkSyncing returns the AllowForkSyncing field if it's non-nil, zero value otherwise.
+func (p *Protection) GetAllowForkSyncing() bool {
+	if p == nil || p.AllowForkSyncing == nil {
+		return false
+	}
+	return *p.AllowForkSyncing
+}
+
 // GetEnforceAdmins returns the EnforceAdmins field.
 func (p *Protection) GetEnforceAdmins() *AdminEnforcement {
 	if p == nil {
@@ -12262,6 +12270,14 @@ func (p *Protection) GetEnforceAdmins() *AdminEnforcement {
 	return p.EnforceAdmins
 }
 
+// GetLockBranch returns the LockBranch field if it's non-nil, zero value otherwise.
+func (p *Protection) GetLockBranch() bool {
+	if p == nil || p.LockBranch == nil {
+		return false
+	}
+	return *p.LockBranch
+}
+
 // GetRequiredConversationResolution returns the RequiredConversationResolution field.
 func (p *Protection) GetRequiredConversationResolution() *RequiredConversationResolution {
 	if p == nil {
diff --git a/github/repos.go b/github/repos.go
index 9364e8d6..2b1a263f 100644
--- a/github/repos.go
+++ b/github/repos.go
@@ -840,6 +840,10 @@ type Protection struct {
 	AllowForcePushes               *AllowForcePushes               `json:"allow_force_pushes"`
 	AllowDeletions                 *AllowDeletions                 `json:"allow_deletions"`
 	RequiredConversationResolution *RequiredConversationResolution `json:"required_conversation_resolution"`
+	// LockBranch represents if the branch is marked as read-only. If this is true, users will not be able to push to the branch.
+	LockBranch *bool `json:"lock_branch,omitempty"`
+	// AllowForkSyncing represents whether users can pull changes from upstream when the branch is locked.
+	AllowForkSyncing *bool `json:"allow_fork_syncing,omitempty"`
 }
 
 // BranchProtectionRule represents the rule applied to a repositories branch.


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index c0565725..ecc0d761 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -14310,6 +14310,16 @@ func TestProtection_GetAllowForcePushes(tt *testing.T) {
 	p.GetAllowForcePushes()
 }
 
+func TestProtection_GetAllowForkSyncing(tt *testing.T) {
+	var zeroValue bool
+	p := &Protection{AllowForkSyncing: &zeroValue}
+	p.GetAllowForkSyncing()
+	p = &Protection{}
+	p.GetAllowForkSyncing()
+	p = nil
+	p.GetAllowForkSyncing()
+}
+
 func TestProtection_GetEnforceAdmins(tt *testing.T) {
 	p := &Protection{}
 	p.GetEnforceAdmins()
@@ -14317,6 +14327,16 @@ func TestProtection_GetEnforceAdmins(tt *testing.T) {
 	p.GetEnforceAdmins()
 }
 
+func TestProtection_GetLockBranch(tt *testing.T) {
+	var zeroValue bool
+	p := &Protection{LockBranch: &zeroValue}
+	p.GetLockBranch()
+	p = &Protection{}
+	p.GetLockBranch()
+	p = nil
+	p.GetLockBranch()
+}
+
 func TestProtection_GetRequiredConversationResolution(tt *testing.T) {
 	p := &Protection{}
 	p.GetRequiredConversationResolution()