/
bitbucket.py
59 lines (49 loc) · 2.12 KB
/
bitbucket.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members
# Copyright 2013 (c) Mamba Team
try:
import json
assert json
except ImportError:
import simplejson as json
from dateutil.parser import parse as dateparse
from twisted.python import log
def getChanges(request, options=None):
"""Catch a POST request from BitBucket and start a build process
Check the URL below if you require more information about payload
https://confluence.atlassian.com/display/BITBUCKET/POST+Service+Management
:param request: the http request Twisted object
:param options: additional options
"""
payload = json.loads(request.args['payload'][0])
repo_url = '%s%s' % (
payload['canon_url'], payload['repository']['absolute_url'])
project = request.args.get('project', [''])[0]
changes = []
for commit in payload['commits']:
changes.append({
'author': commit['raw_author'],
'files': [f['file'] for f in commit['files']],
'comments': commit['message'],
'revision': commit['raw_node'],
'when_timestamp': dateparse(commit['utctimestamp']),
'branch': commit['branch'],
'revlink': '%scommits/%s' % (repo_url, commit['raw_node']),
'repository': repo_url,
'project': project
})
log.msg('New revision: %s' % (commit['node'],))
log.msg('Received %s changes from bitbucket' % (len(changes),))
return (changes, payload['repository']['scm'])