From 4caa1d6d12a652a6656bb72c1985393bfe6203d9 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sun, 9 Apr 2023 22:36:03 +0300 Subject: [PATCH] Add fields to Branch Protection endpoint (#2744) Fixes: #2719. --- github/github-accessors.go | 32 ++++++++++++++++++++++++++++ github/github-accessors_test.go | 37 +++++++++++++++++++++++++++++++++ github/repos.go | 6 +++++- 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 92a952efb33..ae6e2867259 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/github-accessors_test.go b/github/github-accessors_test.go index fae13c0ef97..487104fb0d1 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} diff --git a/github/repos.go b/github/repos.go index fad152e22f2..9c9c7506309 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.