Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
7a3e5930
Commit
7a3e5930
authored
Jul 09, 2015
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for Bitbucket webhooks.
Fixes #771 Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
ddcbc556
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
119 additions
and
1 deletion
+119
-1
docs/changes.rst
docs/changes.rst
+1
-0
weblate/trans/tests/test_hooks.py
weblate/trans/tests/test_hooks.py
+89
-0
weblate/trans/views/api.py
weblate/trans/views/api.py
+29
-1
No files found.
docs/changes.rst
View file @
7a3e5930
...
...
@@ -11,6 +11,7 @@ Released on ? 2015.
* Improved configurability of import_project command.
* Added CSV dump of history.
* Avoid copy/paste errors with whitespace chars.
* Added support for Bitbucket webhooks.
weblate 2.3
-----------
...
...
weblate/trans/tests/test_hooks.py
View file @
7a3e5930
...
...
@@ -209,6 +209,86 @@ BITBUCKET_PAYLOAD_HG_NO_COMMIT = '''
}
'''
BITBUCKET_PAYLOAD_WEBHOOK
=
r'''
{
"actor": {
"username": "emmap1",
"display_name": "Emma",
"uuid": "{a54f16da-24e9-4d7f-a3a7-b1ba2cd98aa3}",
"links": {
"self": {
"href": "https://api.bitbucket.org/api/2.0/users/emmap1"
},
"html": {
"href": "https://api.bitbucket.org/emmap1"
},
"avatar": {
"href": "https://bitbucket-api-assetroot/emmap1-avatar_avatar.png"
}
}
},
"repository": {
"links": {
"self": {
"href": "https://api.bitbucket.org/api/2.0/repositories/bitbucket/bit"
},
"html": {
"href": "https://api.bitbucket.org/bitbucket/bitbucket"
},
"avatar": {
"href": "https://api-staging-assetroot/2629490769-3_avatar.png"
}
},
"uuid": "{673a6070-3421-46c9-9d48-90745f7bfe8e}",
"full_name": "team_name/repo_name",
"name": "repo_name"
},
"push": {
"changes": [
{
"new": {
"type": "branch",
"name": "name-of-branch",
"target": {
"type": "commit",
"hash": "709d658dc5b6d6afcd46049c2f332ee3f515a67d",
"author": {},
"message": "new commit message\n",
"date": "2015-06-09T03:34:49+00:00",
"parents": [
{
"hash": "1e65c05c1d5171631d92438a13901ca7dae9618c",
"type": "commit"
}
]
}
},
"old": {
"type": "branch",
"name": "name-of-branch",
"target": {
"type": "commit",
"hash": "1e65c05c1d5171631d92438a13901ca7dae9618c",
"author": {},
"message": "old commit message\n",
"date": "2015-06-08T21:34:56+00:00",
"parents": [
{
"hash": "e0d0c2041e09746be5ce4b55067d5a8e3098c843",
"type": "commit"
}
]
}
},
"created": false,
"forced": false,
"closed": false
}
]
}
}
'''
class
HooksViewTest
(
ViewTestCase
):
@
OverrideSettings
(
ENABLE_HOOKS
=
True
)
...
...
@@ -277,6 +357,15 @@ class HooksViewTest(ViewTestCase):
)
self
.
assertContains
(
response
,
'update triggered'
)
@
OverrideSettings
(
ENABLE_HOOKS
=
True
)
@
OverrideSettings
(
BACKGROUND_HOOKS
=
False
)
def
test_view_hook_bitbucket_webhook
(
self
):
response
=
self
.
client
.
post
(
reverse
(
'hook-bitbucket'
),
{
'payload'
:
BITBUCKET_PAYLOAD_WEBHOOK
}
)
self
.
assertContains
(
response
,
'update triggered'
)
@
OverrideSettings
(
ENABLE_HOOKS
=
False
)
def
test_disabled
(
self
):
'''
...
...
weblate/trans/views/api.py
View file @
7a3e5930
...
...
@@ -47,6 +47,16 @@ BITBUCKET_HG_REPOS = (
'hg::https://bitbucket.org/%(owner)s/%(slug)s'
,
)
BITBUCKET_REPOS
=
(
'ssh://git@bitbucket.org/%(full_name)s.git'
,
'git@bitbucket.org:%(full_name)s.git'
,
'https://bitbucket.org/%(full_name)s.git'
,
'https://bitbucket.org/%(full_name)s'
,
'ssh://hg@bitbucket.org/%(full_name)s'
,
'hg::ssh://hg@bitbucket.org/%(full_name)s'
,
'hg::https://bitbucket.org/%(full_name)s'
,
)
GITHUB_REPOS
=
(
'git://github.com/%(owner)s/%(slug)s.git'
,
'https://github.com/%(owner)s/%(slug)s.git'
,
...
...
@@ -144,6 +154,7 @@ def vcs_service_hook(request, service):
try
:
service_data
=
hook_helper
(
data
)
except
KeyError
:
weblate
.
logger
.
error
(
'failed to parse service %s data'
,
service
)
return
HttpResponseBadRequest
(
'Invalid data in json payload!'
)
# Log data
...
...
@@ -175,11 +186,28 @@ def vcs_service_hook(request, service):
return
HttpResponse
(
'update triggered'
)
def
bitbucket_webhook_helper
(
data
):
"""API to handle webhooks from Bitbucket"""
repos
=
[
repo
%
{
'full_name'
:
data
[
'repository'
][
'full_name'
]}
for
repo
in
BITBUCKET_REPOS
]
return
{
'service_long_name'
:
'Bitbucket'
,
'repos'
:
repos
,
'branch'
:
data
[
'push'
][
'changes'
][
-
1
][
'new'
][
'name'
]
}
@
register_hook
def
bitbucket_hook_helper
(
data
):
'''
API to handle
commit
hooks from Bitbucket.
API to handle
service
hooks from Bitbucket.
'''
if
'push'
in
data
:
return
bitbucket_webhook_helper
(
data
)
# Parse owner, branch and repository name
owner
=
data
[
'repository'
][
'owner'
]
slug
=
data
[
'repository'
][
'slug'
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment