Repository: google/go-github
Pull request #3153 (2024-04-25 20:38:10)

Add Missing Changes Field to Member Event Type.
Fixes: #3154.

The `member` webhook event as described by github documentation contains a `changes` object. https://docs.github.com/en/webhooks/webhook-events-and-payloads?actionType=edited#member

However, the struct that defines the `Member` webhook event type is missing the `changes` object . This PR adds the missing `changes` object to the `MemberEvent` type.

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/3153/checks?check_run_id=24271641730) 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/3153?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 [(`c190d6b`)](https://app.codecov.io/gh/google/go-github/pull/3153?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> Report is 43 commits behind head on master.


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


```diff
@@            Coverage Diff             @@
##           master    #3153      +/-   ##
==========================================
- 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/3153?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).


Patch:
diff --git a/github/event_types.go b/github/event_types.go
index b820dddf..703af1f2 100644
--- a/github/event_types.go
+++ b/github/event_types.go
@@ -689,14 +689,34 @@ type MarketplacePurchaseEvent struct {
 	Org *Organization `json:"organization,omitempty"`
 }
 
-// MemberEvent is triggered when a user is added as a collaborator to a repository.
+// MemberChangesPermission represents changes to a repository collaborator's permissions.
+type MemberChangesPermission struct {
+	From *string `json:"from,omitempty"`
+	To   *string `json:"to,omitempty"`
+}
+
+// MemberChangesRoleName represents changes to a repository collaborator's role.
+type MemberChangesRoleName struct {
+	From *string `json:"from,omitempty"`
+	To   *string `json:"to,omitempty"`
+}
+
+// MemberChanges represents changes to a repository collaborator's role or permission.
+type MemberChanges struct {
+	Permission *MemberChangesPermission `json:"permission,omitempty"`
+	RoleName   *MemberChangesRoleName   `json:"role_name,omitempty"`
+}
+
+// MemberEvent is triggered when a user's membership as a collaborator to a repository changes.
 // The Webhook event name is "member".
 //
 // GitHub API docs: https://docs.github.com/developers/webhooks-and-events/webhook-events-and-payloads#member
 type MemberEvent struct {
-	// Action is the action that was performed. Possible value is: "added".
-	Action *string `json:"action,omitempty"`
-	Member *User   `json:"member,omitempty"`
+	// Action is the action that was performed. Possible values are:
+	//"added", "edited", "removed".
+	Action  *string        `json:"action,omitempty"`
+	Member  *User          `json:"member,omitempty"`
+	Changes *MemberChanges `json:"changes,omitempty"`
 
 	// The following fields are only populated by Webhook events.
 	Repo         *Repository   `json:"repository,omitempty"`
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 57a7165f..13bf7d66 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -11206,6 +11206,54 @@ func (m *Match) GetText() string {
 	return *m.Text
 }
 
+// GetPermission returns the Permission field.
+func (m *MemberChanges) GetPermission() *MemberChangesPermission {
+	if m == nil {
+		return nil
+	}
+	return m.Permission
+}
+
+// GetRoleName returns the RoleName field.
+func (m *MemberChanges) GetRoleName() *MemberChangesRoleName {
+	if m == nil {
+		return nil
+	}
+	return m.RoleName
+}
+
+// GetFrom returns the From field if it's non-nil, zero value otherwise.
+func (m *MemberChangesPermission) GetFrom() string {
+	if m == nil || m.From == nil {
+		return ""
+	}
+	return *m.From
+}
+
+// GetTo returns the To field if it's non-nil, zero value otherwise.
+func (m *MemberChangesPermission) GetTo() string {
+	if m == nil || m.To == nil {
+		return ""
+	}
+	return *m.To
+}
+
+// GetFrom returns the From field if it's non-nil, zero value otherwise.
+func (m *MemberChangesRoleName) GetFrom() string {
+	if m == nil || m.From == nil {
+		return ""
+	}
+	return *m.From
+}
+
+// GetTo returns the To field if it's non-nil, zero value otherwise.
+func (m *MemberChangesRoleName) GetTo() string {
+	if m == nil || m.To == nil {
+		return ""
+	}
+	return *m.To
+}
+
 // GetAction returns the Action field if it's non-nil, zero value otherwise.
 func (m *MemberEvent) GetAction() string {
 	if m == nil || m.Action == nil {
@@ -11214,6 +11262,14 @@ func (m *MemberEvent) GetAction() string {
 	return *m.Action
 }
 
+// GetChanges returns the Changes field.
+func (m *MemberEvent) GetChanges() *MemberChanges {
+	if m == nil {
+		return nil
+	}
+	return m.Changes
+}
+
 // GetInstallation returns the Installation field.
 func (m *MemberEvent) GetInstallation() *Installation {
 	if m == nil {


Test patch:
diff --git a/github/event_types_test.go b/github/event_types_test.go
index b00e94a3..79532d49 100644
--- a/github/event_types_test.go
+++ b/github/event_types_test.go
@@ -9106,6 +9106,16 @@ func TestMemberEvent_Marshal(t *testing.T) {
 			EventsURL: String("e"),
 			AvatarURL: String("a"),
 		},
+		Changes: &MemberChanges{
+			Permission: &MemberChangesPermission{
+				From: String("f"),
+				To:   String("t"),
+			},
+			RoleName: &MemberChangesRoleName{
+				From: String("f"),
+				To:   String("t"),
+			},
+		},
 		Repo: &Repository{
 			ID:   Int64(1),
 			URL:  String("s"),
@@ -9226,6 +9236,16 @@ func TestMemberEvent_Marshal(t *testing.T) {
 			"events_url": "e",
 			"repos_url": "r"
 		},
+		"changes": {
+			"permission": {
+				"from": "f",
+				"to": "t"
+			},
+			"role_name": {
+				"from": "f",
+				"to": "t"
+			}
+		},
 		"repository": {
 			"id": 1,
 			"name": "n",
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index bbf9fb84..313e92c0 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -13111,6 +13111,60 @@ func TestMatch_GetText(tt *testing.T) {
 	m.GetText()
 }
 
+func TestMemberChanges_GetPermission(tt *testing.T) {
+	m := &MemberChanges{}
+	m.GetPermission()
+	m = nil
+	m.GetPermission()
+}
+
+func TestMemberChanges_GetRoleName(tt *testing.T) {
+	m := &MemberChanges{}
+	m.GetRoleName()
+	m = nil
+	m.GetRoleName()
+}
+
+func TestMemberChangesPermission_GetFrom(tt *testing.T) {
+	var zeroValue string
+	m := &MemberChangesPermission{From: &zeroValue}
+	m.GetFrom()
+	m = &MemberChangesPermission{}
+	m.GetFrom()
+	m = nil
+	m.GetFrom()
+}
+
+func TestMemberChangesPermission_GetTo(tt *testing.T) {
+	var zeroValue string
+	m := &MemberChangesPermission{To: &zeroValue}
+	m.GetTo()
+	m = &MemberChangesPermission{}
+	m.GetTo()
+	m = nil
+	m.GetTo()
+}
+
+func TestMemberChangesRoleName_GetFrom(tt *testing.T) {
+	var zeroValue string
+	m := &MemberChangesRoleName{From: &zeroValue}
+	m.GetFrom()
+	m = &MemberChangesRoleName{}
+	m.GetFrom()
+	m = nil
+	m.GetFrom()
+}
+
+func TestMemberChangesRoleName_GetTo(tt *testing.T) {
+	var zeroValue string
+	m := &MemberChangesRoleName{To: &zeroValue}
+	m.GetTo()
+	m = &MemberChangesRoleName{}
+	m.GetTo()
+	m = nil
+	m.GetTo()
+}
+
 func TestMemberEvent_GetAction(tt *testing.T) {
 	var zeroValue string
 	m := &MemberEvent{Action: &zeroValue}
@@ -13121,6 +13175,13 @@ func TestMemberEvent_GetAction(tt *testing.T) {
 	m.GetAction()
 }
 
+func TestMemberEvent_GetChanges(tt *testing.T) {
+	m := &MemberEvent{}
+	m.GetChanges()
+	m = nil
+	m.GetChanges()
+}
+
 func TestMemberEvent_GetInstallation(tt *testing.T) {
 	m := &MemberEvent{}
 	m.GetInstallation()