Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type SponsorshipEvent #3258

Merged
merged 8 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions github/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
94 changes: 94 additions & 0 deletions github/event_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
80 changes: 80 additions & 0 deletions github/github-accessors.go

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

82 changes: 82 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.

1 change: 1 addition & 0 deletions github/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var (
"secret_scanning_alert": &SecretScanningAlertEvent{},
"security_advisory": &SecurityAdvisoryEvent{},
"security_and_analysis": &SecurityAndAnalysisEvent{},
"sponsorship": &SponsorshipEvent{},
"star": &StarEvent{},
"status": &StatusEvent{},
"team": &TeamEvent{},
Expand Down
4 changes: 4 additions & 0 deletions github/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ func TestParseWebHook(t *testing.T) {
payload: &StatusEvent{},
messageType: "status",
},
{
CodeDiego15 marked this conversation as resolved.
Show resolved Hide resolved
payload: &SponsorshipEvent{},
messageType: "sponsors",
},
{
payload: &TeamEvent{},
messageType: "team",
Expand Down