Repository: google/go-github (go)

Issue:
Add fields to get branch protection API to match GitHub APIs
Upon comparing the API response of the [get branch protection endpoint](https://docs.github.com/en/rest/branches/branch-protection#get-branch-protection) and the struct implemented here I noticed a few fields missing:
- `required_pull_request_reviews.url string`
- `required_signatures.enabled boolean`
- `required_signature.url string`
- `required_status_checks.contexts []string`
- `required_status_checks.contexts_url string`
- `required_status_checks.url string`
- `url string`

Not sure if the `url` types of fields are left out on purpose but there are some cases when they are implemented (eg. `enforce_admins.url`) so I included them.

Pull request description:
Add fields to `Branch Protection` endpoint
Fixes #2719

This adds a few fields that were requested in #2719.

Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 92a952ef..ae6e2867 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -13046,6 +13046,14 @@ func (p *Protection) GetRequiredPullRequestReviews() *PullRequestReviewsEnforcem
 	return p.RequiredPullRequestReviews
 }
 
+// GetRequiredSignatures returns the RequiredSignatures field.
+func (p *Protection) GetRequiredSignatures() *SignaturesProtectedBranch {
+	if p == nil {
+		return nil
+	}
+	return p.RequiredSignatures
+}
+
 // GetRequiredStatusChecks returns the RequiredStatusChecks field.
 func (p *Protection) GetRequiredStatusChecks() *RequiredStatusChecks {
 	if p == nil {
@@ -13070,6 +13078,14 @@ func (p *Protection) GetRestrictions() *BranchRestrictions {
 	return p.Restrictions
 }
 
+// GetURL returns the URL field if it's non-nil, zero value otherwise.
+func (p *Protection) GetURL() string {
+	if p == nil || p.URL == nil {
+		return ""
+	}
+	return *p.URL
+}
+
 // GetAdminEnforced returns the AdminEnforced field.
 func (p *ProtectionChanges) GetAdminEnforced() *AdminEnforcedChanges {
 	if p == nil {
@@ -17718,6 +17734,22 @@ func (r *RequiredStatusCheck) GetAppID() int64 {
 	return *r.AppID
 }
 
+// GetContextsURL returns the ContextsURL field if it's non-nil, zero value otherwise.
+func (r *RequiredStatusChecks) GetContextsURL() string {
+	if r == nil || r.ContextsURL == nil {
+		return ""
+	}
+	return *r.ContextsURL
+}
+
+// GetURL returns the URL field if it's non-nil, zero value otherwise.
+func (r *RequiredStatusChecks) GetURL() string {
+	if r == nil || r.URL == nil {
+		return ""
+	}
+	return *r.URL
+}
+
 // GetFrom returns the From field if it's non-nil, zero value otherwise.
 func (r *RequiredStatusChecksEnforcementLevelChanges) GetFrom() string {
 	if r == nil || r.From == nil {
diff --git a/github/repos.go b/github/repos.go
index fad152e2..9c9c7506 100644
--- a/github/repos.go
+++ b/github/repos.go
@@ -847,6 +847,8 @@ type Protection struct {
 	BlockCreations                 *BlockCreations                 `json:"block_creations,omitempty"`
 	LockBranch                     *LockBranch                     `json:"lock_branch,omitempty"`
 	AllowForkSyncing               *AllowForkSyncing               `json:"allow_fork_syncing,omitempty"`
+	RequiredSignatures             *SignaturesProtectedBranch      `json:"required_signatures,omitempty"`
+	URL                            *string                         `json:"url,omitempty"`
 }
 
 // BlockCreations represents whether users can push changes that create branches. If this is true, this
@@ -1023,7 +1025,9 @@ type RequiredStatusChecks struct {
 	Contexts []string `json:"contexts,omitempty"`
 	// The list of status checks to require in order to merge into this
 	// branch.
-	Checks []*RequiredStatusCheck `json:"checks"`
+	Checks      []*RequiredStatusCheck `json:"checks"`
+	ContextsURL *string                `json:"contexts_url,omitempty"`
+	URL         *string                `json:"url,omitempty"`
 }
 
 // RequiredStatusChecksRequest represents a request to edit a protected branch's status checks.


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index fae13c0e..487104fb 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -15237,6 +15237,13 @@ func TestProtection_GetRequiredPullRequestReviews(tt *testing.T) {
 	p.GetRequiredPullRequestReviews()
 }
 
+func TestProtection_GetRequiredSignatures(tt *testing.T) {
+	p := &Protection{}
+	p.GetRequiredSignatures()
+	p = nil
+	p.GetRequiredSignatures()
+}
+
 func TestProtection_GetRequiredStatusChecks(tt *testing.T) {
 	p := &Protection{}
 	p.GetRequiredStatusChecks()
@@ -15258,6 +15265,16 @@ func TestProtection_GetRestrictions(tt *testing.T) {
 	p.GetRestrictions()
 }
 
+func TestProtection_GetURL(tt *testing.T) {
+	var zeroValue string
+	p := &Protection{URL: &zeroValue}
+	p.GetURL()
+	p = &Protection{}
+	p.GetURL()
+	p = nil
+	p.GetURL()
+}
+
 func TestProtectionChanges_GetAdminEnforced(tt *testing.T) {
 	p := &ProtectionChanges{}
 	p.GetAdminEnforced()
@@ -20639,6 +20656,26 @@ func TestRequiredStatusCheck_GetAppID(tt *testing.T) {
 	r.GetAppID()
 }
 
+func TestRequiredStatusChecks_GetContextsURL(tt *testing.T) {
+	var zeroValue string
+	r := &RequiredStatusChecks{ContextsURL: &zeroValue}
+	r.GetContextsURL()
+	r = &RequiredStatusChecks{}
+	r.GetContextsURL()
+	r = nil
+	r.GetContextsURL()
+}
+
+func TestRequiredStatusChecks_GetURL(tt *testing.T) {
+	var zeroValue string
+	r := &RequiredStatusChecks{URL: &zeroValue}
+	r.GetURL()
+	r = &RequiredStatusChecks{}
+	r.GetURL()
+	r = nil
+	r.GetURL()
+}
+
 func TestRequiredStatusChecksEnforcementLevelChanges_GetFrom(tt *testing.T) {
 	var zeroValue string
 	r := &RequiredStatusChecksEnforcementLevelChanges{From: &zeroValue}