Skip to content

Commit e9d3dcd

Browse files
fixed push payload
1 parent a51ca31 commit e9d3dcd

File tree

3 files changed

+61
-166
lines changed

3 files changed

+61
-166
lines changed

github/payload.go

Lines changed: 47 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,154 +2305,55 @@ type PullRequestReviewCommentPayload struct {
23052305
} `json:"sender"`
23062306
Installation Installation `json:"installation"`
23072307
}
2308+
type Commit struct {
2309+
Sha string `json:"sha"`
2310+
ID string `json:"id"`
2311+
NodeID string `json:"node_id"`
2312+
TreeID string `json:"tree_id"`
2313+
Distinct bool `json:"distinct"`
2314+
Message string `json:"message"`
2315+
Timestamp string `json:"timestamp"`
2316+
URL string `json:"url"`
2317+
Author struct {
2318+
Name string `json:"name"`
2319+
Email string `json:"email"`
2320+
Username string `json:"username"`
2321+
} `json:"author"`
2322+
Committer struct {
2323+
Name string `json:"name"`
2324+
Email string `json:"email"`
2325+
Username string `json:"username"`
2326+
} `json:"committer"`
2327+
Added []string `json:"added"`
2328+
Removed []string `json:"removed"`
2329+
Modified []string `json:"modified"`
2330+
}
23082331

