Skip to content

Commit ca9e5dc

Browse files
committed
Added support for Bitbucket Server “Post-Receive WebHooks” and “Post Webhooks for Bitbucket”.
1 parent 16d0cbd commit ca9e5dc

4 files changed

+326
-1
lines changed

docs/Configuration.md

+49
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,55 @@ Execute script upon GitLab CI successful build of `master` branch.
277277
}
278278
```
279279

280+
#### Bitbucket Server
281+
282+
Get source using SSH.
283+
284+
```json
285+
{
286+
"host": "0.0.0.0",
287+
"port": 8080,
288+
"global_deploy": [
289+
"echo Pre-deploy script",
290+
"echo Post-deploy script"
291+
],
292+
"repositories": [
293+
{
294+
"url": "ssh://[email protected]/KEY/Git-Auto-Deploy.git",
295+
"match-url": "Git-Auto-Deploy",
296+
"branch": "master",
297+
"remote": "origin",
298+
"path": "~/repositories/Git-Auto-Deploy",
299+
"deploy": "echo deploying"
300+
}
301+
]
302+
}
303+
```
304+
305+
Using HTTPS.
306+
307+
```json
308+
{
309+
"host": "0.0.0.0",
310+
"port": 8080,
311+
"global_deploy": [
312+
"echo Pre-deploy script",
313+
"echo Post-deploy script"
314+
],
315+
"repositories": [
316+
{
317+
"url": "https://bitbucket.example.com/scm/KEY/Git-Auto-Deploy.git",
318+
"match-url": "Git-Auto-Deploy",
319+
"branch": "master",
320+
"remote": "origin",
321+
"path": "~/repositories/Git-Auto-Deploy",
322+
"deploy": "echo deploying"
323+
}
324+
]
325+
}
326+
```
327+
```
328+
280329
# Repository configuration using environment variables
281330

282331
It's possible to configure up to one repository using environment variables. This can be useful in some specific use cases where a full config file is undesired.

gitautodeploy/parsers/bitbucket.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,17 @@ def get_matching_projects(self, request_headers, request_body, action):
2828
# needed since the configured repositories might be configured using a different username.
2929
repo_urls.append('https://bitbucket.org/%s.git' % (data['repository']['full_name']))
3030

31+
if 'fullName' in data['repository']:
32+
# For Bitbucket Server add repository name (OWNER/REPO_NAME).
33+
# Support "Post Webhooks for Bitbucket".
34+
repo_urls.append(data['repository']['fullName'])
35+
36+
if 'slug' in data['repository']:
37+
# For Bitbucket Server add repository slug.
38+
# Support "Post-Receive WebHooks" and "Post Webhooks for Bitbucket".
39+
repo_urls.append(data['repository']['slug'])
40+
3141
# Get a list of configured repositories that matches the incoming web hook reqeust
3242
repo_configs = self.get_matching_repo_configs(repo_urls, action)
3343

