From 889737edcf726c84d2c552679b1ad2d77cdb671d Mon Sep 17 00:00:00 2001 From: Osama Faqhruldin Date: Sat, 15 Jul 2023 00:08:01 -0400 Subject: [PATCH 1/2] fix: repo rules bypass settings --- github/github-accessors.go | 24 ++++++++++++++++-------- github/github-accessors_test.go | 30 ++++++++++++++++++++---------- github/orgs_rules_test.go | 14 +++++--------- github/repos_rules.go | 10 +++++----- github/repos_rules_test.go | 10 +++++----- 5 files changed, 51 insertions(+), 37 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index c7089951a34..c22073f9228 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -2238,6 +2238,14 @@ func (b *BypassActor) GetActorType() string { return *b.ActorType } +// GetBypassMode returns the BypassMode field if it's non-nil, zero value otherwise. +func (b *BypassActor) GetBypassMode() string { + if b == nil || b.BypassMode == nil { + return "" + } + return *b.BypassMode +} + // GetApp returns the App field. func (c *CheckRun) GetApp() *App { if c == nil { @@ -18894,14 +18902,6 @@ func (r *RuleRequiredStatusChecks) GetIntegrationID() int64 { return *r.IntegrationID } -// GetBypassMode returns the BypassMode field if it's non-nil, zero value otherwise. -func (r *Ruleset) GetBypassMode() string { - if r == nil || r.BypassMode == nil { - return "" - } - return *r.BypassMode -} - // GetConditions returns the Conditions field. func (r *Ruleset) GetConditions() *RulesetConditions { if r == nil { @@ -18910,6 +18910,14 @@ func (r *Ruleset) GetConditions() *RulesetConditions { return r.Conditions } +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (r *Ruleset) GetID() int64 { + if r == nil || r.ID == nil { + return 0 + } + return *r.ID +} + // GetLinks returns the Links field. func (r *Ruleset) GetLinks() *RulesetLinks { if r == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 7d151331cbb..323708176d4 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -2684,6 +2684,16 @@ func TestBypassActor_GetActorType(tt *testing.T) { b.GetActorType() } +func TestBypassActor_GetBypassMode(tt *testing.T) { + var zeroValue string + b := &BypassActor{BypassMode: &zeroValue} + b.GetBypassMode() + b = &BypassActor{} + b.GetBypassMode() + b = nil + b.GetBypassMode() +} + func TestCheckRun_GetApp(tt *testing.T) { c := &CheckRun{} c.GetApp() @@ -22043,16 +22053,6 @@ func TestRuleRequiredStatusChecks_GetIntegrationID(tt *testing.T) { r.GetIntegrationID() } -func TestRuleset_GetBypassMode(tt *testing.T) { - var zeroValue string - r := &Ruleset{BypassMode: &zeroValue} - r.GetBypassMode() - r = &Ruleset{} - r.GetBypassMode() - r = nil - r.GetBypassMode() -} - func TestRuleset_GetConditions(tt *testing.T) { r := &Ruleset{} r.GetConditions() @@ -22060,6 +22060,16 @@ func TestRuleset_GetConditions(tt *testing.T) { r.GetConditions() } +func TestRuleset_GetID(tt *testing.T) { + var zeroValue int64 + r := &Ruleset{ID: &zeroValue} + r.GetID() + r = &Ruleset{} + r.GetID() + r = nil + r.GetID() +} + func TestRuleset_GetLinks(tt *testing.T) { r := &Ruleset{} r.GetLinks() diff --git a/github/orgs_rules_test.go b/github/orgs_rules_test.go index 7719e142fb5..03226741e56 100644 --- a/github/orgs_rules_test.go +++ b/github/orgs_rules_test.go @@ -44,13 +44,12 @@ func TestOrganizationsService_GetAllOrganizationRulesets(t *testing.T) { } want := []*Ruleset{{ - ID: 26110, + ID: Int64(26110), Name: "test ruleset", Target: String("branch"), SourceType: String("Organization"), Source: "o", Enforcement: "active", - BypassMode: String("none"), NodeID: String("nid"), Links: &RulesetLinks{ Self: &RulesetLink{HRef: String("https://api.github.com/orgs/o/rulesets/26110")}, @@ -210,7 +209,7 @@ func TestOrganizationsService_CreateOrganizationRuleset(t *testing.T) { ctx := context.Background() ruleset, _, err := client.Organizations.CreateOrganizationRuleset(ctx, "o", &Ruleset{ - ID: 21, + ID: Int64(21), Name: "ruleset", Target: String("branch"), SourceType: String("Organization"), @@ -296,7 +295,7 @@ func TestOrganizationsService_CreateOrganizationRuleset(t *testing.T) { } want := &Ruleset{ - ID: 21, + ID: Int64(21), Name: "ruleset", Target: String("branch"), SourceType: String("Organization"), @@ -448,13 +447,12 @@ func TestOrganizationsService_GetOrganizationRuleset(t *testing.T) { } want := &Ruleset{ - ID: 26110, + ID: Int64(26110), Name: "test ruleset", Target: String("branch"), SourceType: String("Organization"), Source: "o", Enforcement: "active", - BypassMode: String("none"), NodeID: String("nid"), Links: &RulesetLinks{ Self: &RulesetLink{HRef: String("https://api.github.com/orgs/o/rulesets/26110")}, @@ -543,7 +541,6 @@ func TestOrganizationsService_UpdateOrganizationRuleset(t *testing.T) { Name: "test ruleset", Target: String("branch"), Enforcement: "active", - BypassMode: String("none"), Conditions: &RulesetConditions{ RefName: &RulesetRefConditionParameters{ Include: []string{"refs/heads/main", "refs/heads/master"}, @@ -565,13 +562,12 @@ func TestOrganizationsService_UpdateOrganizationRuleset(t *testing.T) { } want := &Ruleset{ - ID: 26110, + ID: Int64(26110), Name: "test ruleset", Target: String("branch"), SourceType: String("Organization"), Source: "o", Enforcement: "active", - BypassMode: String("none"), NodeID: String("nid"), Links: &RulesetLinks{ Self: &RulesetLink{HRef: String("https://api.github.com/orgs/o/rulesets/26110")}, diff --git a/github/repos_rules.go b/github/repos_rules.go index 9299d3e7f3d..b5b6e15ac14 100644 --- a/github/repos_rules.go +++ b/github/repos_rules.go @@ -14,8 +14,10 @@ import ( // BypassActor represents the bypass actors from a ruleset. type BypassActor struct { ActorID *int64 `json:"actor_id,omitempty"` - // Possible values for ActorType are: Team, Integration + // Possible values for ActorType are: RepositoryRole, Team, Integration, OrganizationAdmin ActorType *string `json:"actor_type,omitempty"` + // Possible values for BypassMode are: always, pull_request + BypassMode *string `json:"bypass_mode,omitempty"` } // RulesetLink represents a single link object from GitHub ruleset request _links. @@ -312,7 +314,7 @@ func NewTagNamePatternRule(params *RulePatternParameters) (rule *RepositoryRule) // Ruleset represents a GitHub ruleset object. type Ruleset struct { - ID int64 `json:"id"` + ID *int64 `json:"id,omitempty"` Name string `json:"name"` // Possible values for Target are branch, tag Target *string `json:"target,omitempty"` @@ -320,9 +322,7 @@ type Ruleset struct { SourceType *string `json:"source_type,omitempty"` Source string `json:"source"` // Possible values for Enforcement are: disabled, active, evaluate - Enforcement string `json:"enforcement"` - // Possible values for BypassMode are: none, repository, organization - BypassMode *string `json:"bypass_mode,omitempty"` + Enforcement string `json:"enforcement"` BypassActors []*BypassActor `json:"bypass_actors,omitempty"` NodeID *string `json:"node_id,omitempty"` Links *RulesetLinks `json:"_links,omitempty"` diff --git a/github/repos_rules_test.go b/github/repos_rules_test.go index 42c7a6e2ec2..582ec89245b 100644 --- a/github/repos_rules_test.go +++ b/github/repos_rules_test.go @@ -324,14 +324,14 @@ func TestRepositoriesService_GetAllRulesets(t *testing.T) { want := []*Ruleset{ { - ID: 42, + ID: Int64(42), Name: "ruleset", SourceType: String("Repository"), Source: "o/repo", Enforcement: "enabled", }, { - ID: 314, + ID: Int64(314), Name: "Another ruleset", SourceType: String("Repository"), Source: "o/repo", @@ -378,7 +378,7 @@ func TestRepositoriesService_CreateRuleset(t *testing.T) { } want := &Ruleset{ - ID: 42, + ID: Int64(42), Name: "ruleset", SourceType: String("Repository"), Source: "o/repo", @@ -421,7 +421,7 @@ func TestRepositoriesService_GetRuleset(t *testing.T) { } want := &Ruleset{ - ID: 42, + ID: Int64(42), Name: "ruleset", SourceType: String("Organization"), Source: "o", @@ -467,7 +467,7 @@ func TestRepositoriesService_UpdateRuleset(t *testing.T) { } want := &Ruleset{ - ID: 42, + ID: Int64(42), Name: "ruleset", SourceType: String("Repository"), Source: "o/repo", From cb3756272792b47fb57c7779f99ab3133bfae70e Mon Sep 17 00:00:00 2001 From: Osama Faqhruldin Date: Mon, 17 Jul 2023 12:55:49 -0400 Subject: [PATCH 2/2] Update test cases introduced in latest commit to master --- github/orgs_rules_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/orgs_rules_test.go b/github/orgs_rules_test.go index dfa7e2d26e6..50ba4e20c01 100644 --- a/github/orgs_rules_test.go +++ b/github/orgs_rules_test.go @@ -523,7 +523,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) { ctx := context.Background() ruleset, _, err := client.Organizations.CreateOrganizationRuleset(ctx, "o", &Ruleset{ - ID: 21, + ID: Int64(21), Name: "ruleset", Target: String("branch"), SourceType: String("Organization"), @@ -607,7 +607,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) { } want := &Ruleset{ - ID: 21, + ID: Int64(21), Name: "ruleset", Target: String("branch"), SourceType: String("Organization"),