Skip to content

Commit

Permalink
Add type SponsorshipEvent (#3258)
Browse files Browse the repository at this point in the history
Fixes: #2982.
  • Loading branch information
DiegoDev2 authored Sep 10, 2024
1 parent a1e9d75 commit 662da6f
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 0 deletions.
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 @@ -468,6 +468,10 @@ func TestParseWebHook(t *testing.T) {
payload: &SecurityAndAnalysisEvent{},
messageType: "security_and_analysis",
},
{
payload: &SponsorshipEvent{},
messageType: "sponsorship",
},
{
payload: &StarEvent{},
messageType: "star",
Expand Down

0 comments on commit 662da6f

Please sign in to comment.