diff --git a/github/event_types.go b/github/event_types.go index df8d9e033e..41d71f8ddf 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -1821,3 +1821,27 @@ type CodeScanningAlertEvent struct { Installation *Installation `json:"installation,omitempty"` } + +// SponsorshipEvent represents a sponsorship event in GitHub. +// +// GitHub API docs: https://docs.github.com/en/rest/overview/github-event-types?apiVersion=2022-11-28#sponsorshipevent +type SponsorshipEvent struct { + Action *string `json:"action,omitempty"` + EffectiveDate *string `json:"effective_date,omitempty"` + Changes *SponsorshipChanges `json:"changes,omitempty"` + Repository *Repository `json:"repository,omitempty"` + Organization *Organization `json:"organization,omitempty"` + Sender *User `json:"sender,omitempty"` + Installation *Installation `json:"installation,omitempty"` +} + +// SponsorshipChanges represents changes made to the sponsorship. +type SponsorshipChanges struct { + Tier *SponsorshipTier `json:"tier,omitempty"` + PrivacyLevel *string `json:"privacy_level,omitempty"` +} + +// SponsorshipTier represents the tier information of a sponsorship. +type SponsorshipTier struct { + From *string `json:"from,omitempty"` +} diff --git a/github/event_types_test.go b/github/event_types_test.go index 79532d4916..e2a8a39f14 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -17885,3 +17885,97 @@ func TestCodeScanningAlertEvent_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } + +func TestSponsorshipEvent_Marshal(t *testing.T) { + testJSONMarshal(t, &SponsorshipEvent{}, "{}") + + u := &SponsorshipEvent{ + Action: String("created"), + EffectiveDate: String("2023-01-01T00:00:00Z"), + Changes: &SponsorshipChanges{ + Tier: &SponsorshipTier{ + From: String("basic"), + }, + PrivacyLevel: String("public"), + }, + Repository: &Repository{ + ID: Int64(12345), + NodeID: String("MDEwOlJlcG9zaXRvcnkxMjM0NQ=="), + Name: String("example-repo"), + }, + Organization: &Organization{ + Login: String("example-org"), + ID: Int64(67890), + }, + Sender: &User{ + Login: String("example-user"), + ID: Int64(1111), + }, + Installation: &Installation{ + ID: Int64(2222), + }, + } + + want := `{ + "action": "created", + "effective_date": "2023-01-01T00:00:00Z", + "changes": { + "tier": { + "from": "basic" + }, + "privacy_level": "public" + }, + "repository": { + "id": 12345, + "node_id": "MDEwOlJlcG9zaXRvcnkxMjM0NQ==", + "name": "example-repo" + }, + "organization": { + "login": "example-org", + "id": 67890 + }, + "sender": { + "login": "example-user", + "id": 1111 + }, + "installation": { + "id": 2222 + } + }` + + testJSONMarshal(t, u, want) +} + +func TestSponsorshipChanges_Marshal(t *testing.T) { + testJSONMarshal(t, &SponsorshipChanges{}, "{}") + + u := &SponsorshipChanges{ + Tier: &SponsorshipTier{ + From: String("premium"), + }, + PrivacyLevel: String("private"), + } + + want := `{ + "tier": { + "from": "premium" + }, + "privacy_level": "private" + }` + + testJSONMarshal(t, u, want) +} + +func TestSponsorshipTier_Marshal(t *testing.T) { + testJSONMarshal(t, &SponsorshipTier{}, "{}") + + u := &SponsorshipTier{ + From: String("gold"), + } + + want := `{ + "from": "gold" + }` + + testJSONMarshal(t, u, want) +} diff --git a/github/github-accessors.go b/github/github-accessors.go index 10096e44f2..1abbabd0b6 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -22398,6 +22398,86 @@ func (s *SourceImportAuthor) GetURL() string { return *s.URL } +// GetPrivacyLevel returns the PrivacyLevel field if it's non-nil, zero value otherwise. +func (s *SponsorshipChanges) GetPrivacyLevel() string { + if s == nil || s.PrivacyLevel == nil { + return "" + } + return *s.PrivacyLevel +} + +// GetTier returns the Tier field. +func (s *SponsorshipChanges) GetTier() *SponsorshipTier { + if s == nil { + return nil + } + return s.Tier +} + +// GetAction returns the Action field if it's non-nil, zero value otherwise. +func (s *SponsorshipEvent) GetAction() string { + if s == nil || s.Action == nil { + return "" + } + return *s.Action +} + +// GetChanges returns the Changes field. +func (s *SponsorshipEvent) GetChanges() *SponsorshipChanges { + if s == nil { + return nil + } + return s.Changes +} + +// GetEffectiveDate returns the EffectiveDate field if it's non-nil, zero value otherwise. +func (s *SponsorshipEvent) GetEffectiveDate() string { + if s == nil || s.EffectiveDate == nil { + return "" + } + return *s.EffectiveDate +} + +// GetInstallation returns the Installation field. +func (s *SponsorshipEvent) GetInstallation() *Installation { + if s == nil { + return nil + } + return s.Installation +} + +// GetOrganization returns the Organization field. +func (s *SponsorshipEvent) GetOrganization() *Organization { + if s == nil { + return nil + } + return s.Organization +} + +// GetRepository returns the Repository field. +func (s *SponsorshipEvent) GetRepository() *Repository { + if s == nil { + return nil + } + return s.Repository +} + +// GetSender returns the Sender field. +func (s *SponsorshipEvent) GetSender() *User { + if s == nil { + return nil + } + return s.Sender +} + +// GetFrom returns the From field if it's non-nil, zero value otherwise. +func (s *SponsorshipTier) GetFrom() string { + if s == nil || s.From == nil { + return "" + } + return *s.From +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (s *SSHSigningKey) GetCreatedAt() Timestamp { if s == nil || s.CreatedAt == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index aa694fd58e..6d1419c79f 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -26018,6 +26018,88 @@ func TestSourceImportAuthor_GetURL(tt *testing.T) { s.GetURL() } +func TestSponsorshipChanges_GetPrivacyLevel(tt *testing.T) { + var zeroValue string + s := &SponsorshipChanges{PrivacyLevel: &zeroValue} + s.GetPrivacyLevel() + s = &SponsorshipChanges{} + s.GetPrivacyLevel() + s = nil + s.GetPrivacyLevel() +} + +func TestSponsorshipChanges_GetTier(tt *testing.T) { + s := &SponsorshipChanges{} + s.GetTier() + s = nil + s.GetTier() +} + +func TestSponsorshipEvent_GetAction(tt *testing.T) { + var zeroValue string + s := &SponsorshipEvent{Action: &zeroValue} + s.GetAction() + s = &SponsorshipEvent{} + s.GetAction() + s = nil + s.GetAction() +} + +func TestSponsorshipEvent_GetChanges(tt *testing.T) { + s := &SponsorshipEvent{} + s.GetChanges() + s = nil + s.GetChanges() +} + +func TestSponsorshipEvent_GetEffectiveDate(tt *testing.T) { + var zeroValue string + s := &SponsorshipEvent{EffectiveDate: &zeroValue} + s.GetEffectiveDate() + s = &SponsorshipEvent{} + s.GetEffectiveDate() + s = nil + s.GetEffectiveDate() +} + +func TestSponsorshipEvent_GetInstallation(tt *testing.T) { + s := &SponsorshipEvent{} + s.GetInstallation() + s = nil + s.GetInstallation() +} + +func TestSponsorshipEvent_GetOrganization(tt *testing.T) { + s := &SponsorshipEvent{} + s.GetOrganization() + s = nil + s.GetOrganization() +} + +func TestSponsorshipEvent_GetRepository(tt *testing.T) { + s := &SponsorshipEvent{} + s.GetRepository() + s = nil + s.GetRepository() +} + +func TestSponsorshipEvent_GetSender(tt *testing.T) { + s := &SponsorshipEvent{} + s.GetSender() + s = nil + s.GetSender() +} + +func TestSponsorshipTier_GetFrom(tt *testing.T) { + var zeroValue string + s := &SponsorshipTier{From: &zeroValue} + s.GetFrom() + s = &SponsorshipTier{} + s.GetFrom() + s = nil + s.GetFrom() +} + func TestSSHSigningKey_GetCreatedAt(tt *testing.T) { var zeroValue Timestamp s := &SSHSigningKey{CreatedAt: &zeroValue} diff --git a/github/messages.go b/github/messages.go index 72edbd9fee..0385d398bd 100644 --- a/github/messages.go +++ b/github/messages.go @@ -102,6 +102,7 @@ var ( "secret_scanning_alert": &SecretScanningAlertEvent{}, "security_advisory": &SecurityAdvisoryEvent{}, "security_and_analysis": &SecurityAndAnalysisEvent{}, + "sponsorship": &SponsorshipEvent{}, "star": &StarEvent{}, "status": &StatusEvent{}, "team": &TeamEvent{}, diff --git a/github/messages_test.go b/github/messages_test.go index 1243d755be..4783ec683a 100644 --- a/github/messages_test.go +++ b/github/messages_test.go @@ -468,6 +468,10 @@ func TestParseWebHook(t *testing.T) { payload: &SecurityAndAnalysisEvent{}, messageType: "security_and_analysis", }, + { + payload: &SponsorshipEvent{}, + messageType: "sponsorship", + }, { payload: &StarEvent{}, messageType: "star",