Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Unified Diff: scripts/master/gerrit_poller.py

Issue 250983003: Added TryJobGerritScheduler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: nit Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | scripts/master/try_job_gerrit.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/master/gerrit_poller.py
diff --git a/scripts/master/gerrit_poller.py b/scripts/master/gerrit_poller.py
index 57425fd740afd0da300c1fee9e55b9569cbcf26d..7b40849a2711f6bf018a500cc0e78f9cf9712f04 100644
--- a/scripts/master/gerrit_poller.py
+++ b/scripts/master/gerrit_poller.py
@@ -15,6 +15,8 @@ from common.gerrit_agent import GerritAgent
class GerritPoller(base.PollingChangeSource):
"""A poller which queries a gerrit server for new changes and patchsets."""
+ change_category = 'patchset-created'
+
def __init__(self, gerrit_host, gerrit_projects=None, pollInterval=None):
if isinstance(gerrit_projects, basestring):
gerrit_projects = [gerrit_projects]
@@ -34,10 +36,13 @@ class GerritPoller(base.PollingChangeSource):
self.initLastTimeStamp()
base.PollingChangeSource.startService(self)
+ def getChangeQuery(self): # pylint: disable=R0201
+ return 'status:open'
+
@deferredLocked('initLock')
def initLastTimeStamp(self):
log.msg('GerritPoller: Getting latest timestamp from gerrit server.')
- path = '/changes/?q=status:open&n=1'
+ path = '/changes/?q=%s&n=1' % self.getChangeQuery()
d = self.agent.request('GET', path)
def _get_timestamp(j):
if len(j) == 0:
@@ -48,11 +53,14 @@ class GerritPoller(base.PollingChangeSource):
return d
def getChanges(self, sortkey=None):
- path = '/changes/?q=status:open&n=10'
+ path = '/changes/?q=%s&n=10' % self.getChangeQuery()
if sortkey:
path += '&N=%s' % sortkey
return self.agent.request('GET', path)
+ def _is_interesting_message(self, message): # pylint: disable=R0201
+ return message['message'].startswith('Uploaded patch set ')
+
def checkForNewPatchset(self, change, since):
o_params = '&'.join('o=%s' % x for x in (
'MESSAGES', 'CURRENT_REVISION', 'CURRENT_COMMIT', 'ALL_FILES'))
@@ -64,12 +72,12 @@ class GerritPoller(base.PollingChangeSource):
for m in reversed(j['messages']):
if self._parse_timestamp(m['date']) <= since:
break
- if m['message'].startswith('Uploaded patch set '):
- return j
+ if self._is_interesting_message(m):
+ return j, m
d.addCallback(_parse_messages)
return d
- def createBuildbotChange(self, change):
+ def addBuildbotChange(self, change, message):
revision = change['revisions'].values()[0]
commit = revision['commit']
properties = {'event.change.number': change['_number']}
@@ -87,7 +95,7 @@ class GerritPoller(base.PollingChangeSource):
'revision': change['current_revision'],
'comments': commit['subject'],
'files': commit['files'].keys() if 'files' in commit else ['UNKNOWN'],
- 'category': 'patchset-created',
+ 'category': self.change_category,
'when_timestamp': self._parse_timestamp(commit['committer']['date']),
'revlink': '%s://%s/#/c/%s' % (
self.agent.gerrit_protocol, self.agent.gerrit_host,
@@ -95,12 +103,16 @@ class GerritPoller(base.PollingChangeSource):
'repository': '%s://%s/%s' % (
self.agent.gerrit_protocol, self.agent.gerrit_host,
change['project']),
- 'properties': properties}
+ 'properties': properties,
+ }
d = self.master.addChange(**chdict)
d.addErrback(log.err, 'GerritPoller: Could not add buildbot change for '
'gerrit change %s.' % revision['_number'])
return d
+ def addChange(self, change, message):
+ return self.addBuildbotChange(change, message)
+
def processChanges(self, j, since):
need_more = bool(j)
for change in j:
@@ -111,7 +123,7 @@ class GerritPoller(base.PollingChangeSource):
if self.gerrit_projects and change['project'] not in self.gerrit_projects:
continue
d = self.checkForNewPatchset(change, since)
- d.addCallback(lambda x: self.createBuildbotChange(x) if x else None)
+ d.addCallback(lambda x: self.addChange(*x) if x else None)
if need_more and j[-1].get('_more_changes'):
d = self.getChanges(sortkey=j[-1]['_sortkey'])
d.addCallback(self.processChanges, since=since)
« no previous file with comments | « no previous file | scripts/master/try_job_gerrit.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698