def _handleEvent(self): data = self.gerrit.getEvent() if self._stopped: return event = TriggerEvent() event.type = data.get('type') event.trigger_name = self.trigger.name change = data.get('change') if change: event.project_name = change.get('project') event.branch = change.get('branch') event.change_number = change.get('number') event.change_url = change.get('url') patchset = data.get('patchSet') if patchset: event.patch_number = patchset.get('number') event.refspec = patchset.get('ref') event.approvals = data.get('approvals', []) event.comment = data.get('comment') 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') # Map the event types to a field name holding a Gerrit # account attribute. See Gerrit stream-event documentation # in cmd-stream-events.html accountfield_from_type = { 'patchset-created': 'uploader', 'draft-published': 'uploader', # Gerrit 2.5/2.6 'change-abandoned': 'abandoner', 'change-restored': 'restorer', 'change-merged': 'submitter', 'merge-failed': 'submitter', # Gerrit 2.5/2.6 'comment-added': 'author', 'ref-updated': 'submitter', 'reviewer-added': 'reviewer', # Gerrit 2.5/2.6 } try: event.account = data.get(accountfield_from_type[event.type]) except KeyError: self.log.error("Received unrecognized event type '%s' from Gerrit.\ Can not get account information." % event.type) event.account = None if event.change_number: # Call _getChange for the side effect of updating the # cache. Note that this modifies Change objects outside # the main thread. self.trigger._getChange(event.change_number, event.patch_number, refresh=True) self.sched.addEvent(event) self.gerrit.eventDone()
def _handleEvent(self): data = self.gerrit.getEvent() if self._stopped: return event = TriggerEvent() event.type = data.get('type') change = data.get('change') if change: event.project_name = change.get('project') event.branch = change.get('branch') event.change_number = change.get('number') event.change_url = change.get('url') patchset = data.get('patchSet') if patchset: event.patch_number = patchset.get('number') event.refspec = patchset.get('ref') event.approvals = data.get('approvals', []) event.comment = data.get('comment') 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') # Map the event types to a field name holding a Gerrit # account attribute. See Gerrit stream-event documentation # in cmd-stream-events.html accountfield_from_type = { 'patchset-created': 'uploader', 'change-abandoned': 'abandoner', 'change-restored': 'restorer', 'change-merged': 'submitter', 'comment-added': 'author', 'ref-updated': 'submitter', } try: event.account = data.get(accountfield_from_type[event.type]) except KeyError: self.log.error("Received unrecongized event type '%s' from Gerrit.\ Can not get account information." % event.type) event.account = None self.sched.addEvent(event) self.gerrit.eventDone()
def _handleEvent(self): ts, data = self.connection.getEvent() if self._stopped: return # Gerrit can produce inconsistent data immediately after an # event, So ensure that we do not deliver the event to Zuul # until at least a certain amount of time has passed. Note # that if we receive several events in succession, we will # only need to delay for the first event. In essence, Zuul # should always be a constant number of seconds behind Gerrit. now = time.time() time.sleep(max((ts + self.delay) - now, 0.0)) event = TriggerEvent() event.type = data.get('type') event.trigger_name = 'gerrit' change = data.get('change') if change: event.project_name = change.get('project') event.branch = change.get('branch') event.change_number = change.get('number') event.change_url = change.get('url') patchset = data.get('patchSet') if patchset: event.patch_number = patchset.get('number') event.refspec = patchset.get('ref') event.approvals = data.get('approvals', []) event.comment = data.get('comment') 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') # Map the event types to a field name holding a Gerrit # account attribute. See Gerrit stream-event documentation # in cmd-stream-events.html accountfield_from_type = { 'patchset-created': 'uploader', 'draft-published': 'uploader', # Gerrit 2.5/2.6 'change-abandoned': 'abandoner', 'change-restored': 'restorer', 'change-merged': 'submitter', 'merge-failed': 'submitter', # Gerrit 2.5/2.6 'comment-added': 'author', 'ref-updated': 'submitter', 'reviewer-added': 'reviewer', # Gerrit 2.5/2.6 } try: event.account = data.get(accountfield_from_type[event.type]) except KeyError: self.log.warning("Received unrecognized event type '%s' from Gerrit.\ Can not get account information." % event.type) event.account = None if (event.change_number and self.connection.sched.getProject(event.project_name)): # Call _getChange for the side effect of updating the # cache. Note that this modifies Change objects outside # the main thread. # NOTE(jhesketh): Ideally we'd just remove the change from the # cache to denote that it needs updating. However the change # object is already used by Item's and hence BuildSet's etc. and # we need to update those objects by reference so that they have # the correct/new information and also avoid hitting gerrit # multiple times. if self.connection.attached_to['source']: self.connection.attached_to['source'][0]._getChange( event.change_number, event.patch_number, refresh=True) # We only need to do this once since the connection maintains # the cache (which is shared between all the sources) # NOTE(jhesketh): We may couple sources and connections again # at which point this becomes more sensible. self.connection.sched.addEvent(event)
def _handleEvent(self): ts, data = self.connection.getEvent() if self._stopped: self.connection.eventDone() return # Gerrit can produce inconsistent data immediately after an # event, So ensure that we do not deliver the event to Zuul # until at least a certain amount of time has passed. Note # that if we receive several events in succession, we will # only need to delay for the first event. In essence, Zuul # should always be a constant number of seconds behind Gerrit. now = time.time() time.sleep(max((ts + self.delay) - now, 0.0)) event = TriggerEvent() event.type = data.get('type') event.trigger_name = 'gerrit' change = data.get('change') if change: event.project_name = change.get('project') event.branch = change.get('branch') event.change_number = change.get('number') event.change_url = change.get('url') patchset = data.get('patchSet') if patchset: event.patch_number = patchset.get('number') event.refspec = patchset.get('ref') event.approvals = data.get('approvals', []) event.comment = data.get('comment') 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') # Map the event types to a field name holding a Gerrit # account attribute. See Gerrit stream-event documentation # in cmd-stream-events.html accountfield_from_type = { 'patchset-created': 'uploader', 'draft-published': 'uploader', # Gerrit 2.5/2.6 'change-abandoned': 'abandoner', 'change-restored': 'restorer', 'change-merged': 'submitter', 'merge-failed': 'submitter', # Gerrit 2.5/2.6 'comment-added': 'author', 'ref-updated': 'submitter', 'reviewer-added': 'reviewer', # Gerrit 2.5/2.6 } try: event.account = data.get(accountfield_from_type[event.type]) except KeyError: self.log.error("Received unrecognized event type '%s' from Gerrit.\ Can not get account information." % event.type) event.account = None if (event.change_number and self.connection.sched.getProject(event.project_name)): # Mark the change as needing a refresh in the cache event._needs_refresh = True self.connection.sched.addEvent(event) self.connection.eventDone()