From 79357aa1fd73c5931995b07afa17d353cd05719e Mon Sep 17 00:00:00 2001 From: Manuel Bergler Date: Thu, 10 Jul 2025 13:10:47 +0200 Subject: [PATCH] Add missing field to branch protection rule event structs --- github/github-accessors.go | 24 ++++++++++++++++++++++++ github/github-accessors_test.go | 30 ++++++++++++++++++++++++++++++ github/repos.go | 7 +++++++ 3 files changed, 61 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index 3b728d8d922..7f6499fe23a 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -1878,6 +1878,14 @@ func (b *BranchProtectionRule) GetRequiredStatusChecksEnforcementLevel() string return *b.RequiredStatusChecksEnforcementLevel } +// GetRequireLastPushApproval returns the RequireLastPushApproval field if it's non-nil, zero value otherwise. +func (b *BranchProtectionRule) GetRequireLastPushApproval() bool { + if b == nil || b.RequireLastPushApproval == nil { + return false + } + return *b.RequireLastPushApproval +} + // GetSignatureRequirementEnforcementLevel returns the SignatureRequirementEnforcementLevel field if it's non-nil, zero value otherwise. func (b *BranchProtectionRule) GetSignatureRequirementEnforcementLevel() string { if b == nil || b.SignatureRequirementEnforcementLevel == nil { @@ -18614,6 +18622,14 @@ func (p *ProtectionChanges) GetRequiredStatusChecksEnforcementLevel() *RequiredS return p.RequiredStatusChecksEnforcementLevel } +// GetRequireLastPushApproval returns the RequireLastPushApproval field. +func (p *ProtectionChanges) GetRequireLastPushApproval() *RequireLastPushApprovalChanges { + if p == nil { + return nil + } + return p.RequireLastPushApproval +} + // GetSignatureRequirementEnforcementLevel returns the SignatureRequirementEnforcementLevel field. func (p *ProtectionChanges) GetSignatureRequirementEnforcementLevel() *SignatureRequirementEnforcementLevelChanges { if p == nil { @@ -24038,6 +24054,14 @@ func (r *RequiredStatusChecksRuleParameters) GetDoNotEnforceOnCreate() bool { return *r.DoNotEnforceOnCreate } +// GetFrom returns the From field if it's non-nil, zero value otherwise. +func (r *RequireLastPushApprovalChanges) GetFrom() bool { + if r == nil || r.From == nil { + return false + } + return *r.From +} + // GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. func (r *ReviewersRequest) GetNodeID() string { if r == nil || r.NodeID == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 62e7fa7a43d..980688ae0ee 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -2467,6 +2467,17 @@ func TestBranchProtectionRule_GetRequiredStatusChecksEnforcementLevel(tt *testin b.GetRequiredStatusChecksEnforcementLevel() } +func TestBranchProtectionRule_GetRequireLastPushApproval(tt *testing.T) { + tt.Parallel() + var zeroValue bool + b := &BranchProtectionRule{RequireLastPushApproval: &zeroValue} + b.GetRequireLastPushApproval() + b = &BranchProtectionRule{} + b.GetRequireLastPushApproval() + b = nil + b.GetRequireLastPushApproval() +} + func TestBranchProtectionRule_GetSignatureRequirementEnforcementLevel(tt *testing.T) { tt.Parallel() var zeroValue string @@ -24060,6 +24071,14 @@ func TestProtectionChanges_GetRequiredStatusChecksEnforcementLevel(tt *testing.T p.GetRequiredStatusChecksEnforcementLevel() } +func TestProtectionChanges_GetRequireLastPushApproval(tt *testing.T) { + tt.Parallel() + p := &ProtectionChanges{} + p.GetRequireLastPushApproval() + p = nil + p.GetRequireLastPushApproval() +} + func TestProtectionChanges_GetSignatureRequirementEnforcementLevel(tt *testing.T) { tt.Parallel() p := &ProtectionChanges{} @@ -30909,6 +30928,17 @@ func TestRequiredStatusChecksRuleParameters_GetDoNotEnforceOnCreate(tt *testing. r.GetDoNotEnforceOnCreate() } +func TestRequireLastPushApprovalChanges_GetFrom(tt *testing.T) { + tt.Parallel() + var zeroValue bool + r := &RequireLastPushApprovalChanges{From: &zeroValue} + r.GetFrom() + r = &RequireLastPushApprovalChanges{} + r.GetFrom() + r = nil + r.GetFrom() +} + func TestReviewersRequest_GetNodeID(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/repos.go b/github/repos.go index e4f9cc0c074..2ce1df0596c 100644 --- a/github/repos.go +++ b/github/repos.go @@ -1074,6 +1074,7 @@ type BranchProtectionRule struct { RequiredConversationResolutionLevel *string `json:"required_conversation_resolution_level,omitempty"` AuthorizedActorsOnly *bool `json:"authorized_actors_only,omitempty"` AuthorizedActorNames []string `json:"authorized_actor_names,omitempty"` + RequireLastPushApproval *bool `json:"require_last_push_approval,omitempty"` } // ProtectionChanges represents the changes to the rule if the BranchProtection was edited. @@ -1093,6 +1094,7 @@ type ProtectionChanges struct { RequiredStatusChecks *RequiredStatusChecksChanges `json:"required_status_checks,omitempty"` RequiredStatusChecksEnforcementLevel *RequiredStatusChecksEnforcementLevelChanges `json:"required_status_checks_enforcement_level,omitempty"` SignatureRequirementEnforcementLevel *SignatureRequirementEnforcementLevelChanges `json:"signature_requirement_enforcement_level,omitempty"` + RequireLastPushApproval *RequireLastPushApprovalChanges `json:"require_last_push_approval,omitempty"` } // AdminEnforcedChanges represents the changes made to the AdminEnforced policy. @@ -1170,6 +1172,11 @@ type SignatureRequirementEnforcementLevelChanges struct { From *string `json:"from,omitempty"` } +// RequireLastPushApprovalChanges represents the changes made to the RequireLastPushApproval policy. +type RequireLastPushApprovalChanges struct { + From *bool `json:"from,omitempty"` +} + // ProtectionRequest represents a request to create/edit a branch's protection. type ProtectionRequest struct { RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"`