From 6760a5c8b28568e7545282578f50cb216a9183f1 Mon Sep 17 00:00:00 2001 From: Guy Eldar Date: Tue, 1 Jul 2025 23:41:55 +0300 Subject: [PATCH] Added the ProtectionURL field to the Branch struct Included a GetProtectionURL method and test. --- github/github-accessors.go | 8 ++++++++ github/github-accessors_test.go | 11 +++++++++++ github/repos.go | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 57e2d07dfc8..2dc33c6a6aa 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -1614,6 +1614,14 @@ func (b *Branch) GetProtection() *Protection { return b.Protection } +// GetProtectionURL returns the ProtectionURL field if it's non-nil, zero value otherwise. +func (b *Branch) GetProtectionURL() string { + if b == nil || b.ProtectionURL == nil { + return "" + } + return *b.ProtectionURL +} + // GetCommit returns the Commit field. func (b *BranchCommit) GetCommit() *Commit { if b == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 1e66350a1d7..6392c967f7c 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -2122,6 +2122,17 @@ func TestBranch_GetProtection(tt *testing.T) { b.GetProtection() } +func TestBranch_GetProtectionURL(tt *testing.T) { + tt.Parallel() + var zeroValue string + b := &Branch{ProtectionURL: &zeroValue} + b.GetProtectionURL() + b = &Branch{} + b.GetProtectionURL() + b = nil + b.GetProtectionURL() +} + func TestBranchCommit_GetCommit(tt *testing.T) { tt.Parallel() b := &BranchCommit{} diff --git a/github/repos.go b/github/repos.go index 71483534363..e4f9cc0c074 100644 --- a/github/repos.go +++ b/github/repos.go @@ -1010,7 +1010,8 @@ type Branch struct { // such as 'List branches'. In such cases, if branch protection is // enabled, Protected will be `true` but this will be nil, and // additional protection details can be obtained by calling GetBranch(). - Protection *Protection `json:"protection,omitempty"` + Protection *Protection `json:"protection,omitempty"` + ProtectionURL *string `json:"protection_url,omitempty"` } // Protection represents a repository branch's protection.