Repository: google/go-github
Pull request #2384 (2022-06-15 18:13:08)

Add missing common event fields.
See
https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#webhook-payload-object-common-properties
for the list of common fields.

I may have missed some - but gives better coverage for fields we were
missing before.

Signed-off-by: Billy Lynch <billy@chainguard.dev>

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/2384?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2384](https://codecov.io/gh/google/go-github/pull/2384?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (d045eda) into [master](https://codecov.io/gh/google/go-github/commit/3072c0afc8f37b55692ccc00ce978d1bc102a652?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (3072c0a) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #2384   +/-   ##
=======================================
  Coverage   98.06%   98.06%           
=======================================
  Files         119      119           
  Lines       10545    10545           
=======================================
  Hits        10341    10341           
  Misses        140      140           
  Partials       64       64           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/2384?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/event\_types.go](https://codecov.io/gh/google/go-github/pull/2384/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL2V2ZW50X3R5cGVzLmdv) | `100.00% <ø> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/2384?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/2384?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Last update [3072c0a...d045eda](https://codecov.io/gh/google/go-github/pull/2384?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?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 c80a835f..b5503618 100644
--- a/github/event_types.go
+++ b/github/event_types.go
@@ -106,10 +106,11 @@ type CreateEvent struct {
 	RefType      *string `json:"ref_type,omitempty"`
 	MasterBranch *string `json:"master_branch,omitempty"`
 	Description  *string `json:"description,omitempty"`
+	PusherType   *string `json:"pusher_type,omitempty"`
 
 	// The following fields are only populated by Webhook events.
-	PusherType   *string       `json:"pusher_type,omitempty"`
 	Repo         *Repository   `json:"repository,omitempty"`
+	Org          *Organization `json:"organization,omitempty"`
 	Sender       *User         `json:"sender,omitempty"`
 	Installation *Installation `json:"installation,omitempty"`
 }
@@ -493,13 +494,14 @@ type IssuesEvent struct {
 type LabelEvent struct {
 	// Action is the action that was performed. Possible values are:
 	// "created", "edited", "deleted"
-	Action *string `json:"action,omitempty"`
-	Label  *Label  `json:"label,omitempty"`
+	Action  *string     `json:"action,omitempty"`
+	Label   *Label      `json:"label,omitempty"`
+	Changes *EditChange `json:"changes,omitempty"`
 
 	// The following fields are only populated by Webhook events.
-	Changes      *EditChange   `json:"changes,omitempty"`
 	Repo         *Repository   `json:"repository,omitempty"`
 	Org          *Organization `json:"organization,omitempty"`
+	Sender       *User         `json:"sender,omitempty"`
 	Installation *Installation `json:"installation,omitempty"`
 }
 
@@ -574,6 +576,9 @@ type MetaEvent struct {
 	Hook *Hook `json:"hook,omitempty"`
 
 	// The following fields are only populated by Webhook events.
+	Repo         *Repository   `json:"repository,omitempty"`
+	Org          *Organization `json:"organization,omitempty"`
+	Sender       *User         `json:"sender,omitempty"`
 	Installation *Installation `json:"installation,omitempty"`
 }
 
@@ -682,7 +687,12 @@ type PingEvent struct {
 	// The ID of the webhook that triggered the ping.
 	HookID *int64 `json:"hook_id,omitempty"`
 	// The webhook configuration.
-	Hook         *Hook         `json:"hook,omitempty"`
+	Hook *Hook `json:"hook,omitempty"`
+
+	// The following fields are only populated by Webhook events.
+	Repo         *Repository   `json:"repository,omitempty"`
+	Org          *Organization `json:"organization,omitempty"`
+	Sender       *User         `json:"sender,omitempty"`
 	Installation *Installation `json:"installation,omitempty"`
 }
 
diff --git a/github/github-accessors.go b/github/github-accessors.go
index c1cb0d1f..01fc3ceb 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -3438,6 +3438,14 @@ func (c *CreateEvent) GetMasterBranch() string {
 	return *c.MasterBranch
 }
 
+// GetOrg returns the Org field.
+func (c *CreateEvent) GetOrg() *Organization {
+	if c == nil {
+		return nil
+	}
+	return c.Org
+}
+
 // GetPusherType returns the PusherType field if it's non-nil, zero value otherwise.
 func (c *CreateEvent) GetPusherType() string {
 	if c == nil || c.PusherType == nil {
@@ -7902,6 +7910,14 @@ func (l *LabelEvent) GetRepo() *Repository {
 	return l.Repo
 }
 
+// GetSender returns the Sender field.
+func (l *LabelEvent) GetSender() *User {
+	if l == nil {
+		return nil
+	}
+	return l.Sender
+}
+
 // GetColor returns the Color field if it's non-nil, zero value otherwise.
 func (l *LabelResult) GetColor() string {
 	if l == nil || l.Color == nil {
@@ -8742,6 +8758,30 @@ func (m *MetaEvent) GetInstallation() *Installation {
 	return m.Installation
 }
 
+// GetOrg returns the Org field.
+func (m *MetaEvent) GetOrg() *Organization {
+	if m == nil {
+		return nil
+	}
+	return m.Org
+}
+
+// GetRepo returns the Repo field.
+func (m *MetaEvent) GetRepo() *Repository {
+	if m == nil {
+		return nil
+	}
+	return m.Repo
+}
+
+// GetSender returns the Sender field.
+func (m *MetaEvent) GetSender() *User {
+	if m == nil {
+		return nil
+	}
+	return m.Sender
+}
+
 // GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise.
 func (m *Metric) GetHTMLURL() string {
 	if m == nil || m.HTMLURL == nil {
@@ -10766,6 +10806,30 @@ func (p *PingEvent) GetInstallation() *Installation {
 	return p.Installation
 }
 
+// GetOrg returns the Org field.
+func (p *PingEvent) GetOrg() *Organization {
+	if p == nil {
+		return nil
+	}
+	return p.Org
+}
+
+// GetRepo returns the Repo field.
+func (p *PingEvent) GetRepo() *Repository {
+	if p == nil {
+		return nil
+	}
+	return p.Repo
+}
+
+// GetSender returns the Sender field.
+func (p *PingEvent) GetSender() *User {
+	if p == nil {
+		return nil
+	}
+	return p.Sender
+}
+
 // GetZen returns the Zen field if it's non-nil, zero value otherwise.
 func (p *PingEvent) GetZen() string {
 	if p == nil || p.Zen == nil {


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 80134620..dc827e65 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -4022,6 +4022,13 @@ func TestCreateEvent_GetMasterBranch(tt *testing.T) {
 	c.GetMasterBranch()
 }
 
+func TestCreateEvent_GetOrg(tt *testing.T) {
+	c := &CreateEvent{}
+	c.GetOrg()
+	c = nil
+	c.GetOrg()
+}
+
 func TestCreateEvent_GetPusherType(tt *testing.T) {
 	var zeroValue string
 	c := &CreateEvent{PusherType: &zeroValue}
@@ -9245,6 +9252,13 @@ func TestLabelEvent_GetRepo(tt *testing.T) {
 	l.GetRepo()
 }
 
+func TestLabelEvent_GetSender(tt *testing.T) {
+	l := &LabelEvent{}
+	l.GetSender()
+	l = nil
+	l.GetSender()
+}
+
 func TestLabelResult_GetColor(tt *testing.T) {
 	var zeroValue string
 	l := &LabelResult{Color: &zeroValue}
@@ -10229,6 +10243,27 @@ func TestMetaEvent_GetInstallation(tt *testing.T) {
 	m.GetInstallation()
 }
 
+func TestMetaEvent_GetOrg(tt *testing.T) {
+	m := &MetaEvent{}
+	m.GetOrg()
+	m = nil
+	m.GetOrg()
+}
+
+func TestMetaEvent_GetRepo(tt *testing.T) {
+	m := &MetaEvent{}
+	m.GetRepo()
+	m = nil
+	m.GetRepo()
+}
+
+func TestMetaEvent_GetSender(tt *testing.T) {
+	m := &MetaEvent{}
+	m.GetSender()
+	m = nil
+	m.GetSender()
+}
+
 func TestMetric_GetHTMLURL(tt *testing.T) {
 	var zeroValue string
 	m := &Metric{HTMLURL: &zeroValue}
@@ -12621,6 +12656,27 @@ func TestPingEvent_GetInstallation(tt *testing.T) {
 	p.GetInstallation()
 }
 
+func TestPingEvent_GetOrg(tt *testing.T) {
+	p := &PingEvent{}
+	p.GetOrg()
+	p = nil
+	p.GetOrg()
+}
+
+func TestPingEvent_GetRepo(tt *testing.T) {
+	p := &PingEvent{}
+	p.GetRepo()
+	p = nil
+	p.GetRepo()
+}
+
+func TestPingEvent_GetSender(tt *testing.T) {
+	p := &PingEvent{}
+	p.GetSender()
+	p = nil
+	p.GetSender()
+}
+
 func TestPingEvent_GetZen(tt *testing.T) {
 	var zeroValue string
 	p := &PingEvent{Zen: &zeroValue}