diff --git a/github/github-accessors.go b/github/github-accessors.go index 009b1bebef..1be9493a37 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 { @@ -19046,14 +19054,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 { @@ -19062,6 +19062,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 4671670ce0..2235cc5e13 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() @@ -22209,16 +22219,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() @@ -22226,6 +22226,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 48c6c5e2bd..50ba4e20c0 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_RepoNames(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_RepoNames(t *testing.T) } want := &Ruleset{ - ID: 21, + ID: Int64(21), Name: "ruleset", Target: String("branch"), SourceType: String("Organization"), @@ -524,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"), @@ -608,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"), @@ -758,13 +757,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")}, @@ -853,7 +851,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"}, @@ -875,13 +872,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 ee9c82e714..4e6f5f1347 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. @@ -319,7 +321,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"` @@ -327,9 +329,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 42c7a6e2ec..582ec89245 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",