diff --git a/github/payload.go b/github/payload.go index bbd26a3..07fb260 100644 --- a/github/payload.go +++ b/github/payload.go @@ -718,28 +718,17 @@ type PullRequestReviewCommentPayload struct { // PushPayload contains the information for GitHub's push hook event type PushPayload struct { - Ref string `json:"ref"` - Before string `json:"before"` - After string `json:"after"` - Created bool `json:"created"` - Deleted bool `json:"deleted"` - Forced bool `json:"forced"` - BaseRef *string `json:"base_ref"` - Compare string `json:"compare"` - Commits []*Commit `json:"commits"` - HeadCommit *Commit `json:"head_commit"` - //TODO: the repository object for this payload is slightly different - //should we ignore or create a separate type? - //diff: - // +@ ["repository","master_branch"] - // +- "master" - // +@ ["repository","owner","email"] - // +- "21031067+Codertocat@users.noreply.github.com" - // +@ ["repository","owner","name"] - // +- "Codertocat" - // +@ ["repository","stargazers"] - // +- 0 - Repository Repository `json:"repository"` + Ref string `json:"ref"` + Before string `json:"before"` + After string `json:"after"` + Created bool `json:"created"` + Deleted bool `json:"deleted"` + Forced bool `json:"forced"` + BaseRef *string `json:"base_ref"` + Compare string `json:"compare"` + Commits []*Commit `json:"commits"` + HeadCommit *Commit `json:"head_commit"` + Repository PushRepository `json:"repository"` Pusher struct { Name string `json:"name"` Email string `json:"email"` @@ -1053,6 +1042,30 @@ type User struct { SiteAdmin bool `json:"site_admin"` } +// PushRepositoryOwner represents a user in a PushPayload which differs slightly from other user objects. +type PushRepositoryOwner struct { + Login string `json:"login"` + ID int64 `json:"id"` + NodeID string `json:"node_id"` + AvatarURL string `json:"avatar_url"` + GravatarID string `json:"gravatar_id"` + URL string `json:"url"` + HTMLURL string `json:"html_url"` + FollowersURL string `json:"followers_url"` + FollowingURL string `json:"following_url"` + GistsURL string `json:"gists_url"` + StarredURL string `json:"starred_url"` + SubscriptionsURL string `json:"subscriptions_url"` + OrganizationsURL string `json:"organizations_url"` + ReposURL string `json:"repos_url"` + EventsURL string `json:"events_url"` + ReceivedEventsURL string `json:"received_events_url"` + Type string `json:"type"` + SiteAdmin bool `json:"site_admin"` + Email string `json:"email"` + Name string `json:"name"` +} + // Milestone contains GitHub's milestone information type Milestone struct { URL string `json:"url"` @@ -1183,6 +1196,86 @@ type Repository struct { DefaultBranch string `json:"default_branch"` } +// PushRepository represents the repository object of a PushPayload, +// CreatedAt and PushedAt are integer timestamps instead of formatted dates. +type PushRepository struct { + ID int64 `json:"id"` + NodeID string `json:"node_id"` + Name string `json:"name"` + FullName string `json:"full_name"` + Owner PushRepositoryOwner `json:"owner"` + Private bool `json:"private"` + Archived bool `json:"archived"` + Disabled bool `json:"disabled"` + HTMLURL string `json:"html_url"` + Description *string `json:"description"` + Fork bool `json:"fork"` + URL string `json:"url"` + ForksURL string `json:"forks_url"` + KeysURL string `json:"keys_url"` + CollaboratorsURL string `json:"collaborators_url"` + TeamsURL string `json:"teams_url"` + HooksURL string `json:"hooks_url"` + IssueEventsURL string `json:"issue_events_url"` + EventsURL string `json:"events_url"` + AssigneesURL string `json:"assignees_url"` + BranchesURL string `json:"branches_url"` + TagsURL string `json:"tags_url"` + BlobsURL string `json:"blobs_url"` + GitTagsURL string `json:"git_tags_url"` + GitRefsURL string `json:"git_refs_url"` + TreesURL string `json:"trees_url"` + StatusesURL string `json:"statuses_url"` + LanguagesURL string `json:"languages_url"` + StargazersURL string `json:"stargazers_url"` + ContributorsURL string `json:"contributors_url"` + SubscribersURL string `json:"subscribers_url"` + SubscriptionURL string `json:"subscription_url"` + CommitsURL string `json:"commits_url"` + GitCommitsURL string `json:"git_commits_url"` + CommentsURL string `json:"comments_url"` + IssueCommentURL string `json:"issue_comment_url"` + ContentsURL string `json:"contents_url"` + CompareURL string `json:"compare_url"` + MergesURL string `json:"merges_url"` + ArchiveURL string `json:"archive_url"` + DownloadsURL string `json:"downloads_url"` + IssuesURL string `json:"issues_url"` + PullsURL string `json:"pulls_url"` + MilestonesURL string `json:"milestones_url"` + NotificationsURL string `json:"notifications_url"` + LabelsURL string `json:"labels_url"` + ReleasesURL string `json:"releases_url"` + CreatedAt int64 `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + PushedAt int64 `json:"pushed_at"` + GitURL string `json:"git_url"` + SSHURL string `json:"ssh_url"` + CloneURL string `json:"clone_url"` + SvnURL string `json:"svn_url"` + DeploymentsURL string `json:"deployments_url"` + License *string `json:"license"` + Homepage *string `json:"homepage"` + Size int64 `json:"size"` + StargazersCount int64 `json:"stargazers_count"` + WatchersCount int64 `json:"watchers_count"` + Language *string `json:"language"` + HasIssues bool `json:"has_issues"` + HasDownloads bool `json:"has_downloads"` + HasWiki bool `json:"has_wiki"` + HasPages bool `json:"has_pages"` + HasProjects bool `json:"has_projects"` + ForksCount int64 `json:"forks_count"` + MirrorURL *string `json:"mirror_url"` + OpenIssuesCount int64 `json:"open_issues_count"` + Forks int64 `json:"forks"` + OpenIssues int64 `json:"open_issues"` + Watchers int64 `json:"watchers"` + DefaultBranch string `json:"default_branch"` + MasterBranch string `json:"master_branch"` + Stargazers int `json:"stargazers"` +} + // Installation contains the ID of the installation of the app that recieved the payload type Installation struct { ID int64 `json:"id"` @@ -1294,9 +1387,7 @@ type Issue struct { // Commit contains information about a commit in a push payload type Commit struct { - Sha string `json:"sha"` ID string `json:"id"` - NodeID string `json:"node_id"` TreeID string `json:"tree_id"` Distinct bool `json:"distinct"` Message string `json:"message"` diff --git a/testdata/github/push.json b/testdata/github/push.json index 121f0f3..16d9f23 100755 --- a/testdata/github/push.json +++ b/testdata/github/push.json @@ -16,6 +16,8 @@ "full_name": "Codertocat/Hello-World", "private": false, "owner": { + "name": "Codertocat", + "email": "21031067+Codertocat@users.noreply.github.com", "login": "Codertocat", "id": 21031067, "node_id": "MDQ6VXNlcjIxMDMxMDY3", @@ -75,9 +77,9 @@ "labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}", "releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}", "deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments", - "created_at": "2019-05-15T15:20:41Z", + "created_at": 1557933565, "updated_at": "2019-05-15T15:20:41Z", - "pushed_at": "2019-05-15T15:20:41Z", + "pushed_at": 1557933657, "git_url": "git://github.com/Codertocat/Hello-World.git", "ssh_url": "git@github.com:Codertocat/Hello-World.git", "clone_url": "https://github.com/Codertocat/Hello-World.git", @@ -101,7 +103,9 @@ "forks": 1, "open_issues": 2, "watchers": 0, - "default_branch": "master" + "default_branch": "master", + "stargazers": 0, + "master_branch": "master" }, "pusher": { "name": "Codertocat",