Skip to content

Commit

Permalink
Add json fields to the RepositoryRule object
Browse files Browse the repository at this point in the history
The purpose of this commit is to allow further querying of rulesets
for a specific branch, at the organization or the repository level.
To achieve this, this commit adds the `ruleset_id` and `ruleset_source_type`
fields to the RepositoryRule object according to the returned information
from the github API.
  • Loading branch information
tomfeigin committed Mar 3, 2024
1 parent a25989b commit 14c7bd5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions github/repos_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ type RequiredWorkflowsRuleParameters struct {

// RepositoryRule represents a GitHub Rule.
type RepositoryRule struct {
Type string `json:"type"`
Parameters *json.RawMessage `json:"parameters,omitempty"`
Type string `json:"type"`
Parameters *json.RawMessage `json:"parameters,omitempty"`
SourceType string `json:"ruleset_source_type"`
RulesetSource string `json:"ruleset_source"`
RulesetID int64 `json:"ruleset_id"`
}

// UnmarshalJSON implements the json.Unmarshaler interface.
Expand All @@ -125,6 +128,9 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
return err
}

r.RulesetID = RepositoryRule.RulesetID
r.SourceType = RepositoryRule.SourceType
r.RulesetSource = RepositoryRule.RulesetSource
r.Type = RepositoryRule.Type

switch RepositoryRule.Type {
Expand Down
4 changes: 4 additions & 0 deletions github/repos_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,11 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[
{
"ruleset_id": 42069,
"type": "creation"
},
{
"ruleset_id": 42069,
"type": "update",
"parameters": {
"update_allows_fetch_and_merge": true
Expand All @@ -280,9 +282,11 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) {
}

creationRule := NewCreationRule()
creationRule.RulesetID = 42069
updateRule := NewUpdateRule(&UpdateAllowsFetchAndMergeRuleParameters{
UpdateAllowsFetchAndMerge: true,
})
updateRule.RulesetID = 42069

want := []*RepositoryRule{
creationRule,
Expand Down

0 comments on commit 14c7bd5

Please sign in to comment.