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 all 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
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ Matt Gaunt <matt@gauntface.co.uk>
Matt Landis <landis.matt@gmail.com>
Matt Moore <mattmoor@vmware.com>
Matt Simons <mattsimons@ntlworld.com>
Matthew Reidy <matthewreidy5@gmail.com>
Maxime Bury <maxime.bury@gmail.com>
Michael Meng <mmeng@lyft.com>
Michael Spiegel <michael.m.spiegel@gmail.com>
Expand Down Expand Up @@ -484,4 +485,4 @@ Zach Latta <zach@zachlatta.com>
zhouhaibing089 <zhouhaibing089@gmail.com>
六开箱 <lkxed@outlook.com>
缘生 <i@ysicing.me>
蒋航 <hang.jiang@daocloud.io>
蒋航 <hang.jiang@daocloud.io>
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
9 changes: 8 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", "merge_queue", "non_fast_forward", "required_linear_history", "required_signatures":
r.Parameters = nil
case "update":
if RepositoryRule.Parameters == nil {
Expand Down Expand Up @@ -210,6 +210,13 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
return nil
}

// NewMergeQueueRule creates a rule to only allow merges via a merge queue.
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