Skip to content

define struct types instead of using anonymous structs #1900

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

Merged
merged 11 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 19 additions & 16 deletions github/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,25 @@ type FeedLink struct {

// Feeds represents timeline resources in Atom format.
type Feeds struct {
TimelineURL *string `json:"timeline_url,omitempty"`
UserURL *string `json:"user_url,omitempty"`
CurrentUserPublicURL *string `json:"current_user_public_url,omitempty"`
CurrentUserURL *string `json:"current_user_url,omitempty"`
CurrentUserActorURL *string `json:"current_user_actor_url,omitempty"`
CurrentUserOrganizationURL *string `json:"current_user_organization_url,omitempty"`
CurrentUserOrganizationURLs []string `json:"current_user_organization_urls,omitempty"`
Links *struct {
Timeline *FeedLink `json:"timeline,omitempty"`
User *FeedLink `json:"user,omitempty"`
CurrentUserPublic *FeedLink `json:"current_user_public,omitempty"`
CurrentUser *FeedLink `json:"current_user,omitempty"`
CurrentUserActor *FeedLink `json:"current_user_actor,omitempty"`
CurrentUserOrganization *FeedLink `json:"current_user_organization,omitempty"`
CurrentUserOrganizations []*FeedLink `json:"current_user_organizations,omitempty"`
} `json:"_links,omitempty"`
TimelineURL *string `json:"timeline_url,omitempty"`
UserURL *string `json:"user_url,omitempty"`
CurrentUserPublicURL *string `json:"current_user_public_url,omitempty"`
CurrentUserURL *string `json:"current_user_url,omitempty"`
CurrentUserActorURL *string `json:"current_user_actor_url,omitempty"`
CurrentUserOrganizationURL *string `json:"current_user_organization_url,omitempty"`
CurrentUserOrganizationURLs []string `json:"current_user_organization_urls,omitempty"`
Links *FeedLinks `json:"_links,omitempty"`
}

// FeedLinks represents the links in a Feed.
type FeedLinks struct {
Timeline *FeedLink `json:"timeline,omitempty"`
User *FeedLink `json:"user,omitempty"`
CurrentUserPublic *FeedLink `json:"current_user_public,omitempty"`
CurrentUser *FeedLink `json:"current_user,omitempty"`
CurrentUserActor *FeedLink `json:"current_user_actor,omitempty"`
CurrentUserOrganization *FeedLink `json:"current_user_organization,omitempty"`
CurrentUserOrganizations []*FeedLink `json:"current_user_organizations,omitempty"`
}

// ListFeeds lists all the feeds available to the authenticated user.
Expand Down
10 changes: 1 addition & 9 deletions github/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,7 @@ var wantFeeds = &Feeds{
CurrentUserOrganizationURLs: []string{
"https://github.com/organizations/github/defunkt.private.atom?token=abc123",
},
Links: &struct {
Timeline *FeedLink `json:"timeline,omitempty"`
User *FeedLink `json:"user,omitempty"`
CurrentUserPublic *FeedLink `json:"current_user_public,omitempty"`
CurrentUser *FeedLink `json:"current_user,omitempty"`
CurrentUserActor *FeedLink `json:"current_user_actor,omitempty"`
CurrentUserOrganization *FeedLink `json:"current_user_organization,omitempty"`
CurrentUserOrganizations []*FeedLink `json:"current_user_organizations,omitempty"`
}{
Links: &FeedLinks{
Timeline: &FeedLink{
HRef: String("https://github.com/timeline"),
Type: String("application/atom+xml"),
Expand Down
158 changes: 103 additions & 55 deletions github/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,66 +215,111 @@ type GollumEvent struct {
// EditChange represents the changes when an issue, pull request, or comment has
// been edited.
type EditChange struct {
Title *struct {
From *string `json:"from,omitempty"`
} `json:"title,omitempty"`
Body *struct {
From *string `json:"from,omitempty"`
} `json:"body,omitempty"`
Base *struct {
Ref *struct {
From *string `json:"from,omitempty"`
} `json:"ref,omitempty"`
SHA *struct {
From *string `json:"from,omitempty"`
} `json:"sha,omitempty"`
} `json:"base,omitempty"`
Title *EditTitle `json:"title,omitempty"`
Body *EditBody `json:"body,omitempty"`
Base *EditBase `json:"base,omitempty"`
}

// EditTitle represents a pull-request title change.
type EditTitle struct {
From *string `json:"from,omitempty"`
}

// EditBody represents a change of pull-request body.
type EditBody struct {
From *string `json:"from,omitempty"`
}

// EditBase represents the change of a pull-request base branch.
type EditBase struct {
Ref *EditRef `json:"ref,omitempty"`
SHA *EditSHA `json:"sha,omitempty"`
}

// EditRef represents a ref change of a pull-request.
type EditRef struct {
From *string `json:"from,omitempty"`
}

// EditSHA represents a sha change of a pull-request.
type EditSHA struct {
From *string `json:"from,omitempty"`
}

// ProjectChange represents the changes when a project has been edited.
type ProjectChange struct {
Name *struct {
From *string `json:"from,omitempty"`
} `json:"name,omitempty"`
Body *struct {
From *string `json:"from,omitempty"`
} `json:"body,omitempty"`
Name *ProjectName `json:"name,omitempty"`
Body *ProjectBody `json:"body,omitempty"`
}

// ProjectName represents a project name change.
type ProjectName struct {
From *string `json:"from,omitempty"`
}

// ProjectBody represents a project body change.
type ProjectBody struct {
From *string `json:"from,omitempty"`
}

// ProjectCardChange represents the changes when a project card has been edited.
type ProjectCardChange struct {
Note *struct {
From *string `json:"from,omitempty"`
} `json:"note,omitempty"`
Note *ProjectCardNote `json:"note,omitempty"`
}

// ProjectCardNote represents a change of a note of a project card.
type ProjectCardNote struct {
From *string `json:"from,omitempty"`
}

// ProjectColumnChange represents the changes when a project column has been edited.
type ProjectColumnChange struct {
Name *struct {
From *string `json:"from,omitempty"`
} `json:"name,omitempty"`
Name *ProjectColumnName `json:"name,omitempty"`
}

// ProjectColumnName represents a project column name change.
type ProjectColumnName struct {
From *string `json:"from,omitempty"`
}

// TeamChange represents the changes when a team has been edited.
type TeamChange struct {
Description *struct {
From *string `json:"from,omitempty"`
} `json:"description,omitempty"`
Name *struct {
From *string `json:"from,omitempty"`
} `json:"name,omitempty"`
Privacy *struct {
From *string `json:"from,omitempty"`
} `json:"privacy,omitempty"`
Repository *struct {
Permissions *struct {
From *struct {
Admin *bool `json:"admin,omitempty"`
Pull *bool `json:"pull,omitempty"`
Push *bool `json:"push,omitempty"`
} `json:"from,omitempty"`
} `json:"permissions,omitempty"`
} `json:"repository,omitempty"`
Description *TeamDescription `json:"description,omitempty"`
Name *TeamName `json:"name,omitempty"`
Privacy *TeamPrivacy `json:"privacy,omitempty"`
Repository *TeamRepository `json:"repository,omitempty"`
}

// TeamDescription represents a team description change.
type TeamDescription struct {
From *string `json:"from,omitempty"`
}

// TeamName represents a team name change.
type TeamName struct {
From *string `json:"from,omitempty"`
}

// TeamPrivacy represents a team privacy change.
type TeamPrivacy struct {
From *string `json:"from,omitempty"`
}

// TeamRepository represents a team repository permission change.
type TeamRepository struct {
Permissions *TeamPermissions `json:"permissions,omitempty"`
}

// TeamPermissions represents a team permission change.
type TeamPermissions struct {
From *TeamPermissionsFrom `json:"from,omitempty"`
}

// TeamPermissionsFrom represents a team permission change.
type TeamPermissionsFrom struct {
Admin *bool `json:"admin,omitempty"`
Pull *bool `json:"pull,omitempty"`
Push *bool `json:"push,omitempty"`
}

// InstallationEvent is triggered when a GitHub App has been installed, uninstalled, suspend, unsuspended
Expand Down Expand Up @@ -890,22 +935,25 @@ type RepositoryVulnerabilityAlertEvent struct {
Action *string `json:"action,omitempty"`

//The security alert of the vulnerable dependency.
Alert *struct {
ID *int64 `json:"id,omitempty"`
AffectedRange *string `json:"affected_range,omitempty"`
AffectedPackageName *string `json:"affected_package_name,omitempty"`
ExternalReference *string `json:"external_reference,omitempty"`
ExternalIdentifier *string `json:"external_identifier,omitempty"`
FixedIn *string `json:"fixed_in,omitempty"`
Dismisser *User `json:"dismisser,omitempty"`
DismissReason *string `json:"dismiss_reason,omitempty"`
DismissedAt *Timestamp `json:"dismissed_at,omitempty"`
} `json:"alert,omitempty"`
Alert *RepositoryVulnerabilityAlert `json:"alert,omitempty"`

//The repository of the vulnerable dependency.
Repository *Repository `json:"repository,omitempty"`
}

// RepositoryVulnerabilityAlert represents a repository security alert.
type RepositoryVulnerabilityAlert struct {
ID *int64 `json:"id,omitempty"`
AffectedRange *string `json:"affected_range,omitempty"`
AffectedPackageName *string `json:"affected_package_name,omitempty"`
ExternalReference *string `json:"external_reference,omitempty"`
ExternalIdentifier *string `json:"external_identifier,omitempty"`
FixedIn *string `json:"fixed_in,omitempty"`
Dismisser *User `json:"dismisser,omitempty"`
DismissReason *string `json:"dismiss_reason,omitempty"`
DismissedAt *Timestamp `json:"dismissed_at,omitempty"`
}

// StarEvent is triggered when a star is added or removed from a repository.
// The Webhook event name is "star".
//
Expand Down
55 changes: 16 additions & 39 deletions github/event_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ import (
func TestEditChange_Marshal_TitleChange(t *testing.T) {
testJSONMarshal(t, &EditChange{}, "{}")

TitleFrom := struct {
From *string `json:"from,omitempty"`
}{
From: String("TitleFrom"),
}

u := &EditChange{
Title: &TitleFrom,
Body: nil,
Base: nil,
Title: &EditTitle{
From: String("TitleFrom"),
},
Body: nil,
Base: nil,
}

want := `{
Expand All @@ -36,16 +32,12 @@ func TestEditChange_Marshal_TitleChange(t *testing.T) {
func TestEditChange_Marshal_BodyChange(t *testing.T) {
testJSONMarshal(t, &EditChange{}, "{}")

BodyFrom := struct {
From *string `json:"from,omitempty"`
}{
From: String("BodyFrom"),
}

u := &EditChange{
Title: nil,
Body: &BodyFrom,
Base: nil,
Body: &EditBody{
From: String("BodyFrom"),
},
Base: nil,
}

want := `{
Expand All @@ -60,28 +52,13 @@ func TestEditChange_Marshal_BodyChange(t *testing.T) {
func TestEditChange_Marshal_BaseChange(t *testing.T) {
testJSONMarshal(t, &EditChange{}, "{}")

RefFrom := struct {
From *string `json:"from,omitempty"`
}{
From: String("BaseRefFrom"),
}

SHAFrom := struct {
From *string `json:"from,omitempty"`
}{
From: String("BaseSHAFrom"),
}

Base := struct {
Ref *struct {
From *string `json:"from,omitempty"`
} `json:"ref,omitempty"`
SHA *struct {
From *string `json:"from,omitempty"`
} `json:"sha,omitempty"`
}{
Ref: &RefFrom,
SHA: &SHAFrom,
Base := EditBase{
Ref: &EditRef{
From: String("BaseRefFrom"),
},
SHA: &EditSHA{
From: String("BaseSHAFrom"),
},
}

u := &EditChange{
Expand Down
Loading