From 355b56471ba86aca02345241a7056d025e80a77b Mon Sep 17 00:00:00 2001 From: CodeDiego15 Date: Sun, 8 Sep 2024 03:17:54 -0400 Subject: [PATCH 1/6] [Add Type] Add type SponsorshipEvent --- github/event_types.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/github/event_types.go b/github/event_types.go index df8d9e033e2..41d71f8ddf2 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"` +} From 62efb013bfe5f7407410ddf538c25e05f30c578a Mon Sep 17 00:00:00 2001 From: CodeDiego15 Date: Sun, 8 Sep 2024 13:14:22 -0400 Subject: [PATCH 2/6] [Add Type in event_types_test.go] --- github/event_types_test.go | 94 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/github/event_types_test.go b/github/event_types_test.go index 79532d4916a..e2a8a39f147 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) +} From d0228f02f4d54b8e7e5543c660f33a2138d4e3e5 Mon Sep 17 00:00:00 2001 From: CodeDiego15 Date: Sun, 8 Sep 2024 14:37:07 -0400 Subject: [PATCH 3/6] run step 4 Signed-off-by: CodeDiego15 --- github/github-accessors.go | 80 ++++++++++++++++++++++++++++++++ github/github-accessors_test.go | 82 +++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index 10096e44f21..1abbabd0b63 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 aa694fd58e1..6d1419c79f2 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} From b2e4f612eba4b49e99cf85c5560cdddab6e8a613 Mon Sep 17 00:00:00 2001 From: CodeDiego15 Date: Mon, 9 Sep 2024 15:44:17 -0400 Subject: [PATCH 4/6] Add sponsorship in messages.go and messages_test.go --- github/messages.go | 1 + github/messages_test.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/github/messages.go b/github/messages.go index 72edbd9feef..0385d398bda 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 1243d755be8..49990d7fb9b 100644 --- a/github/messages_test.go +++ b/github/messages_test.go @@ -476,6 +476,10 @@ func TestParseWebHook(t *testing.T) { payload: &StatusEvent{}, messageType: "status", }, + { + payload: &SponsorshipEvent{}, + messageType: "sponsors", + }, { payload: &TeamEvent{}, messageType: "team", From b2cf37c1ddaacb5bf685fc0264aa915fca74d29a Mon Sep 17 00:00:00 2001 From: CodeDiego15 Date: Mon, 9 Sep 2024 16:51:51 -0400 Subject: [PATCH 5/6] We ordered part of messages_test.go well --- github/messages_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/github/messages_test.go b/github/messages_test.go index 49990d7fb9b..dcfc571d234 100644 --- a/github/messages_test.go +++ b/github/messages_test.go @@ -465,21 +465,25 @@ func TestParseWebHook(t *testing.T) { messageType: "security_advisory", }, { - payload: &SecurityAndAnalysisEvent{}, - messageType: "security_and_analysis", + payload: &SecretScanningAlertEvent{}, + messageType: "secret_scanning_alert", }, { - payload: &StarEvent{}, - messageType: "star", + payload: &SecurityAdvisoryEvent{}, + messageType: "security_advisory", }, { - payload: &StatusEvent{}, - messageType: "status", + payload: &SecurityAndAnalysisEvent{}, + messageType: "security_and_analysis", }, { payload: &SponsorshipEvent{}, messageType: "sponsors", }, + { + payload: &StarEvent{}, + messageType: "star", + }, { payload: &TeamEvent{}, messageType: "team", From b5df93cfdd1dd91d75035b62404b18c731fe5eec Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:44:49 -0400 Subject: [PATCH 6/6] Update messages_test.go --- github/messages_test.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/github/messages_test.go b/github/messages_test.go index dcfc571d234..4783ec683aa 100644 --- a/github/messages_test.go +++ b/github/messages_test.go @@ -464,26 +464,22 @@ func TestParseWebHook(t *testing.T) { payload: &SecurityAdvisoryEvent{}, messageType: "security_advisory", }, - { - payload: &SecretScanningAlertEvent{}, - messageType: "secret_scanning_alert", - }, - { - payload: &SecurityAdvisoryEvent{}, - messageType: "security_advisory", - }, { payload: &SecurityAndAnalysisEvent{}, messageType: "security_and_analysis", }, { payload: &SponsorshipEvent{}, - messageType: "sponsors", + messageType: "sponsorship", }, { payload: &StarEvent{}, messageType: "star", }, + { + payload: &StatusEvent{}, + messageType: "status", + }, { payload: &TeamEvent{}, messageType: "team",