34-
return repo_configs
44+
return repo_configs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
{
2+
"config": {
3+
"branch": "master",
4+
"deploy": "echo test!",
5+
"remote": "origin",
6+
"url": "https://bitbucket.example.com/scm/PROJ_KEY/test-hook.git",
7+
"match-url": "PROJ_KEY/test-hook",
8+
"header-filter": {
9+
"x-event-key": "pullrequest:merged"
10+
}
11+
},
12+
"expected": {
13+
"status": 200,
14+
"data": []
15+
},
16+
"headers": {
17+
"accept": "*/*",
18+
"accept-encoding": "gzip, deflate",
19+
"connection": "keep-alive",
20+
"content-length": "4248",
21+
"content-type": "application/json",
22+
"host": "narpau.se:8001",
23+
"user-agent": "Bitbucket-Webhooks/2.0",
24+
"x-attempt-number": "1",
25+
"x-event-key": "pullrequest:created",
26+
"x-hook-uuid": "1f813038-7b26-4d08-9b80-ee76eeb53d93",
27+
"x-request-uuid": "2e6626d9-effe-46f7-8bfd-e9dee9a58920"
28+
},
29+
"payload": {
30+
"actor": {
31+
"username": "username",
32+
"displayName": "User Name"
33+
},
34+
"pullrequest": {
35+
"id": "1",
36+
"title": "Pull request title",
37+
"link": "https://bitbucket.example.com/projects/PROJ_KEY/repos/test-hook/pull-requests/1",
38+
"authorLogin": "User Name",
39+
"fromRef": {
40+
"repository": {
41+
"scmId": "git",
42+
"project": {
43+
"key": "PROJ_KEY",
44+
"name": "Project Key"
45+
},
46+
"slug": "test-hook",
47+
"links": {
48+
"self": [
49+
{
50+
"href": "https://bitbucket.example.com/projects/PROJ_KEY/repos/test-hook/browse"
51+
}
52+
]
53+
},
54+
"public": false,
55+
"owner": {
56+
"username": "PROJ_KEY",
57+
"displayName": "PROJ_KEY"
58+
},
59+
"fullName": "PROJ_KEY/test-hook",
60+
"ownerName": "PROJ_KEY"
61+
},
62+
"branch": {
63+
"name": "test",
64+
"rawNode": "4f430da32d7bea2ea13fb8e564267758bce84801"
65+
},
66+
"commit": {
67+
"message": null,
68+
"date": null,
69+
"hash": "4f430da32d7bea2ea13fb8e564267758bce84801",
70+
"authorTimestamp": 0
71+
}
72+
},
73+
"toRef": {
74+
"repository": {
75+
"scmId": "git",
76+
"project": {
77+
"key": "PROJ_KEY",
78+
"name": "Project Key"
79+
},
80+
"slug": "test-hook",
81+
"links": {
82+
"self": [
83+
{
84+
"href": "https://bitbucket.example.com/projects/PROJ_KEY/repos/test-hook/browse"
85+
}
86+
]
87+
},
88+
"public": false,
89+
"owner": {
90+
"username": "PROJ_KEY",
91+
"displayName": "PROJ_KEY"
92+
},
93+
"fullName": "PROJ_KEY/test-hook",
94+
"ownerName": "PROJ_KEY"
95+
},
96+
"branch": {
97+
"name": "develop",
98+
"rawNode": "82f42b549b35a42626df183003f84db6d896209d"
99+
},
100+
"commit": {
101+
"message": null,
102+
"date": null,
103+
"hash": "82f42b549b35a42626df183003f84db6d896209d",
104+
"authorTimestamp": 0
105+
}
106+
}
107+
},
108+
"repository": {
109+
"scmId": "git",
110+
"project": {
111+
"key": "PROJ_KEY",
112+
"name": "Project Key"
113+
},
114+
"slug": "test-hook",
115+
"links": {
116+
"self": [
117+
{
118+
"href": "https://bitbucket.example.com/projects/PROJ_KEY/repos/test-hook/browse"
119+
}
120+
]
121+
},
122+
"public": false,
123+
"owner": {
124+
"username": "PROJ_KEY",
125+
"displayName": "PROJ_KEY"
126+
},
127+
"fullName": "PROJ_KEY/test-hook",
128+
"ownerName": "PROJ_KEY"
129+
}
130+
}
131+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
"config": {
3+
"branch": "master",
4+
"deploy": "echo test!",
5+
"remote": "origin",
6+
"url": "https://bitbucket.example.com/scm/PROJ_KEY/test-hook.git",
7+
"match-url": "PROJ_KEY/test-hook",
8+
"header-filter": {
9+
"x-event-key": "pullrequest:created"
10+
}
11+
},
12+
"expected": {
13+
"status": 200,
14+
"data": [
15+
{
16+
"deploy": 0
17+
}
18+
]
19+
},
20+
"headers": {
21+
"accept": "*/*",
22+
"accept-encoding": "gzip, deflate",
23+
"connection": "keep-alive",
24+
"content-length": "4248",
25+
"content-type": "application/json",
26+
"host": "narpau.se:8001",
27+
"user-agent": "Bitbucket-Webhooks/2.0",
28+
"x-attempt-number": "1",
29+
"x-event-key": "pullrequest:created",
30+
"x-hook-uuid": "1f813038-7b26-4d08-9b80-ee76eeb53d93",
31+
"x-request-uuid": "2e6626d9-effe-46f7-8bfd-e9dee9a58920"
32+
},
33+
"payload": {
34+
"actor": {
35+
"username": "username",
36+
"displayName": "User Name"
37+
},
38+
"pullrequest": {
39+
"id": "1",
40+
"title": "Pull request title",
41+
"link": "https://bitbucket.example.com/projects/PROJ_KEY/repos/test-hook/pull-requests/1",
42+
"authorLogin": "User Name",
43+
"fromRef": {
44+
"repository": {
45+
"scmId": "git",
46+
"project": {
47+
"key": "PROJ_KEY",
48+
"name": "Project Key"
49+
},
50+
"slug": "test-hook",
51+
"links": {
52+
"self": [
53+
{
54+
"href": "https://bitbucket.example.com/projects/PROJ_KEY/repos/test-hook/browse"
55+
}
56+
]
57+
},
58+
"public": false,
59+
"owner": {
60+
"username": "PROJ_KEY",
61+
"displayName": "PROJ_KEY"
62+
},
63+
"fullName": "PROJ_KEY/test-hook",
64+
"ownerName": "PROJ_KEY"
65+
},
66+
"branch": {
67+
"name": "test",
68+
"rawNode": "4f430da32d7bea2ea13fb8e564267758bce84801"
69+
},
70+
"commit": {
71+
"message": null,
72+
"date": null,
73+
"hash": "4f430da32d7bea2ea13fb8e564267758bce84801",
74+
"authorTimestamp": 0
75+
}
76+
},
77+
"toRef": {
78+
"repository": {
79+
"scmId": "git",
80+
"project": {
81+
"key": "PROJ_KEY",
82+
"name": "Project Key"
83+
},
84+
"slug": "test-hook",
85+
"links": {
86+
"self": [
87+
{
88+
"href": "https://bitbucket.example.com/projects/PROJ_KEY/repos/test-hook/browse"
89+
}
90+
]
91+
},
92+
"public": false,
93+
"owner": {
94+
"username": "PROJ_KEY",
95+
"displayName": "PROJ_KEY"
96+
},
97+
"fullName": "PROJ_KEY/test-hook",
98+
"ownerName": "PROJ_KEY"
99+
},
100+
"branch": {
101+
"name": "develop",
102+
"rawNode": "82f42b549b35a42626df183003f84db6d896209d"
103+
},
104+
"commit": {
105+
"message": null,
106+
"date": null,
107+
"hash": "82f42b549b35a42626df183003f84db6d896209d",
108+
"authorTimestamp": 0
109+
}
110+
}
111+
},
112+
"repository": {
113+
"scmId": "git",
114+
"project": {
115+
"key": "PROJ_KEY",
116+
"name": "Project Key"
117+
},
118+
"slug": "test-hook",
119+
"links": {
120+
"self": [
121+
{
122+
"href": "https://bitbucket.example.com/projects/PROJ_KEY/repos/test-hook/browse"
123+
}
124+
]
125+
},
126+
"public": false,
127+
"owner": {
128+
"username": "PROJ_KEY",
129+
"displayName": "PROJ_KEY"
130+
},
131+
"fullName": "PROJ_KEY/test-hook",
132+
"ownerName": "PROJ_KEY"
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)