Skip to content

Commit

Permalink
fix BitbucketPullrequestPoller issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zapster committed Feb 12, 2014
1 parent 07d06fc commit 2029075
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
23 changes: 9 additions & 14 deletions master/buildbot/changes/bitbucket.py
Expand Up @@ -26,19 +26,17 @@


class BitbucketPullrequestPoller(base.PollingChangeSource):
"""This source will poll a bitbucket repo slug for pull requests and submit
them to the change master."""

compare_attrs = ["owner", "slug", "branch",
"pollInterval", "usetimestamps",
"pollInterval", "useTimestamps",
"category", "project", "pollAtLaunch"]

db_class_name = 'BitbucketPullrequestPoller'

def __init__(self, owner, slug,
branch=None,
pollInterval=10 * 60,
usetimestamps=True,
useTimestamps=True,
category=None,
project='',
pullrequest_filter=True,
Expand All @@ -60,10 +58,9 @@ def __init__(self, owner, slug,

self.lastChange = time.time()
self.lastPoll = time.time()
self.usetimestamps = usetimestamps
self.useTimestamps = useTimestamps
self.category = category
self.project = project
#self.commitInfo = {}
self.initLock = defer.DeferredLock()

def describe(self):
Expand All @@ -86,7 +83,9 @@ def _getChanges(self):

@defer.inlineCallbacks
def _processChanges(self, page):
log.msg(page)
result = json.loads(page, encoding=self.encoding)
log.msg(result)
for pr in result['values']:
branch = pr['source']['branch']['name']
nr = int(pr['id'])
Expand All @@ -113,7 +112,7 @@ def _processChanges(self, page):
author = pr['author']['display_name']
prlink = pr['links']['html']['href']
# Get time updated time. Note that the timezone offset is ignored.
if self.usetimestamps:
if self.useTimestamps:
updated = datetime.strptime(pr['updated_on'][:-6], '%Y-%m-%dT%H:%M:%S.%f')
else:
updated = datetime.now()
Expand All @@ -136,7 +135,6 @@ def _processChanges(self, page):
author=author,
revision=revision,
revlink=revlink,
#files=files,
comments='pull-request #%d: %s\n%s' % (nr, title, prlink),
when_timestamp=updated,
branch=self.branch,
Expand All @@ -153,8 +151,7 @@ def _processChangesFailure(self, f):
return None

def _getCurrentRev(self, pr_id):
"""Return a deferred datetime object for the given pull request number or None.
"""
# Return a deferred datetime object for the given pull request number or None.
d = self._getStateObjectId()

def oid_callback(oid):
Expand All @@ -168,8 +165,7 @@ def result_callback(result):
return d

def _setCurrentRev(self, pr_id, rev):
"""Set the datetime entry for a specifed pull request.
"""
# Set the datetime entry for a specifed pull request.
d = self._getStateObjectId()

def oid_callback(oid):
Expand All @@ -179,7 +175,6 @@ def oid_callback(oid):
return d

def _getStateObjectId(self):
"""Return a deferred for object id in state db.
"""
# Return a deferred for object id in state db.
return self.master.db.state.getObjectId(
'%s/%s#%s' % (self.owner, self.slug, self.branch), self.db_class_name)
2 changes: 1 addition & 1 deletion master/docs/manual/cfg-changesources.rst
Expand Up @@ -1075,7 +1075,7 @@ The :bb:chsrc:`BitbucketPullrequestPoller` accepts the following arguments:
triggering particular builders.

``pullrequest_filter``
A callable which takes one parameter, the JSON notation of the pull request.
A callable which takes one parameter, the decoded Python object of the pull request JSON.
If the it returns ``False`` the pull request is ignored.
It can be used to define custom filters based on the content of the pull request.
See the Bitbucket documentation for more information about the format of the response.
Expand Down

0 comments on commit 2029075

Please sign in to comment.