Skip to content

Commit

Permalink
Add support for merge queue ruleset JSON unmarshaling (#3131)
Browse files Browse the repository at this point in the history
Fixes: #3098.
  • Loading branch information
Matthew-Reidy committed Apr 19, 2024
1 parent a6806bc commit b02f283
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
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
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
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
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

0 comments on commit b02f283

Please sign in to comment.