Skip to content

Commit 22d5883

Browse files
committed
correctly parse deploy hook for commit
1 parent 7d81093 commit 22d5883

File tree

4 files changed

+206
-0
lines changed

4 files changed

+206
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
{
2+
"deployment": {
3+
"url": "https://api.github.com/repos/Codertocat/Hello-World/deployments/87972451",
4+
"id": 87972451,
5+
"node_id": "MDEwOkRlcGxveW1lbnQ4Nzk3MjQ1MQ==",
6+
"sha": "a10867b14bb761a232cd80139fbd4c0d33264240",
7+
"ref": "a10867b14bb761a232cd80139fbd4c0d33264240",
8+
"task": "deploy",
9+
"payload": {
10+
"foo": "bar"
11+
},
12+
"environment": "production",
13+
"description": "this is a description",
14+
"creator": {
15+
"login": "Codertocat",
16+
"id": 21031067,
17+
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
18+
"avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4",
19+
"gravatar_id": "",
20+
"url": "https://api.github.com/users/Codertocat",
21+
"html_url": "https://github.com/Codertocat",
22+
"followers_url": "https://api.github.com/users/Codertocat/followers",
23+
"following_url": "https://api.github.com/users/Codertocat/following{/other_user}",
24+
"gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}",
25+
"starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}",
26+
"subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions",
27+
"organizations_url": "https://api.github.com/users/Codertocat/orgs",
28+
"repos_url": "https://api.github.com/users/Codertocat/repos",
29+
"events_url": "https://api.github.com/users/Codertocat/events{/privacy}",
30+
"received_events_url": "https://api.github.com/users/Codertocat/received_events",
31+
"type": "User",
32+
"site_admin": false
33+
},
34+
"created_at": "2018-05-30T20:18:45Z",
35+
"updated_at": "2018-05-30T20:18:45Z",
36+
"statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments/87972451/statuses",
37+
"repository_url": "https://api.github.com/repos/Codertocat/Hello-World"
38+
},
39+
"repository": {
40+
"id": 135493233,
41+
"node_id": "MDEwOlJlcG9zaXRvcnkxMzU0OTMyMzM=",
42+
"name": "Hello-World",
43+
"full_name": "Codertocat/Hello-World",
44+
"owner": {
45+
"login": "Codertocat",
46+
"id": 21031067,
47+
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
48+
"avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4",
49+
"gravatar_id": "",
50+
"url": "https://api.github.com/users/Codertocat",
51+
"html_url": "https://github.com/Codertocat",
52+
"followers_url": "https://api.github.com/users/Codertocat/followers",
53+
"following_url": "https://api.github.com/users/Codertocat/following{/other_user}",
54+
"gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}",
55+
"starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}",
56+
"subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions",
57+
"organizations_url": "https://api.github.com/users/Codertocat/orgs",
58+
"repos_url": "https://api.github.com/users/Codertocat/repos",
59+
"events_url": "https://api.github.com/users/Codertocat/events{/privacy}",
60+
"received_events_url": "https://api.github.com/users/Codertocat/received_events",
61+
"type": "User",
62+
"site_admin": false
63+
},
64+
"private": false,
65+
"html_url": "https://github.com/Codertocat/Hello-World",
66+
"description": null,
67+
"fork": false,
68+
"url": "https://api.github.com/repos/Codertocat/Hello-World",
69+
"forks_url": "https://api.github.com/repos/Codertocat/Hello-World/forks",
70+
"keys_url": "https://api.github.com/repos/Codertocat/Hello-World/keys{/key_id}",
71+
"collaborators_url": "https://api.github.com/repos/Codertocat/Hello-World/collaborators{/collaborator}",
72+
"teams_url": "https://api.github.com/repos/Codertocat/Hello-World/teams",
73+
"hooks_url": "https://api.github.com/repos/Codertocat/Hello-World/hooks",
74+
"issue_events_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/events{/number}",
75+
"events_url": "https://api.github.com/repos/Codertocat/Hello-World/events",
76+
"assignees_url": "https://api.github.com/repos/Codertocat/Hello-World/assignees{/user}",
77+
"branches_url": "https://api.github.com/repos/Codertocat/Hello-World/branches{/branch}",
78+
"tags_url": "https://api.github.com/repos/Codertocat/Hello-World/tags",
79+
"blobs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/blobs{/sha}",
80+
"git_tags_url": "https://api.github.com/repos/Codertocat/Hello-World/git/tags{/sha}",
81+
"git_refs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/refs{/sha}",
82+
"trees_url": "https://api.github.com/repos/Codertocat/Hello-World/git/trees{/sha}",
83+
"statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/statuses/{sha}",
84+
"languages_url": "https://api.github.com/repos/Codertocat/Hello-World/languages",
85+
"stargazers_url": "https://api.github.com/repos/Codertocat/Hello-World/stargazers",
86+
"contributors_url": "https://api.github.com/repos/Codertocat/Hello-World/contributors",
87+
"subscribers_url": "https://api.github.com/repos/Codertocat/Hello-World/subscribers",
88+
"subscription_url": "https://api.github.com/repos/Codertocat/Hello-World/subscription",
89+
"commits_url": "https://api.github.com/repos/Codertocat/Hello-World/commits{/sha}",
90+
"git_commits_url": "https://api.github.com/repos/Codertocat/Hello-World/git/commits{/sha}",
91+
"comments_url": "https://api.github.com/repos/Codertocat/Hello-World/comments{/number}",
92+
"issue_comment_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/comments{/number}",
93+
"contents_url": "https://api.github.com/repos/Codertocat/Hello-World/contents/{+path}",
94+
"compare_url": "https://api.github.com/repos/Codertocat/Hello-World/compare/{base}...{head}",
95+
"merges_url": "https://api.github.com/repos/Codertocat/Hello-World/merges",
96+
"archive_url": "https://api.github.com/repos/Codertocat/Hello-World/{archive_format}{/ref}",
97+
"downloads_url": "https://api.github.com/repos/Codertocat/Hello-World/downloads",
98+
"issues_url": "https://api.github.com/repos/Codertocat/Hello-World/issues{/number}",
99+
"pulls_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls{/number}",
100+
"milestones_url": "https://api.github.com/repos/Codertocat/Hello-World/milestones{/number}",
101+
"notifications_url": "https://api.github.com/repos/Codertocat/Hello-World/notifications{?since,all,participating}",
102+
"labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}",
103+
"releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}",
104+
"deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments",
105+
"created_at": "2018-05-30T20:18:04Z",
106+
"updated_at": "2018-05-30T20:18:35Z",
107+
"pushed_at": "2018-05-30T20:18:44Z",
108+
"git_url": "git://github.com/Codertocat/Hello-World.git",
109+
"ssh_url": "[email protected]:Codertocat/Hello-World.git",
110+
"clone_url": "https://github.com/Codertocat/Hello-World.git",
111+
"svn_url": "https://github.com/Codertocat/Hello-World",
112+
"homepage": null,
113+
"size": 0,
114+
"stargazers_count": 0,
115+
"watchers_count": 0,
116+
"language": null,
117+
"has_issues": true,
118+
"has_projects": true,
119+
"has_downloads": true,
120+
"has_wiki": true,
121+
"has_pages": true,
122+
"forks_count": 0,
123+
"mirror_url": null,
124+
"archived": false,
125+
"open_issues_count": 2,
126+
"license": null,
127+
"forks": 0,
128+
"open_issues": 2,
129+
"watchers": 0,
130+
"default_branch": "master"
131+
},
132+
"sender": {
133+
"login": "Codertocat",
134+
"id": 21031067,
135+
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
136+
"avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4",
137+
"gravatar_id": "",
138+
"url": "https://api.github.com/users/Codertocat",
139+
"html_url": "https://github.com/Codertocat",
140+
"followers_url": "https://api.github.com/users/Codertocat/followers",
141+
"following_url": "https://api.github.com/users/Codertocat/following{/other_user}",
142+
"gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}",
143+
"starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}",
144+
"subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions",
145+
"organizations_url": "https://api.github.com/users/Codertocat/orgs",
146+
"repos_url": "https://api.github.com/users/Codertocat/repos",
147+
"events_url": "https://api.github.com/users/Codertocat/events{/privacy}",
148+
"received_events_url": "https://api.github.com/users/Codertocat/received_events",
149+
"type": "User",
150+
"site_admin": false
151+
}
152+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"Data": {
3+
"foo": "bar"
4+
},
5+
"Desc": "this is a description",
6+
"Number": 87972451,
7+
"Ref": {
8+
"Name": "",
9+
"Path": "",
10+
"Sha": "a10867b14bb761a232cd80139fbd4c0d33264240"
11+
},
12+
"Repo": {
13+
"ID": "135493233",
14+
"Namespace": "Codertocat",
15+
"Name": "Hello-World",
16+
"Perm": null,
17+
"Branch": "master",
18+
"Private": false,
19+
"Clone": "https://github.com/Codertocat/Hello-World.git",
20+
"CloneSSH": "[email protected]:Codertocat/Hello-World.git",
21+
"Link": "https://github.com/Codertocat/Hello-World",
22+
"Created": "0001-01-01T00:00:00Z",
23+
"Updated": "0001-01-01T00:00:00Z"
24+
},
25+
"Sender": {
26+
"Login": "Codertocat",
27+
"Name": "",
28+
"Email": "",
29+
"Avatar": "https://avatars1.githubusercontent.com/u/21031067?v=4",
30+
"Created": "0001-01-01T00:00:00Z",
31+
"Updated": "0001-01-01T00:00:00Z"
32+
},
33+
"Target": "production",
34+
"TargetURL": "",
35+
"Task": "deploy"
36+
}

