Skip to content

Commit 662da6f

Browse files
authored
Add type SponsorshipEvent (#3258)
Fixes: #2982.
1 parent a1e9d75 commit 662da6f

File tree

6 files changed

+285
-0
lines changed

6 files changed

+285
-0
lines changed

github/event_types.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,3 +1821,27 @@ type CodeScanningAlertEvent struct {
18211821

18221822
Installation *Installation `json:"installation,omitempty"`
18231823
}
1824+
1825+
// SponsorshipEvent represents a sponsorship event in GitHub.
1826+
//
1827+
// GitHub API docs: https://docs.github.com/en/rest/overview/github-event-types?apiVersion=2022-11-28#sponsorshipevent
1828+
type SponsorshipEvent struct {
1829+
Action *string `json:"action,omitempty"`
1830+
EffectiveDate *string `json:"effective_date,omitempty"`
1831+
Changes *SponsorshipChanges `json:"changes,omitempty"`
1832+
Repository *Repository `json:"repository,omitempty"`
1833+
Organization *Organization `json:"organization,omitempty"`
1834+
Sender *User `json:"sender,omitempty"`
1835+
Installation *Installation `json:"installation,omitempty"`
1836+
}
1837+
1838+
// SponsorshipChanges represents changes made to the sponsorship.
1839+
type SponsorshipChanges struct {
1840+
Tier *SponsorshipTier `json:"tier,omitempty"`
1841+
PrivacyLevel *string `json:"privacy_level,omitempty"`
1842+
}
1843+
1844+
// SponsorshipTier represents the tier information of a sponsorship.
1845+
type SponsorshipTier struct {
1846+
From *string `json:"from,omitempty"`
1847+
}

github/event_types_test.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17885,3 +17885,97 @@ func TestCodeScanningAlertEvent_Marshal(t *testing.T) {
1788517885

1788617886
testJSONMarshal(t, u, want)
1788717887
}
17888+
17889+
func TestSponsorshipEvent_Marshal(t *testing.T) {
17890+
testJSONMarshal(t, &SponsorshipEvent{}, "{}")
17891+
17892+
u := &SponsorshipEvent{
17893+
Action: String("created"),
17894+
EffectiveDate: String("2023-01-01T00:00:00Z"),
17895+
Changes: &SponsorshipChanges{
17896+
Tier: &SponsorshipTier{
17897+
From: String("basic"),
17898+
},
17899+
PrivacyLevel: String("public"),
17900+
},
17901+
Repository: &Repository{
17902+
ID: Int64(12345),
17903+
NodeID: String("MDEwOlJlcG9zaXRvcnkxMjM0NQ=="),
17904+
Name: String("example-repo"),
17905+
},
17906+
Organization: &Organization{
17907+
Login: String("example-org"),
17908+
ID: Int64(67890),
17909+
},
17910+
Sender: &User{
17911+
Login: String("example-user"),
17912+
ID: Int64(1111),
17913+
},
17914+
Installation: &Installation{
17915+
ID: Int64(2222),
17916+
},
17917+
}
17918+
17919+
want := `{
17920+
"action": "created",
17921+
"effective_date": "2023-01-01T00:00:00Z",
17922+
"changes": {
17923+
"tier": {
17924+
"from": "basic"
17925+
},
17926+
"privacy_level": "public"
17927+
},
17928+
"repository": {
17929+
"id": 12345,
17930+
"node_id": "MDEwOlJlcG9zaXRvcnkxMjM0NQ==",
17931+
"name": "example-repo"
17932+
},
17933+
"organization": {
17934+
"login": "example-org",
17935+
"id": 67890
17936+
},
17937+
"sender": {
17938+
"login": "example-user",
17939+
"id": 1111
17940+
},
17941+
"installation": {
17942+
"id": 2222
17943+
}
17944+
}`
17945+
17946+
testJSONMarshal(t, u, want)
17947+
}
17948+
17949+
func TestSponsorshipChanges_Marshal(t *testing.T) {
17950+
testJSONMarshal(t, &SponsorshipChanges{}, "{}")
17951+
17952+
u := &SponsorshipChanges{
17953+
Tier: &SponsorshipTier{
17954+
From: String("premium"),
17955+
},
17956+
PrivacyLevel: String("private"),
17957+
}
17958+
17959+
want := `{
17960+
"tier": {
17961+
"from": "premium"
17962+
},
17963+
"privacy_level": "private"
17964+
}`
17965+
17966+
testJSONMarshal(t, u, want)
17967+
}
17968+
17969+
func TestSponsorshipTier_Marshal(t *testing.T) {
17970+
testJSONMarshal(t, &SponsorshipTier{}, "{}")
17971+
17972+
u := &SponsorshipTier{
17973+
From: String("gold"),
17974+
}
17975+
17976+
want := `{
17977+
"from": "gold"
17978+
}`
17979+
17980+
testJSONMarshal(t, u, want)
17981+
}

github/github-accessors.go

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/messages.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ var (
102102
"secret_scanning_alert": &SecretScanningAlertEvent{},
103103
"security_advisory": &SecurityAdvisoryEvent{},
104104
"security_and_analysis": &SecurityAndAnalysisEvent{},
105+
"sponsorship": &SponsorshipEvent{},
105106
"star": &StarEvent{},
106107
"status": &StatusEvent{},
107108
"team": &TeamEvent{},

github/messages_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ func TestParseWebHook(t *testing.T) {
468468
payload: &SecurityAndAnalysisEvent{},
469469
messageType: "security_and_analysis",
470470
},
471+
{
472+
payload: &SponsorshipEvent{},
473+
messageType: "sponsorship",
474+
},
471475
{
472476
payload: &StarEvent{},
473477
messageType: "star",

0 commit comments

Comments
 (0)