23092332
// PushPayload contains the information for GitHub's push hook event
23102333
type PushPayload struct {
2311-
Ref string `json:"ref"`
2312-
Before string `json:"before"`
2313-
After string `json:"after"`
2314-
Created bool `json:"created"`
2315-
Deleted bool `json:"deleted"`
2316-
Forced bool `json:"forced"`
2317-
BaseRef *string `json:"base_ref"`
2318-
Compare string `json:"compare"`
2319-
Commits []struct {
2320-
Sha string `json:"sha"`
2321-
ID string `json:"id"`
2322-
NodeID string `json:"node_id"`
2323-
TreeID string `json:"tree_id"`
2324-
Distinct bool `json:"distinct"`
2325-
Message string `json:"message"`
2326-
Timestamp string `json:"timestamp"`
2327-
URL string `json:"url"`
2328-
Author struct {
2329-
Name string `json:"name"`
2330-
Email string `json:"email"`
2331-
Username string `json:"username"`
2332-
} `json:"author"`
2333-
Committer struct {
2334-
Name string `json:"name"`
2335-
Email string `json:"email"`
2336-
Username string `json:"username"`
2337-
} `json:"committer"`
2338-
Added []string `json:"added"`
2339-
Removed []string `json:"removed"`
2340-
Modified []string `json:"modified"`
2341-
} `json:"commits"`
2342-
HeadCommit struct {
2343-
ID string `json:"id"`
2344-
NodeID string `json:"node_id"`
2345-
TreeID string `json:"tree_id"`
2346-
Distinct bool `json:"distinct"`
2347-
Message string `json:"message"`
2348-
Timestamp string `json:"timestamp"`
2349-
URL string `json:"url"`
2350-
Author struct {
2351-
Name string `json:"name"`
2352-
Email string `json:"email"`
2353-
Username string `json:"username"`
2354-
} `json:"author"`
2355-
Committer struct {
2356-
Name string `json:"name"`
2357-
Email string `json:"email"`
2358-
Username string `json:"username"`
2359-
} `json:"committer"`
2360-
Added []string `json:"added"`
2361-
Removed []string `json:"removed"`
2362-
Modified []string `json:"modified"`
2363-
} `json:"head_commit"`
2364-
Repository struct {
2365-
ID int64 `json:"id"`
2366-
NodeID string `json:"node_id"`
2367-
Name string `json:"name"`
2368-
FullName string `json:"full_name"`
2369-
Owner struct {
2370-
Login string `json:"login"`
2371-
ID int64 `json:"id"`
2372-
NodeID string `json:"node_id"`
2373-
AvatarURL string `json:"avatar_url"`
2374-
GravatarID string `json:"gravatar_id"`
2375-
URL string `json:"url"`
2376-
HTMLURL string `json:"html_url"`
2377-
FollowersURL string `json:"followers_url"`
2378-
FollowingURL string `json:"following_url"`
2379-
GistsURL string `json:"gists_url"`
2380-
StarredURL string `json:"starred_url"`
2381-
SubscriptionsURL string `json:"subscriptions_url"`
2382-
OrganizationsURL string `json:"organizations_url"`
2383-
ReposURL string `json:"repos_url"`
2384-
EventsURL string `json:"events_url"`
2385-
ReceivedEventsURL string `json:"received_events_url"`
2386-
Type string `json:"type"`
2387-
SiteAdmin bool `json:"site_admin"`
2388-
} `json:"owner"`
2389-
Private bool `json:"private"`
2390-
HTMLURL string `json:"html_url"`
2391-
Description string `json:"description"`
2392-
Fork bool `json:"fork"`
2393-
URL string `json:"url"`
2394-
ForksURL string `json:"forks_url"`
2395-
KeysURL string `json:"keys_url"`
2396-
CollaboratorsURL string `json:"collaborators_url"`
2397-
TeamsURL string `json:"teams_url"`
2398-
HooksURL string `json:"hooks_url"`
2399-
IssueEventsURL string `json:"issue_events_url"`
2400-
EventsURL string `json:"events_url"`
2401-
AssigneesURL string `json:"assignees_url"`
2402-
BranchesURL string `json:"branches_url"`
2403-
TagsURL string `json:"tags_url"`
2404-
BlobsURL string `json:"blobs_url"`
2405-
GitTagsURL string `json:"git_tags_url"`
2406-
GitRefsURL string `json:"git_refs_url"`
2407-
TreesURL string `json:"trees_url"`
2408-
StatusesURL string `json:"statuses_url"`
2409-
LanguagesURL string `json:"languages_url"`
2410-
StargazersURL string `json:"stargazers_url"`
2411-
ContributorsURL string `json:"contributors_url"`
2412-
SubscribersURL string `json:"subscribers_url"`
2413-
SubscriptionURL string `json:"subscription_url"`
2414-
CommitsURL string `json:"commits_url"`
2415-
GitCommitsURL string `json:"git_commits_url"`
2416-
CommentsURL string `json:"comments_url"`
2417-
IssueCommentURL string `json:"issue_comment_url"`
2418-
ContentsURL string `json:"contents_url"`
2419-
CompareURL string `json:"compare_url"`
2420-
MergesURL string `json:"merges_url"`
2421-
ArchiveURL string `json:"archive_url"`
2422-
DownloadsURL string `json:"downloads_url"`
2423-
IssuesURL string `json:"issues_url"`
2424-
PullsURL string `json:"pulls_url"`
2425-
MilestonesURL string `json:"milestones_url"`
2426-
NotificationsURL string `json:"notifications_url"`
2427-
LabelsURL string `json:"labels_url"`
2428-
ReleasesURL string `json:"releases_url"`
2429-
CreatedAt int64 `json:"created_at"`
2430-
UpdatedAt time.Time `json:"updated_at"`
2431-
PushedAt int64 `json:"pushed_at"`
2432-
GitURL string `json:"git_url"`
2433-
SSHURL string `json:"ssh_url"`
2434-
CloneURL string `json:"clone_url"`
2435-
SvnURL string `json:"svn_url"`
2436-
Homepage *string `json:"homepage"`
2437-
Size int64 `json:"size"`
2438-
StargazersCount int64 `json:"stargazers_count"`
2439-
WatchersCount int64 `json:"watchers_count"`
2440-
Language *string `json:"language"`
2441-
HasIssues bool `json:"has_issues"`
2442-
HasDownloads bool `json:"has_downloads"`
2443-
HasWiki bool `json:"has_wiki"`
2444-
HasPages bool `json:"has_pages"`
2445-
ForksCount int64 `json:"forks_count"`
2446-
MirrorURL *string `json:"mirror_url"`
2447-
OpenIssuesCount int64 `json:"open_issues_count"`
2448-
Forks int64 `json:"forks"`
2449-
OpenIssues int64 `json:"open_issues"`
2450-
Watchers int64 `json:"watchers"`
2451-
DefaultBranch string `json:"default_branch"`
2452-
Stargazers int64 `json:"stargazers"`
2453-
MasterBranch string `json:"master_branch"`
2454-
} `json:"repository"`
2455-
Pusher struct {
2334+
Ref string `json:"ref"`
2335+
Before string `json:"before"`
2336+
After string `json:"after"`
2337+
Created bool `json:"created"`
2338+
Deleted bool `json:"deleted"`
2339+
Forced bool `json:"forced"`
2340+
BaseRef *string `json:"base_ref"`
2341+
Compare string `json:"compare"`
2342+
Commits []*Commit `json:"commits"`
2343+
HeadCommit *Commit `json:"head_commit"`
2344+
//TODO: the repository object for this payload is slightly different
2345+
//should we ignore or create a separate type?
2346+
//diff:
2347+
// +@ ["repository","master_branch"]
2348+
// +- "master"
2349+
// +@ ["repository","owner","email"]
2350+
// +- "21031067+Codertocat@users.noreply.github.com"
2351+
// +@ ["repository","owner","name"]
2352+
// +- "Codertocat"
2353+
// +@ ["repository","stargazers"]
2354+
// +- 0
2355+
Repository Repository `json:"repository"`
2356+
Pusher struct {
24562357
Name string `json:"name"`
24572358
Email string `json:"email"`
24582359
} `json:"pusher"`
@@ -2476,9 +2377,7 @@ type PushPayload struct {
24762377
Type string `json:"type"`
24772378
SiteAdmin bool `json:"site_admin"`
24782379
} `json:"sender"`
2479-
Installation struct {
2480-
ID int `json:"id"`
2481-
} `json:"installation"`
2380+
Installation Installation `json:"installation"`
24822381
}
24832382

24842383
// ReleasePayload contains the information for GitHub's release hook event

github/payload_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,16 @@ func TestPayloads(t *testing.T) {
169169
filename: "pull-request.json",
170170
typ: &PullRequestPayload{},
171171
},
172-
// {
173-
// name: "PushPayload",
174-
// filename: "push.json",
175-
// typ: &PushPayload{},
176-
// },
177-
// {
178-
// name: "ReleasePayload",
179-
// filename: "release.json",
180-
// typ: &ReleasePayload{},
181-
// },
172+
{
173+
name: "PushPayload",
174+
filename: "push.json",
175+
typ: &PushPayload{},
176+
},
177+
{
178+
name: "ReleasePayload",
179+
filename: "release.json",
180+
typ: &ReleasePayload{},
181+
},
182182
// {
183183
// name: "RepositoryVulnerabilityAlertPayload",
184184
// filename: "repository-vulnerability-alert.json",

tmp/push.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
"full_name": "Codertocat/Hello-World",
1717
"private": false,
1818
"owner": {
19-
"name": "Codertocat",
20-
"email": "21031067+Codertocat@users.noreply.github.com",
2119
"login": "Codertocat",
2220
"id": 21031067,
2321
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
@@ -38,7 +36,7 @@
3836
"site_admin": false
3937
},
4038
"html_url": "https://github.com/Codertocat/Hello-World",
41-
"description": "hellors",
39+
"description": null,
4240
"fork": false,
4341
"url": "https://github.com/Codertocat/Hello-World",
4442
"forks_url": "https://api.github.com/repos/Codertocat/Hello-World/forks",
@@ -77,9 +75,9 @@
7775
"labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}",
7876
"releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}",
7977
"deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments",
80-
"created_at": 1557933565,
78+
"created_at": "2019-05-15T15:20:41Z",
8179
"updated_at": "2019-05-15T15:20:41Z",
82-
"pushed_at": 1557933657,
80+
"pushed_at": "2019-05-15T15:20:41Z",
8381
"git_url": "git://github.com/Codertocat/Hello-World.git",
8482
"ssh_url": "git@github.com:Codertocat/Hello-World.git",
8583
"clone_url": "https://github.com/Codertocat/Hello-World.git",
@@ -103,9 +101,7 @@
103101
"forks": 1,
104102
"open_issues": 2,
105103
"watchers": 0,
106-
"default_branch": "master",
107-
"stargazers": 0,
108-
"master_branch": "master"
104+
"default_branch": "master"
109105
},
110106
"pusher": {
111107
"name": "Codertocat",

0 commit comments

Comments
 (0)