Skip to content

Commit a920656

Browse files
authored
Merge pull request #137 from ptu/github-deploy-key-event
Added GitHub deploy_key Event
2 parents 06301b5 + 2e6b493 commit a920656

File tree

4 files changed

+267
-0
lines changed

4 files changed

+267
-0
lines changed

Diff for: github/github.go

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const (
3333
CommitCommentEvent Event = "commit_comment"
3434
CreateEvent Event = "create"
3535
DeleteEvent Event = "delete"
36+
DeployKeyEvent Event = "deploy_key"
3637
DeploymentEvent Event = "deployment"
3738
DeploymentStatusEvent Event = "deployment_status"
3839
ForkEvent Event = "fork"
@@ -184,6 +185,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
184185
var pl CreatePayload
185186
err = json.Unmarshal([]byte(payload), &pl)
186187
return pl, err
188+
case DeployKeyEvent:
189+
var pl DeployKeyPayload
190+
err = json.Unmarshal([]byte(payload), &pl)
191+
return pl, err
187192
case DeleteEvent:
188193
var pl DeletePayload
189194
err = json.Unmarshal([]byte(payload), &pl)

Diff for: github/github_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@ func TestWebhooks(t *testing.T) {
183183
"X-Hub-Signature": []string{"sha1=4ddef04fd05b504c7041e294fca3ad1804bc7be1"},
184184
},
185185
},
186+
{
187+
name: "DeployKeyEvent",
188+
event: DeployKeyEvent,
189+
typ: DeployKeyPayload{},
190+
filename: "../testdata/github/deploy_key.json",
191+
headers: http.Header{
192+
"X-Github-Event": []string{"deploy_key"},
193+
"X-Hub-Signature": []string{"sha1=dc9eea5621f5942542c94443cd2b71c8d7526168"},
194+
},
195+
},
186196
{
187197
name: "DeploymentEvent",
188198
event: DeploymentEvent,

Diff for: github/payload.go

+127
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,133 @@ type DeletePayload struct {
769769
} `json:"sender"`
770770
}
771771

