Skip to content

Commit 9bb6bf4

Browse files
authored
Allow querying rule set information by ID with information returned from GetRulesFromBranch (#3089)
1 parent a25989b commit 9bb6bf4

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

github/repos_rules.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ type RequiredWorkflowsRuleParameters struct {
112112

113113
// RepositoryRule represents a GitHub Rule.
114114
type RepositoryRule struct {
115-
Type string `json:"type"`
116-
Parameters *json.RawMessage `json:"parameters,omitempty"`
115+
Type string `json:"type"`
116+
Parameters *json.RawMessage `json:"parameters,omitempty"`
117+
RulesetSourceType string `json:"ruleset_source_type"`
118+
RulesetSource string `json:"ruleset_source"`
119+
RulesetID int64 `json:"ruleset_id"`
117120
}
118121

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

131+
r.RulesetID = RepositoryRule.RulesetID
132+
r.RulesetSourceType = RepositoryRule.RulesetSourceType
133+
r.RulesetSource = RepositoryRule.RulesetSource
128134
r.Type = RepositoryRule.Type
129135

130136
switch RepositoryRule.Type {

github/repos_rules_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ func TestRepositoryRule_UnmarshalJSON(t *testing.T) {
2828
},
2929
wantErr: true,
3030
},
31+
"With Metadata": {
32+
data: `{
33+
"type": "creation",
34+
"ruleset_source_type": "Repository",
35+
"ruleset_source": "google",
36+
"ruleset_id": 1984
37+
}`,
38+
want: &RepositoryRule{
39+
RulesetSource: "google",
40+
RulesetSourceType: "Repository",
41+
RulesetID: 1984,
42+
Type: "creation",
43+
},
44+
},
3145
"Valid creation": {
3246
data: `{"type":"creation"}`,
3347
want: NewCreationRule(),
@@ -262,9 +276,15 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) {
262276
testMethod(t, r, "GET")
263277
fmt.Fprint(w, `[
264278
{
279+
"ruleset_id": 42069,
280+
"ruleset_source_type": "Repository",
281+
"ruleset_source": "google",
265282
"type": "creation"
266283
},
267284
{
285+
"ruleset_id": 42069,
286+
"ruleset_source_type": "Organization",
287+
"ruleset_source": "google",
268288
"type": "update",
269289
"parameters": {
270290
"update_allows_fetch_and_merge": true
@@ -280,9 +300,15 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) {
280300
}
281301

282302
creationRule := NewCreationRule()
303+
creationRule.RulesetID = 42069
304+
creationRule.RulesetSource = "google"
305+
creationRule.RulesetSourceType = "Repository"
283306
updateRule := NewUpdateRule(&UpdateAllowsFetchAndMergeRuleParameters{
284307
UpdateAllowsFetchAndMerge: true,
285308
})
309+
updateRule.RulesetID = 42069
310+
updateRule.RulesetSource = "google"
311+
updateRule.RulesetSourceType = "Organization"
286312

287313
want := []*RepositoryRule{
288314
creationRule,

0 commit comments

Comments
 (0)