Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Refactor the repository ruleset code #3430

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion example/verifyartifact/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func main() {
}

err := runVerification(sev, pb, b)

if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion github/code_scanning.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func (s *CodeScanningService) UploadSarif(ctx context.Context, owner, repo strin
return nil, nil, err
}

// This will always return an error without unmarshalling the data
// This will always return an error without unmarshaling the data
resp, err := s.client.Do(ctx, req, nil)
// Even though there was an error, we still return the response
// in case the caller wants to inspect it further.
Expand Down
26 changes: 13 additions & 13 deletions github/enterprise_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import (
"fmt"
)

// CreateEnterpriseRuleset creates a ruleset for the specified enterprise.
// CreateRepositoryRuleset creates a repository ruleset for the specified enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/rules#create-an-enterprise-repository-ruleset
//
//meta:operation POST /enterprises/{enterprise}/rulesets
func (s *EnterpriseService) CreateEnterpriseRuleset(ctx context.Context, enterprise string, ruleset Ruleset) (*Ruleset, *Response, error) {
func (s *EnterpriseService) CreateRepositoryRuleset(ctx context.Context, enterprise string, ruleset RepositoryRuleset) (*RepositoryRuleset, *Response, error) {
u := fmt.Sprintf("enterprises/%v/rulesets", enterprise)

req, err := s.client.NewRequest("POST", u, ruleset)
if err != nil {
return nil, nil, err
}

var rs *Ruleset
var rs *RepositoryRuleset
resp, err := s.client.Do(ctx, req, &rs)
if err != nil {
return nil, resp, err
Expand All @@ -32,20 +32,20 @@ func (s *EnterpriseService) CreateEnterpriseRuleset(ctx context.Context, enterpr
return rs, resp, nil
}

// GetEnterpriseRuleset gets a ruleset from the specified enterprise.
// GetRepositoryRuleset gets a repository ruleset for the specified enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/rules#get-an-enterprise-repository-ruleset
//
//meta:operation GET /enterprises/{enterprise}/rulesets/{ruleset_id}
func (s *EnterpriseService) GetEnterpriseRuleset(ctx context.Context, enterprise string, rulesetID int64) (*Ruleset, *Response, error) {
func (s *EnterpriseService) GetRepositoryRuleset(ctx context.Context, enterprise string, rulesetID int64) (*RepositoryRuleset, *Response, error) {
u := fmt.Sprintf("enterprises/%v/rulesets/%v", enterprise, rulesetID)

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

var ruleset *Ruleset
var ruleset *RepositoryRuleset
resp, err := s.client.Do(ctx, req, &ruleset)
if err != nil {
return nil, resp, err
Expand All @@ -54,20 +54,20 @@ func (s *EnterpriseService) GetEnterpriseRuleset(ctx context.Context, enterprise
return ruleset, resp, nil
}

// UpdateEnterpriseRuleset updates a ruleset from the specified enterprise.
// UpdateRepositoryRuleset updates a repository ruleset for the specified enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/rules#update-an-enterprise-repository-ruleset
//
//meta:operation PUT /enterprises/{enterprise}/rulesets/{ruleset_id}
func (s *EnterpriseService) UpdateEnterpriseRuleset(ctx context.Context, enterprise string, rulesetID int64, ruleset Ruleset) (*Ruleset, *Response, error) {
func (s *EnterpriseService) UpdateRepositoryRuleset(ctx context.Context, enterprise string, rulesetID int64, ruleset RepositoryRuleset) (*RepositoryRuleset, *Response, error) {
u := fmt.Sprintf("enterprises/%v/rulesets/%v", enterprise, rulesetID)

req, err := s.client.NewRequest("PUT", u, ruleset)
if err != nil {
return nil, nil, err
}

var rs *Ruleset
var rs *RepositoryRuleset
resp, err := s.client.Do(ctx, req, &rs)
if err != nil {
return nil, resp, err
Expand All @@ -76,14 +76,14 @@ func (s *EnterpriseService) UpdateEnterpriseRuleset(ctx context.Context, enterpr
return rs, resp, nil
}

// UpdateEnterpriseRulesetClearBypassActor clears the ruleset bypass actors for a ruleset for the specified repository.
// UpdateRepositoryRulesetClearBypassActor clears the bypass actors for a repository ruleset for the specified enterprise.
//
// This function is necessary as the UpdateEnterpriseRuleset function does not marshal ByPassActor if passed as an empty array.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/rules#update-an-enterprise-repository-ruleset
//
//meta:operation PUT /enterprises/{enterprise}/rulesets/{ruleset_id}
func (s *EnterpriseService) UpdateEnterpriseRulesetClearBypassActor(ctx context.Context, enterprise string, rulesetID int64) (*Response, error) {
func (s *EnterpriseService) UpdateRepositoryRulesetClearBypassActor(ctx context.Context, enterprise string, rulesetID int64) (*Response, error) {
u := fmt.Sprintf("enterprises/%v/rulesets/%v", enterprise, rulesetID)

rsClearBypassActor := rulesetClearBypassActors{}
Expand All @@ -101,12 +101,12 @@ func (s *EnterpriseService) UpdateEnterpriseRulesetClearBypassActor(ctx context.
return resp, nil
}

// DeleteEnterpriseRuleset deletes a ruleset from the specified enterprise.
// DeleteRepositoryRuleset deletes a repository ruleset from the specified enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/rules#delete-an-enterprise-repository-ruleset
//
//meta:operation DELETE /enterprises/{enterprise}/rulesets/{ruleset_id}
func (s *EnterpriseService) DeleteEnterpriseRuleset(ctx context.Context, enterprise string, rulesetID int64) (*Response, error) {
func (s *EnterpriseService) DeleteRepositoryRuleset(ctx context.Context, enterprise string, rulesetID int64) (*Response, error) {
u := fmt.Sprintf("enterprises/%v/rulesets/%v", enterprise, rulesetID)

req, err := s.client.NewRequest("DELETE", u, nil)
Expand Down
Loading
Loading