scm/driver/github/webhook.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,14 @@ func convertDeploymentHook(src *deploymentHook) *scm.DeployHook {
383383
Target: src.Deployment.Environment.String,
384384
TargetURL: src.Deployment.EnvironmentURL.String,
385385
}
386+
// handle deployment events for commits which
387+
// use a different payload structure and lack
388+
// branch or reference details.
389+
if len(dst.Ref.Name) == 40 && dst.Ref.Name == dst.Ref.Sha {
390+
dst.Ref.Name = ""
391+
dst.Ref.Path = ""
392+
return dst
393+
}
386394
if tagRE.MatchString(dst.Ref.Name) {
387395
dst.Ref.Path = scm.ExpandRef(dst.Ref.Path, "refs/tags/")
388396
} else {

scm/driver/github/webhook_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,23 @@ func TestWebhooks(t *testing.T) {
156156
after: "testdata/webhooks/pr_unlabeled.json.golden",
157157
obj: new(scm.PullRequestHook),
158158
},
159+
160+
//
159161
// deployment
162+
//
163+
160164
{
161165
event: "deployment",
162166
before: "testdata/webhooks/deployment.json",
163167
after: "testdata/webhooks/deployment.json.golden",
164168
obj: new(scm.DeployHook),
165169
},
170+
{
171+
event: "deployment",
172+
before: "testdata/webhooks/deployment_commit.json",
173+
after: "testdata/webhooks/deployment_commit.json.golden",
174+
obj: new(scm.DeployHook),
175+
},
166176
}
167177

168178
for _, test := range tests {

0 commit comments

Comments
 (0)