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

Implement rulesets #2795

Merged
merged 39 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
958a8a0
Add repository ruleset and related structs
liaodaniel May 31, 2023
1e2554c
Add GetAllOrganizationRepositoryRulesets
liaodaniel May 31, 2023
6a93946
Extend ruleset struct with conditions
liaodaniel May 31, 2023
5b15d81
Create all the different rules
liaodaniel May 31, 2023
dc199b5
Spilt out ruleset conditions in different types
liaodaniel May 31, 2023
90d803f
Add missing requiredStatusChecks struct
liaodaniel Jun 1, 2023
8b3f493
Add CreateOrganizationRepositoryRuleset
liaodaniel Jun 1, 2023
f2b462f
Fix unhandled rulesetRule type message
liaodaniel Jun 1, 2023
113d39f
Add comments on the rule creations
liaodaniel Jun 1, 2023
93e2a90
Add GetOrganizationRepositoryRuleset
liaodaniel Jun 1, 2023
3208f5c
Add copyright metadata
liaodaniel Jun 1, 2023
f58936c
Add UpdateOrganizationRepositoryRuleset
liaodaniel Jun 1, 2023
879e3e0
Add DeleteOrganizationRepositoryRuleset
liaodaniel Jun 1, 2023
d89d75a
Add comment on ruleset
liaodaniel Jun 1, 2023
51f34d4
Fix linting
liaodaniel Jun 1, 2023
8d47d85
Add tests for Rule_UnmarshalJSON
liaodaniel Jun 1, 2023
5439e29
Fix newline linting
liaodaniel Jun 1, 2023
3f1a6b4
Rename RuleSetRule to RepositoryRule
liaodaniel Jun 1, 2023
90c2a8d
Add GetRulesForBranch
liaodaniel Jun 1, 2023
0e828ee
Add GetAllRulesets
liaodaniel Jun 2, 2023
5589fc1
Add CreateRuleset
liaodaniel Jun 2, 2023
8c128a6
Add GetRuleset
liaodaniel Jun 2, 2023
7696f52
Add UpdateRuleset
liaodaniel Jun 2, 2023
9db0040
Fix http method for UpdateOrganizationRepositoryRuleset
liaodaniel Jun 2, 2023
fc0b2f1
Always return response when deleting rulesets
liaodaniel Jun 2, 2023
5a90752
Update comments
liaodaniel Jun 2, 2023
5492131
Small renaming and tidy up for consistency
liaodaniel Jun 2, 2023
fdbe041
Merge branch 'master' into add_org_ruleset
liaodaniel Jun 2, 2023
b814d7f
Add includesParent query to GetAllRulesets
liaodaniel Jun 2, 2023
c390b09
Further tidy up comments
liaodaniel Jun 2, 2023
6ab01f8
Fix the test for RepositoryRule UnmarshalJSON
liaodaniel Jun 2, 2023
a7d82e3
Make fields in RulesetRepositoryConditionParameters optional
liaodaniel Jun 2, 2023
fe12731
Fix line break and spelling
liaodaniel Jun 2, 2023
b584269
Rename some vars
liaodaniel Jun 4, 2023
ac74284
Simplify Ruleset struct to use list of pointers
liaodaniel Jun 4, 2023
b4eb612
Make BypassActor fields optional
liaodaniel Jun 5, 2023
ad0beca
Add testing for RepositoryRule UnmarshalJSON
liaodaniel Jun 5, 2023
5618f6f
Switch parameters to *json.RawMessage type
liaodaniel Jun 7, 2023
221c3ee
Merge branch 'master' into add_ruleset
liaodaniel Jun 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
128 changes: 128 additions & 0 deletions github/github-accessors.go

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

145 changes: 145 additions & 0 deletions github/github-accessors_test.go

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

105 changes: 105 additions & 0 deletions github/orgs_rules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright 2023 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
"context"
"fmt"
)

// GetAllOrganizationRulesets gets all the rulesets for the specified organization.
//
// GitHub API docs: https://docs.github.com/en/rest/orgs/rules#get-all-organization-repository-rulesets
func (s *OrganizationsService) GetAllOrganizationRulesets(ctx context.Context, org string) ([]*Ruleset, *Response, error) {
u := fmt.Sprintf("orgs/%v/rulesets", org)

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

var rulesets []*Ruleset
resp, err := s.client.Do(ctx, req, &rulesets)
if err != nil {
return nil, resp, err
}

return rulesets, resp, nil
}

// CreateOrganizationRuleset creates a ruleset for the specified organization.
//
// GitHub API docs: https://docs.github.com/en/rest/orgs/rules#create-an-organization-repository-ruleset
func (s *OrganizationsService) CreateOrganizationRuleset(ctx context.Context, org string, rs *Ruleset) (*Ruleset, *Response, error) {
u := fmt.Sprintf("orgs/%v/rulesets", org)

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

var ruleset *Ruleset
resp, err := s.client.Do(ctx, req, &ruleset)
if err != nil {
return nil, resp, err
}

return ruleset, resp, nil
}

// GetOrganizationRuleset gets a ruleset from the specified organization.
//
// GitHub API docs: https://docs.github.com/en/rest/orgs/rules#get-an-organization-repository-ruleset
func (s *OrganizationsService) GetOrganizationRuleset(ctx context.Context, org string, rulesetID int64) (*Ruleset, *Response, error) {
u := fmt.Sprintf("orgs/%v/rulesets/%v", org, rulesetID)

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

var rulesets *Ruleset
liaodaniel marked this conversation as resolved.
Show resolved Hide resolved
resp, err := s.client.Do(ctx, req, &rulesets)
if err != nil {
return nil, resp, err
}

return rulesets, resp, nil
}

// UpdateOrganizationRuleset updates a ruleset from the specified organization.
//
// GitHub API docs: https://docs.github.com/en/rest/orgs/rules#update-an-organization-repository-ruleset
func (s *OrganizationsService) UpdateOrganizationRuleset(ctx context.Context, org string, rulesetID int64, rs *Ruleset) (*Ruleset, *Response, error) {
u := fmt.Sprintf("orgs/%v/rulesets/%v", org, rulesetID)

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

var rulesets *Ruleset
liaodaniel marked this conversation as resolved.
Show resolved Hide resolved
resp, err := s.client.Do(ctx, req, &rulesets)
if err != nil {
return nil, resp, err
}

return rulesets, resp, nil
}

// DeleteOrganizationRuleset deletes a ruleset from the specified organization.
//
// GitHub API docs: https://docs.github.com/en/rest/orgs/rules#delete-an-organization-repository-ruleset
func (s *OrganizationsService) DeleteOrganizationRuleset(ctx context.Context, org string, rulesetID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/rulesets/%v", org, rulesetID)

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

return s.client.Do(ctx, req, nil)
}