Skip to content

Commit

Permalink
fix: repo rules bypass settings
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sama committed Jul 15, 2023
1 parent cd43862 commit 889737e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 37 deletions.
24 changes: 16 additions & 8 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 20 additions & 10 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions github/orgs_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")},
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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")},
Expand Down Expand Up @@ -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"},
Expand All @@ -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")},
Expand Down
10 changes: 5 additions & 5 deletions github/repos_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -312,17 +314,15 @@ 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"`
// Possible values for SourceType are: Repository, Organization
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"`
Expand Down
10 changes: 5 additions & 5 deletions github/repos_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -421,7 +421,7 @@ func TestRepositoriesService_GetRuleset(t *testing.T) {
}

want := &Ruleset{
ID: 42,
ID: Int64(42),
Name: "ruleset",
SourceType: String("Organization"),
Source: "o",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 889737e

Please sign in to comment.