772+
// DeployKeyPayload contains the information for GitHub's deploy_key hook
773+
type DeployKeyPayload struct {
774+
Action string `json:"action"`
775+
Key struct {
776+
ID int `json:"id"`
777+
Key string `json:"key"`
778+
URL string `json:"url"`
779+
Title string `json:"title"`
780+
Verified bool `json:"verified"`
781+
CreatedAt time.Time `json:"created_at"`
782+
ReadOnly bool `json:"read_only"`
783+
} `json:"key"`
784+
Repository struct {
785+
ID int `json:"id"`
786+
NodeID string `json:"node_id"`
787+
Name string `json:"name"`
788+
FullName string `json:"full_name"`
789+
Owner struct {
790+
Login string `json:"login"`
791+
ID int `json:"id"`
792+
NodeID string `json:"node_id"`
793+
AvatarURL string `json:"avatar_url"`
794+
GravatarID string `json:"gravatar_id"`
795+
URL string `json:"url"`
796+
HTMLURL string `json:"html_url"`
797+
FollowersURL string `json:"followers_url"`
798+
FollowingURL string `json:"following_url"`
799+
GistsURL string `json:"gists_url"`
800+
StarredURL string `json:"starred_url"`
801+
SubscriptionsURL string `json:"subscriptions_url"`
802+
OrganizationsURL string `json:"organizations_url"`
803+
ReposURL string `json:"repos_url"`
804+
EventsURL string `json:"events_url"`
805+
ReceivedEventsURL string `json:"received_events_url"`
806+
Type string `json:"type"`
807+
SiteAdmin bool `json:"site_admin"`
808+
} `json:"owner"`
809+
Private bool `json:"private"`
810+
HTMLURL string `json:"html_url"`
811+
Description interface{} `json:"description"`
812+
Fork bool `json:"fork"`
813+
URL string `json:"url"`
814+
ForksURL string `json:"forks_url"`
815+
KeysURL string `json:"keys_url"`
816+
CollaboratorsURL string `json:"collaborators_url"`
817+
TeamsURL string `json:"teams_url"`
818+
HooksURL string `json:"hooks_url"`
819+
IssueEventsURL string `json:"issue_events_url"`
820+
EventsURL string `json:"events_url"`
821+
AssigneesURL string `json:"assignees_url"`
822+
BranchesURL string `json:"branches_url"`
823+
TagsURL string `json:"tags_url"`
824+
BlobsURL string `json:"blobs_url"`
825+
GitTagsURL string `json:"git_tags_url"`
826+
GitRefsURL string `json:"git_refs_url"`
827+
TreesURL string `json:"trees_url"`
828+
StatusesURL string `json:"statuses_url"`
829+
LanguagesURL string `json:"languages_url"`
830+
StargazersURL string `json:"stargazers_url"`
831+
ContributorsURL string `json:"contributors_url"`
832+
SubscribersURL string `json:"subscribers_url"`
833+
SubscriptionURL string `json:"subscription_url"`
834+
CommitsURL string `json:"commits_url"`
835+
GitCommitsURL string `json:"git_commits_url"`
836+
CommentsURL string `json:"comments_url"`
837+
IssueCommentURL string `json:"issue_comment_url"`
838+
ContentsURL string `json:"contents_url"`
839+
CompareURL string `json:"compare_url"`
840+
MergesURL string `json:"merges_url"`
841+
ArchiveURL string `json:"archive_url"`
842+
DownloadsURL string `json:"downloads_url"`
843+
IssuesURL string `json:"issues_url"`
844+
PullsURL string `json:"pulls_url"`
845+
MilestonesURL string `json:"milestones_url"`
846+
NotificationsURL string `json:"notifications_url"`
847+
LabelsURL string `json:"labels_url"`
848+
ReleasesURL string `json:"releases_url"`
849+
DeploymentsURL string `json:"deployments_url"`
850+
CreatedAt time.Time `json:"created_at"`
851+
UpdatedAt time.Time `json:"updated_at"`
852+
PushedAt time.Time `json:"pushed_at"`
853+
GitURL string `json:"git_url"`
854+
SSHURL string `json:"ssh_url"`
855+
CloneURL string `json:"clone_url"`
856+
SvnURL string `json:"svn_url"`
857+
Homepage interface{} `json:"homepage"`
858+
Size int `json:"size"`
859+
StargazersCount int `json:"stargazers_count"`
860+
WatchersCount int `json:"watchers_count"`
861+
Language interface{} `json:"language"`
862+
HasIssues bool `json:"has_issues"`
863+
HasProjects bool `json:"has_projects"`
864+
HasDownloads bool `json:"has_downloads"`
865+
HasWiki bool `json:"has_wiki"`
866+
HasPages bool `json:"has_pages"`
867+
ForksCount int `json:"forks_count"`
868+
MirrorURL interface{} `json:"mirror_url"`
869+
Archived bool `json:"archived"`
870+
OpenIssuesCount int `json:"open_issues_count"`
871+
License interface{} `json:"license"`
872+
Forks int `json:"forks"`
873+
OpenIssues int `json:"open_issues"`
874+
Watchers int `json:"watchers"`
875+
DefaultBranch string `json:"default_branch"`
876+
} `json:"repository"`
877+
Sender struct {
878+
Login string `json:"login"`
879+
ID int `json:"id"`
880+
NodeID string `json:"node_id"`
881+
AvatarURL string `json:"avatar_url"`
882+
GravatarID string `json:"gravatar_id"`
883+
URL string `json:"url"`
884+
HTMLURL string `json:"html_url"`
885+
FollowersURL string `json:"followers_url"`
886+
FollowingURL string `json:"following_url"`
887+
GistsURL string `json:"gists_url"`
888+
StarredURL string `json:"starred_url"`
889+
SubscriptionsURL string `json:"subscriptions_url"`
890+
OrganizationsURL string `json:"organizations_url"`
891+
ReposURL string `json:"repos_url"`
892+
EventsURL string `json:"events_url"`
893+
ReceivedEventsURL string `json:"received_events_url"`
894+
Type string `json:"type"`
895+
SiteAdmin bool `json:"site_admin"`
896+
} `json:"sender"`
897+
}
898+
772899
// DeploymentPayload contains the information for GitHub's deployment hook
773900
type DeploymentPayload struct {
774901
Deployment struct {

Diff for: testdata/github/deploy_key.json

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
{
2+
"action": "created",
3+
"key": {
4+
"id": 100,
5+
"key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQConScVc7ouWWgwcjneNnJ4PScDkkwEjuDL5leLIUU5aIg13dH55/f4aqKUSvfcLUOKJ0a8073tFqMbR9rfvLAhLGeStKxmYApJXpzVkphauu7kfNW8kQNi1fI4kmHyOpQ+dKtoonzjZAT4L9AV3FlVTOfRq3U8wJ2RPwU+4EtOpMKUF+wcoDJ5ONlKBOW6uAeBt/guBiu6r3awDClDGRo4Q2YCmMceiAyoiuXcr2mFNSyzTqU1f20fftFwucV/VqnxlJjZvZ/zhlfB+v+UgQN11pJJ5vChZ7bzyRtIRRsjxbTReyWxqVZ5hEle5sm1oAR97abW9zTWfwIABgClKo+z",
6+
"url": "https://api.github.com/repos/Codertocat/Hello-World/keys/100",
7+
"title": "hey-its-a-deploy-key",
8+
"verified": true,
9+
"created_at": "2019-04-02T17:37:07Z",
10+
"read_only": true
11+
},
12+
"repository": {
13+
"id": 135493233,
14+
"node_id": "MDEwOlJlcG9zaXRvcnkxMzU0OTMyMzM=",
15+
"name": "Hello-World",
16+
"full_name": "Codertocat/Hello-World",
17+
"owner": {
18+
"login": "Codertocat",
19+
"id": 21031067,
20+
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
21+
"avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4",
22+
"gravatar_id": "",
23+
"url": "https://api.github.com/users/Codertocat",
24+
"html_url": "https://github.com/Codertocat",
25+
"followers_url": "https://api.github.com/users/Codertocat/followers",
26+
"following_url": "https://api.github.com/users/Codertocat/following{/other_user}",
27+
"gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}",
28+
"starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}",
29+
"subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions",
30+
"organizations_url": "https://api.github.com/users/Codertocat/orgs",
31+
"repos_url": "https://api.github.com/users/Codertocat/repos",
32+
"events_url": "https://api.github.com/users/Codertocat/events{/privacy}",
33+
"received_events_url": "https://api.github.com/users/Codertocat/received_events",
34+
"type": "User",
35+
"site_admin": false
36+
},
37+
"private": false,
38+
"html_url": "https://github.com/Codertocat/Hello-World",
39+
"description": null,
40+
"fork": false,
41+
"url": "https://api.github.com/repos/Codertocat/Hello-World",
42+
"forks_url": "https://api.github.com/repos/Codertocat/Hello-World/forks",
43+
"keys_url": "https://api.github.com/repos/Codertocat/Hello-World/keys{/key_id}",
44+
"collaborators_url": "https://api.github.com/repos/Codertocat/Hello-World/collaborators{/collaborator}",
45+
"teams_url": "https://api.github.com/repos/Codertocat/Hello-World/teams",
46+
"hooks_url": "https://api.github.com/repos/Codertocat/Hello-World/hooks",
47+
"issue_events_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/events{/number}",
48+
"events_url": "https://api.github.com/repos/Codertocat/Hello-World/events",
49+
"assignees_url": "https://api.github.com/repos/Codertocat/Hello-World/assignees{/user}",
50+
"branches_url": "https://api.github.com/repos/Codertocat/Hello-World/branches{/branch}",
51+
"tags_url": "https://api.github.com/repos/Codertocat/Hello-World/tags",
52+
"blobs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/blobs{/sha}",
53+
"git_tags_url": "https://api.github.com/repos/Codertocat/Hello-World/git/tags{/sha}",
54+
"git_refs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/refs{/sha}",
55+
"trees_url": "https://api.github.com/repos/Codertocat/Hello-World/git/trees{/sha}",
56+
"statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/statuses/{sha}",
57+
"languages_url": "https://api.github.com/repos/Codertocat/Hello-World/languages",
58+
"stargazers_url": "https://api.github.com/repos/Codertocat/Hello-World/stargazers",
59+
"contributors_url": "https://api.github.com/repos/Codertocat/Hello-World/contributors",
60+
"subscribers_url": "https://api.github.com/repos/Codertocat/Hello-World/subscribers",
61+
"subscription_url": "https://api.github.com/repos/Codertocat/Hello-World/subscription",
62+
"commits_url": "https://api.github.com/repos/Codertocat/Hello-World/commits{/sha}",
63+
"git_commits_url": "https://api.github.com/repos/Codertocat/Hello-World/git/commits{/sha}",
64+
"comments_url": "https://api.github.com/repos/Codertocat/Hello-World/comments{/number}",
65+
"issue_comment_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/comments{/number}",
66+
"contents_url": "https://api.github.com/repos/Codertocat/Hello-World/contents/{+path}",
67+
"compare_url": "https://api.github.com/repos/Codertocat/Hello-World/compare/{base}...{head}",
68+
"merges_url": "https://api.github.com/repos/Codertocat/Hello-World/merges",
69+
"archive_url": "https://api.github.com/repos/Codertocat/Hello-World/{archive_format}{/ref}",
70+
"downloads_url": "https://api.github.com/repos/Codertocat/Hello-World/downloads",
71+
"issues_url": "https://api.github.com/repos/Codertocat/Hello-World/issues{/number}",
72+
"pulls_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls{/number}",
73+
"milestones_url": "https://api.github.com/repos/Codertocat/Hello-World/milestones{/number}",
74+
"notifications_url": "https://api.github.com/repos/Codertocat/Hello-World/notifications{?since,all,participating}",
75+
"labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}",
76+
"releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}",
77+
"deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments",
78+
"created_at": "2018-05-30T20:18:04Z",
79+
"updated_at": "2018-05-30T20:18:50Z",
80+
"pushed_at": "2018-05-30T20:18:48Z",
81+
"git_url": "git://github.com/Codertocat/Hello-World.git",
82+
"ssh_url": "[email protected]:Codertocat/Hello-World.git",
83+
"clone_url": "https://github.com/Codertocat/Hello-World.git",
84+
"svn_url": "https://github.com/Codertocat/Hello-World",
85+
"homepage": null,
86+
"size": 0,
87+
"stargazers_count": 0,
88+
"watchers_count": 0,
89+
"language": null,
90+
"has_issues": true,
91+
"has_projects": true,
92+
"has_downloads": true,
93+
"has_wiki": true,
94+
"has_pages": true,
95+
"forks_count": 0,
96+
"mirror_url": null,
97+
"archived": false,
98+
"open_issues_count": 1,
99+
"license": null,
100+
"forks": 0,
101+
"open_issues": 1,
102+
"watchers": 0,
103+
"default_branch": "master"
104+
},
105+
"sender": {
106+
"login": "Codertocat",
107+
"id": 21031067,
108+
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
109+
"avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4",
110+
"gravatar_id": "",
111+
"url": "https://api.github.com/users/Codertocat",
112+
"html_url": "https://github.com/Codertocat",
113+
"followers_url": "https://api.github.com/users/Codertocat/followers",
114+
"following_url": "https://api.github.com/users/Codertocat/following{/other_user}",
115+
"gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}",
116+
"starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}",
117+
"subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions",
118+
"organizations_url": "https://api.github.com/users/Codertocat/orgs",
119+
"repos_url": "https://api.github.com/users/Codertocat/repos",
120+
"events_url": "https://api.github.com/users/Codertocat/events{/privacy}",
121+
"received_events_url": "https://api.github.com/users/Codertocat/received_events",
122+
"type": "User",
123+
"site_admin": false
124+
}
125+
}

0 commit comments

Comments
 (0)