Add support for ref-updated events.
Fix paramiko import problem. Fix pep8 error. Change-Id: I7098da304ddfca18dfcc6bf79369479a73c8ae94
This commit is contained in:
parent
4c58c8f599
commit
3266340ecc
11
zuul-server
11
zuul-server
@ -21,9 +21,9 @@ import logging.config
|
||||
import os
|
||||
import signal
|
||||
|
||||
import zuul.scheduler
|
||||
import zuul.launcher.jenkins
|
||||
import zuul.trigger.gerrit
|
||||
# No zuul imports here because they pull in paramiko which must not be
|
||||
# imported until after the daemonization.
|
||||
# https://github.com/paramiko/paramiko/issues/59
|
||||
|
||||
|
||||
class Server(object):
|
||||
@ -70,6 +70,11 @@ class Server(object):
|
||||
signal.signal(signal.SIGHUP, self.reconfigure_handler)
|
||||
|
||||
def main(self):
|
||||
# See comment at top of file about zuul imports
|
||||
import zuul.scheduler
|
||||
import zuul.launcher.jenkins
|
||||
import zuul.trigger.gerrit
|
||||
|
||||
self.sched = zuul.scheduler.Scheduler()
|
||||
|
||||
jenkins = zuul.launcher.jenkins.Jenkins(self.config, self.sched)
|
||||
|
@ -167,13 +167,18 @@ class Jenkins(object):
|
||||
self.log.info("Launch job %s for change %s with dependent changes %s" %
|
||||
(job, change, dependent_changes))
|
||||
uuid = str(uuid1())
|
||||
changes_str = '^'.join(
|
||||
['%s:%s:%s' % (c.project.name, c.branch, c.refspec)
|
||||
for c in dependent_changes + [change]])
|
||||
params = dict(UUID=uuid,
|
||||
GERRIT_PROJECT=change.project.name,
|
||||
GERRIT_BRANCH=change.branch,
|
||||
GERRIT_CHANGES=changes_str)
|
||||
GERRIT_PROJECT=change.project.name)
|
||||
if change.refspec:
|
||||
changes_str = '^'.join(
|
||||
['%s:%s:%s' % (c.project.name, c.branch, c.refspec)
|
||||
for c in dependent_changes + [change]])
|
||||
params['GERRIT_BRANCH'] = change.branch
|
||||
params['GERRIT_CHANGES'] = changes_str
|
||||
if change.ref:
|
||||
params['GERRIT_REFNAME'] = change.ref
|
||||
params['GERRIT_OLDREV'] = change.oldrev
|
||||
params['GERRIT_NEWREV'] = change.newrev
|
||||
build = Build(job, uuid)
|
||||
self.builds[uuid] = build
|
||||
# We can get the started notification on another thread before
|
||||
|
@ -145,29 +145,47 @@ class Project(object):
|
||||
|
||||
|
||||
class Change(object):
|
||||
def __init__(self, queue_name, project, branch, number, patchset, refspec):
|
||||
def __init__(self, queue_name, project, event):
|
||||
self.queue_name = queue_name
|
||||
self.project = project
|
||||
self.branch = branch
|
||||
self.number = number
|
||||
self.patchset = patchset
|
||||
self.refspec = refspec
|
||||
self.branch = None
|
||||
self.number = None
|
||||
self.patchset = None
|
||||
self.refspec = None
|
||||
self.ref = None
|
||||
self.oldrev = None
|
||||
self.newrev = None
|
||||
|
||||
if event.change_number:
|
||||
self.branch = event.branch
|
||||
self.number = event.change_number
|
||||
self.patchset = event.patch_number
|
||||
self.refspec = event.refspec
|
||||
if event.ref:
|
||||
self.ref = event.ref
|
||||
self.oldrev = event.oldrev
|
||||
self.newrev = event.newrev
|
||||
|
||||
self.jobs = {}
|
||||
self.job_urls = {}
|
||||
self.change_ahead = None
|
||||
self.change_behind = None
|
||||
self.running_builds = []
|
||||
|
||||
def _id(self):
|
||||
if self.number:
|
||||
return '%s,%s' % (self.number, self.patchset)
|
||||
return self.newrev
|
||||
|
||||
def __str__(self):
|
||||
return '<Change 0x%x %s,%s>' % (id(self), self.number, self.patchset)
|
||||
return '<Change 0x%x %s>' % (id(self), self._id())
|
||||
|
||||
def formatStatus(self, indent=0):
|
||||
indent_str = ' ' * indent
|
||||
ret = ''
|
||||
ret += '%sProject %s change %s,%s\n' % (indent_str,
|
||||
self.project.name,
|
||||
self.number,
|
||||
self.patchset)
|
||||
ret += '%sProject %s change %s\n' % (indent_str,
|
||||
self.project.name,
|
||||
self._id())
|
||||
for job in self.project.getJobs(self.queue_name):
|
||||
result = self.jobs.get(job.name)
|
||||
ret += '%s %s: %s\n' % (indent_str, job.name, result)
|
||||
@ -250,14 +268,19 @@ class Change(object):
|
||||
class TriggerEvent(object):
|
||||
def __init__(self):
|
||||
self.data = None
|
||||
# common
|
||||
self.type = None
|
||||
self.project_name = None
|
||||
# patchset-created, comment-added, etc.
|
||||
self.change_number = None
|
||||
self.patch_number = None
|
||||
self.refspec = None
|
||||
self.approvals = []
|
||||
self.branch = None
|
||||
# ref-updated
|
||||
self.ref = None
|
||||
self.oldrev = None
|
||||
self.newrew = None
|
||||
|
||||
def __str__(self):
|
||||
ret = '<TriggerEvent %s %s' % (self.type, self.project_name)
|
||||
|
@ -44,7 +44,7 @@ class Scheduler(threading.Thread):
|
||||
def toList(item):
|
||||
if not item:
|
||||
return []
|
||||
if type(item) == type([]):
|
||||
if isinstance(item, list):
|
||||
return item
|
||||
return [item]
|
||||
|
||||
@ -199,13 +199,10 @@ class Scheduler(threading.Thread):
|
||||
if not manager.eventMatches(event):
|
||||
self.log.debug("Event %s ignored by %s" % (event, manager))
|
||||
continue
|
||||
if event.change_number:
|
||||
change = Change(manager.name, project, event.branch,
|
||||
event.change_number, event.patch_number,
|
||||
event.refspec)
|
||||
self.log.info("Adding %s, %s to to %s" % (
|
||||
project, change, manager))
|
||||
manager.addChange(change)
|
||||
change = Change(manager.name, project, event)
|
||||
self.log.info("Adding %s, %s to to %s" % (
|
||||
project, change, manager))
|
||||
manager.addChange(change)
|
||||
|
||||
def process_result_queue(self):
|
||||
self.log.debug("Fetching result event")
|
||||
|
@ -42,6 +42,12 @@ class GerritEventConnector(threading.Thread):
|
||||
event.patch_number = patchset.get('number')
|
||||
event.refspec = patchset.get('ref')
|
||||
event.approvals = data.get('approvals')
|
||||
refupdate = data.get('refUpdate')
|
||||
if refupdate:
|
||||
event.project_name = refupdate.get('project')
|
||||
event.ref = refupdate.get('refName')
|
||||
event.oldrev = refupdate.get('oldRev')
|
||||
event.newrev = refupdate.get('newRev')
|
||||
self.sched.addEvent(event)
|
||||
|
||||
def run(self):
|
||||
@ -72,12 +78,20 @@ class Gerrit(object):
|
||||
def report(self, change, message, action):
|
||||
self.log.debug("Report change %s, action %s, message: %s" %
|
||||
(change, action, message))
|
||||
if not change.number:
|
||||
self.log.debug("Change has no number; not reporting")
|
||||
return
|
||||
changeid = '%s,%s' % (change.number, change.patchset)
|
||||
return self.gerrit.review(change.project.name, changeid,
|
||||
message, action)
|
||||
|
||||
def isMerged(self, change):
|
||||
self.log.debug("Checking if change %s is merged", change)
|
||||
if not change.number:
|
||||
self.log.debug("Change has no number; considering it merged")
|
||||
# Good question. It's probably ref-updated, which, ah,
|
||||
# means it's merged.
|
||||
return True
|
||||
data = self.gerrit.query(change.number)
|
||||
if not data:
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user