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

Add support for merge queue ruleset JSON unmarshaling #3131

Merged
merged 5 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,4 @@ zhouhaibing089 <[email protected]>
六开箱 <[email protected]>
缘生 <[email protected]>
蒋航 <[email protected]>
Matthew Reidy <[email protected]>
gmlewis marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 10 additions & 0 deletions github/orgs_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoNames(t *testing.T)
{
"type": "deletion"
},
{
"type": "merge_queue"
},
{
"type": "required_linear_history"
},
Expand Down Expand Up @@ -238,6 +241,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoNames(t *testing.T)
UpdateAllowsFetchAndMerge: true,
}),
NewDeletionRule(),
NewMergeQueueRule(),
NewRequiredLinearHistoryRule(),
NewRequiredDeploymentsRule(&RequiredDeploymentEnvironmentsRuleParameters{
RequiredDeploymentEnvironments: []string{"test"},
Expand Down Expand Up @@ -324,6 +328,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoNames(t *testing.T)
UpdateAllowsFetchAndMerge: true,
}),
NewDeletionRule(),
NewMergeQueueRule(),
NewRequiredLinearHistoryRule(),
NewRequiredDeploymentsRule(&RequiredDeploymentEnvironmentsRuleParameters{
RequiredDeploymentEnvironments: []string{"test"},
Expand Down Expand Up @@ -437,6 +442,9 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) {
{
"type": "deletion"
},
{
"type": "merge_queue"
},
{
"type": "required_linear_history"
},
Expand Down Expand Up @@ -550,6 +558,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) {
UpdateAllowsFetchAndMerge: true,
}),
NewDeletionRule(),
NewMergeQueueRule(),
NewRequiredLinearHistoryRule(),
NewRequiredDeploymentsRule(&RequiredDeploymentEnvironmentsRuleParameters{
RequiredDeploymentEnvironments: []string{"test"},
Expand Down Expand Up @@ -634,6 +643,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) {
UpdateAllowsFetchAndMerge: true,
}),
NewDeletionRule(),
NewMergeQueueRule(),
NewRequiredLinearHistoryRule(),
NewRequiredDeploymentsRule(&RequiredDeploymentEnvironmentsRuleParameters{
RequiredDeploymentEnvironments: []string{"test"},
Expand Down
10 changes: 9 additions & 1 deletion github/repos_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
r.Type = RepositoryRule.Type

switch RepositoryRule.Type {
case "creation", "deletion", "required_linear_history", "required_signatures", "non_fast_forward":
case "creation", "deletion", "required_linear_history", "required_signatures", "non_fast_forward", "merge_queue":
gmlewis marked this conversation as resolved.
Show resolved Hide resolved
r.Parameters = nil
case "update":
if RepositoryRule.Parameters == nil {
Expand Down Expand Up @@ -201,6 +201,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
rawParams := json.RawMessage(bytes)

r.Parameters = &rawParams

gmlewis marked this conversation as resolved.
Show resolved Hide resolved
default:
r.Type = ""
r.Parameters = nil
Expand All @@ -210,6 +211,13 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
return nil
}

// NewMergeQueueRule creates a rule to only allow users with bypass permission to create matching refs.
Matthew-Reidy marked this conversation as resolved.
Show resolved Hide resolved
func NewMergeQueueRule() (rule *RepositoryRule) {
return &RepositoryRule{
Type: "merge_queue",
}
}

// NewCreationRule creates a rule to only allow users with bypass permission to create matching refs.
func NewCreationRule() (rule *RepositoryRule) {
return &RepositoryRule{
Expand Down
7 changes: 7 additions & 0 deletions github/repos_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ func TestRepositoryRule_UnmarshalJSON(t *testing.T) {
Parameters: nil,
},
},
"Valid merge_queue": {
data: `{"type":"merge_queue"}`,
want: &RepositoryRule{
Type: "merge_queue",
Parameters: nil,
},
},
"Valid non_fast_forward": {
data: `{"type":"non_fast_forward"}`,
want: &RepositoryRule{
Expand Down
Loading