From 14b3be54deec2e35150783dc28500296dad7b55e Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sat, 8 Apr 2023 20:58:54 +0000 Subject: [PATCH 1/3] Add fields to `Branch Protection` endpoint Fixes #2719 This adds a few fields that were requested in #2719. --- github/github-accessors.go | 32 ++++++++++++++++++++++++++++ github/github-accessors_test.go | 37 +++++++++++++++++++++++++++++++++ github/repos.go | 9 ++++++++ 3 files changed, 78 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index 92a952efb33..a6ba4d90230 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() *RequiredSignatures { + 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..1c2ca9887ca 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..318f24f368c 100644 --- a/github/repos.go +++ b/github/repos.go @@ -834,6 +834,11 @@ type Branch struct { Protected *bool `json:"protected,omitempty"` } +type RequiredSignatures struct { + Url string `json:"url"` + Enabled bool `json:"enabled"` +} + // Protection represents a repository branch's protection. type Protection struct { RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"` @@ -847,6 +852,8 @@ type Protection struct { BlockCreations *BlockCreations `json:"block_creations,omitempty"` LockBranch *LockBranch `json:"lock_branch,omitempty"` AllowForkSyncing *AllowForkSyncing `json:"allow_fork_syncing,omitempty"` + RequiredSignatures *RequiredSignatures `json:"required_signatures,omitempty"` + Url *string `json:"url,omitempty"` } // BlockCreations represents whether users can push changes that create branches. If this is true, this @@ -1015,6 +1022,8 @@ type ProtectionRequest struct { // RequiredStatusChecks represents the protection status of a individual branch. type RequiredStatusChecks struct { + Url *string `json:"url,omitempty"` + ContextsUrl *string `json:"contexts_url,omitempty"` // Require branches to be up to date before merging. (Required.) Strict bool `json:"strict"` // The list of status checks to require in order to merge into this From 386f4bcb2ce113f0cdf9d923c122dbef12387332 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sun, 9 Apr 2023 08:31:18 +0000 Subject: [PATCH 2/3] Use `SignaturesProtectedBranch` instead of `RequiredSignatures` and `URL` instead of `Url` --- github/github-accessors.go | 26 +++++++++++++------------- github/github-accessors_test.go | 30 +++++++++++++++--------------- github/repos.go | 13 ++++--------- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index a6ba4d90230..ae6e2867259 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -13047,7 +13047,7 @@ func (p *Protection) GetRequiredPullRequestReviews() *PullRequestReviewsEnforcem } // GetRequiredSignatures returns the RequiredSignatures field. -func (p *Protection) GetRequiredSignatures() *RequiredSignatures { +func (p *Protection) GetRequiredSignatures() *SignaturesProtectedBranch { if p == nil { return nil } @@ -13078,12 +13078,12 @@ 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 { +// 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 + return *p.URL } // GetAdminEnforced returns the AdminEnforced field. @@ -17734,20 +17734,20 @@ 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 { +// 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 + 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 { +// 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 + return *r.URL } // GetFrom returns the From field if it's non-nil, zero value otherwise. diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 1c2ca9887ca..487104fb0d1 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -15265,14 +15265,14 @@ func TestProtection_GetRestrictions(tt *testing.T) { p.GetRestrictions() } -func TestProtection_GetUrl(tt *testing.T) { +func TestProtection_GetURL(tt *testing.T) { var zeroValue string - p := &Protection{Url: &zeroValue} - p.GetUrl() + p := &Protection{URL: &zeroValue} + p.GetURL() p = &Protection{} - p.GetUrl() + p.GetURL() p = nil - p.GetUrl() + p.GetURL() } func TestProtectionChanges_GetAdminEnforced(tt *testing.T) { @@ -20656,24 +20656,24 @@ func TestRequiredStatusCheck_GetAppID(tt *testing.T) { r.GetAppID() } -func TestRequiredStatusChecks_GetContextsUrl(tt *testing.T) { +func TestRequiredStatusChecks_GetContextsURL(tt *testing.T) { var zeroValue string - r := &RequiredStatusChecks{ContextsUrl: &zeroValue} - r.GetContextsUrl() + r := &RequiredStatusChecks{ContextsURL: &zeroValue} + r.GetContextsURL() r = &RequiredStatusChecks{} - r.GetContextsUrl() + r.GetContextsURL() r = nil - r.GetContextsUrl() + r.GetContextsURL() } -func TestRequiredStatusChecks_GetUrl(tt *testing.T) { +func TestRequiredStatusChecks_GetURL(tt *testing.T) { var zeroValue string - r := &RequiredStatusChecks{Url: &zeroValue} - r.GetUrl() + r := &RequiredStatusChecks{URL: &zeroValue} + r.GetURL() r = &RequiredStatusChecks{} - r.GetUrl() + r.GetURL() r = nil - r.GetUrl() + r.GetURL() } func TestRequiredStatusChecksEnforcementLevelChanges_GetFrom(tt *testing.T) { diff --git a/github/repos.go b/github/repos.go index 318f24f368c..35d698fd41e 100644 --- a/github/repos.go +++ b/github/repos.go @@ -834,11 +834,6 @@ type Branch struct { Protected *bool `json:"protected,omitempty"` } -type RequiredSignatures struct { - Url string `json:"url"` - Enabled bool `json:"enabled"` -} - // Protection represents a repository branch's protection. type Protection struct { RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"` @@ -852,8 +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 *RequiredSignatures `json:"required_signatures,omitempty"` - Url *string `json:"url,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 @@ -1022,8 +1017,8 @@ type ProtectionRequest struct { // RequiredStatusChecks represents the protection status of a individual branch. type RequiredStatusChecks struct { - Url *string `json:"url,omitempty"` - ContextsUrl *string `json:"contexts_url,omitempty"` + URL *string `json:"url,omitempty"` + ContextsURL *string `json:"contexts_url,omitempty"` // Require branches to be up to date before merging. (Required.) Strict bool `json:"strict"` // The list of status checks to require in order to merge into this From 23e1c6e9a57f6e3071b09265a10ae717d30de7ae Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sun, 9 Apr 2023 18:58:52 +0000 Subject: [PATCH 3/3] Move `URL` to the end --- github/repos.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/repos.go b/github/repos.go index 35d698fd41e..9c9c7506309 100644 --- a/github/repos.go +++ b/github/repos.go @@ -1017,8 +1017,6 @@ type ProtectionRequest struct { // RequiredStatusChecks represents the protection status of a individual branch. type RequiredStatusChecks struct { - URL *string `json:"url,omitempty"` - ContextsURL *string `json:"contexts_url,omitempty"` // Require branches to be up to date before merging. (Required.) Strict bool `json:"strict"` // The list of status checks to require in order to merge into this @@ -1027,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.