Repository: google/go-github
Pull request #3508 (2025-03-10 18:16:16)

Add reason parameter to MergeGroupEvent
Fixes: #3507.

I am submitting this as a Block (Square) employee. Block has signed the Google Corporate CLA
q

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/3508?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 91.21%. Comparing base [(`d0976cc`)](https://app.codecov.io/gh/google/go-github/commit/d0976cc1b1715743296c1dba5c8f8ec422a5e8c6?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) to head [(`8d58b56`)](https://app.codecov.io/gh/google/go-github/commit/8d58b56b7871c3b9640bb67d0d10fc7b679a97f9?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> Report is 4 commits behind head on master.

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


```diff
@@            Coverage Diff             @@
##           master    #3508      +/-   ##
==========================================
+ Coverage   91.17%   91.21%   +0.03%     
==========================================
  Files         181      182       +1     
  Lines       15859    15930      +71     
==========================================
+ Hits        14460    14531      +71     
  Misses       1225     1225              
  Partials      174      174              
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/google/go-github/pull/3508?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).

<details><summary>🚀 New features to boost your workflow: </summary>

- ❄ [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>

Patch:
diff --git a/github/event_types.go b/github/event_types.go
index 0df3b30c..6a6caf19 100644
--- a/github/event_types.go
+++ b/github/event_types.go
@@ -858,8 +858,10 @@ type MergeGroup struct {
 //
 // GitHub API docs: https://docs.github.com/developers/webhooks-and-events/webhook-events-and-payloads#merge_group
 type MergeGroupEvent struct {
-	// The action that was performed. Currently, can only be checks_requested.
+	// The action that was performed. Possible values are: "checks_requested", "destroyed".
 	Action *string `json:"action,omitempty"`
+	// Reason is populated when the action is "destroyed". Possible values: "merged", "invalidated", "dequeued".
+	Reason *string `json:"reason,omitempty"`
 	// The merge group.
 	MergeGroup *MergeGroup `json:"merge_group,omitempty"`
 
diff --git a/github/github-accessors.go b/github/github-accessors.go
index e2a16527..711d48a6 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -14334,6 +14334,14 @@ func (m *MergeGroupEvent) GetOrg() *Organization {
 	return m.Org
 }
 
+// GetReason returns the Reason field if it's non-nil, zero value otherwise.
+func (m *MergeGroupEvent) GetReason() string {
+	if m == nil || m.Reason == nil {
+		return ""
+	}
+	return *m.Reason
+}
+
 // GetRepo returns the Repo field.
 func (m *MergeGroupEvent) GetRepo() *Repository {
 	if m == nil {


Test patch:
diff --git a/github/event_types_test.go b/github/event_types_test.go
index 947f9702..35d57dbe 100644
--- a/github/event_types_test.go
+++ b/github/event_types_test.go
@@ -10746,6 +10746,7 @@ func TestMergeGroupEvent_Marshal(t *testing.T) {
 
 	u := &MergeGroupEvent{
 		Action: Ptr("a"),
+		Reason: Ptr("r"),
 		MergeGroup: &MergeGroup{
 			HeadSHA:    Ptr("hs"),
 			HeadRef:    Ptr("hr"),
@@ -10886,6 +10887,7 @@ func TestMergeGroupEvent_Marshal(t *testing.T) {
 
 	want := `{
 		"action": "a",
+		"reason": "r",
 		"merge_group": {
 			"head_sha": "hs",
 			"head_ref": "hr",
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 66132f57..5a11f891 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -18571,6 +18571,17 @@ func TestMergeGroupEvent_GetOrg(tt *testing.T) {
 	m.GetOrg()
 }
 
+func TestMergeGroupEvent_GetReason(tt *testing.T) {
+	tt.Parallel()
+	var zeroValue string
+	m := &MergeGroupEvent{Reason: &zeroValue}
+	m.GetReason()
+	m = &MergeGroupEvent{}
+	m.GetReason()
+	m = nil
+	m.GetReason()
+}
+
 func TestMergeGroupEvent_GetRepo(tt *testing.T) {
 	tt.Parallel()
 	m := &MergeGroupEvent{}