Repository: google/go-github
Pull request #3131 (2024-04-18 17:38:25)

Add support for merge queue ruleset JSON unmarshaling 
Fixes: #3098.

Added support for respository ruleset merge_queue in JSON unmarshalling code with accompanying tests 

google-cla[bot]: Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this [failed invocation](https://github.com/google/go-github/pull/3131/checks?check_run_id=23990367319) of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/3131?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 92.88%. Comparing base [(`2b8c7fa`)](https://app.codecov.io/gh/google/go-github/commit/2b8c7fa86fcd1cb4a89a44c8e7b5a49fe4be8a45?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) to head [(`aabde61`)](https://app.codecov.io/gh/google/go-github/pull/3131?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> Report is 41 commits behind head on master.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #3131      +/-   ##
==========================================
- Coverage   97.72%   92.88%   -4.84%     
==========================================
  Files         153      170      +17     
  Lines       13390    11426    -1964     
==========================================
- Hits        13085    10613    -2472     
- Misses        215      723     +508     
  Partials       90       90              
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/google/go-github/pull/3131?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).

Matthew-Reidy: Sure thing. I'll get I'll fix those items shortly
liaodaniel: Just a minor comment to update but looks good otherwise
Matthew-Reidy: changes to that comment have been made

Patch:
diff --git a/AUTHORS b/AUTHORS
index 74a21dc6..0197b94a 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -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>
@@ -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>
\ No newline at end of file
diff --git a/github/repos_rules.go b/github/repos_rules.go
index 34711dda..6f046a35 100644
--- a/github/repos_rules.go
+++ b/github/repos_rules.go
@@ -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 {
@@ -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{


Test patch:
diff --git a/github/orgs_rules_test.go b/github/orgs_rules_test.go
index 50ba4e20..0ed54ca8 100644
--- a/github/orgs_rules_test.go
+++ b/github/orgs_rules_test.go
@@ -123,6 +123,9 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoNames(t *testing.T)
 			  {
 				"type": "deletion"
 			  },
+			  {
+				"type": "merge_queue"
+			  },
 			  {
 				"type": "required_linear_history"
 			  },
@@ -238,6 +241,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoNames(t *testing.T)
 				UpdateAllowsFetchAndMerge: true,
 			}),
 			NewDeletionRule(),
+			NewMergeQueueRule(),
 			NewRequiredLinearHistoryRule(),
 			NewRequiredDeploymentsRule(&RequiredDeploymentEnvironmentsRuleParameters{
 				RequiredDeploymentEnvironments: []string{"test"},
@@ -324,6 +328,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoNames(t *testing.T)
 				UpdateAllowsFetchAndMerge: true,
 			}),
 			NewDeletionRule(),
+			NewMergeQueueRule(),
 			NewRequiredLinearHistoryRule(),
 			NewRequiredDeploymentsRule(&RequiredDeploymentEnvironmentsRuleParameters{
 				RequiredDeploymentEnvironments: []string{"test"},
@@ -437,6 +442,9 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) {
 			  {
 				"type": "deletion"
 			  },
+			  {
+				"type": "merge_queue"
+			  },
 			  {
 				"type": "required_linear_history"
 			  },
@@ -550,6 +558,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) {
 				UpdateAllowsFetchAndMerge: true,
 			}),
 			NewDeletionRule(),
+			NewMergeQueueRule(),
 			NewRequiredLinearHistoryRule(),
 			NewRequiredDeploymentsRule(&RequiredDeploymentEnvironmentsRuleParameters{
 				RequiredDeploymentEnvironments: []string{"test"},
@@ -634,6 +643,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) {
 				UpdateAllowsFetchAndMerge: true,
 			}),
 			NewDeletionRule(),
+			NewMergeQueueRule(),
 			NewRequiredLinearHistoryRule(),
 			NewRequiredDeploymentsRule(&RequiredDeploymentEnvironmentsRuleParameters{
 				RequiredDeploymentEnvironments: []string{"test"},
diff --git a/github/repos_rules_test.go b/github/repos_rules_test.go
index cbc3e5ce..23ffd3ed 100644
--- a/github/repos_rules_test.go
+++ b/github/repos_rules_test.go
@@ -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{