Skip to content

Commit

Permalink
Add Missing Changes Field to Member Event Type. (#3153)
Browse files Browse the repository at this point in the history
Fixes: #3154.
  • Loading branch information
tayosec authored Apr 25, 2024
1 parent 8d4be0b commit d067824
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 4 deletions.
28 changes: 24 additions & 4 deletions github/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
20 changes: 20 additions & 0 deletions github/event_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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",
Expand Down
56 changes: 56 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d067824

Please sign in to comment.