Esempio n. 1
0
 def _parse_messages(j):
     if not j or 'messages' not in j:
         return
     for m in reversed(j['messages']):
         if ParseGerritTime(m['date']) <= since:
             break
         if self._is_interesting_message(m):
             return j, m
Esempio n. 2
0
    def created_time(self):
        """Returns a 'datetime.datetime' corresponding to this change's 'created'
    field. If the field was missing, this will return 'None'.

    Return: A datetime.datetime object representing the created time, or None
      if the created time is not present.

    Raises:
      ValueError if the 'created' field could not be successfully parsed.
    """
        result = self.get('created')
        if result is not None:
            result = ParseGerritTime(result)
        return result
Esempio n. 3
0
 def processChanges(self, j, since, skip=0):
     need_more = bool(j)
     for change in j:
         skip += 1
         tm = ParseGerritTime(change['updated'])
         if tm <= since:
             need_more = False
             break
         if self.gerrit_projects and change[
                 'project'] not in self.gerrit_projects:
             continue
         d = self.checkForNewPatchset(change, since)
         d.addCallback(lambda x: self.addChange(*x) if x else None)
     if need_more and j[-1].get('_more_changes'):
         d = self.getChanges(skip=skip)
         d.addCallback(self.processChanges, since=since, skip=skip)
     else:
         d = defer.succeed(None)
     return d
Esempio n. 4
0
 def date(self):
     return ParseGerritTime(self['date'])
Esempio n. 5
0
 def date(self):
     value = self._data.get('date')
     if value is None:
         return None
     return ParseGerritTime(value)
Esempio n. 6
0
 def _update_last_timestamp(j):
     if j:
         self.last_timestamp = ParseGerritTime(j[0]['updated'])
     return j
Esempio n. 7
0
    def addBuildbotChange(self, change, revision=None, additional_chdict=None):
        """Adds a buildbot change into the database.

    Args:
      change: ChangeInfo Gerrit object. Documentation:
        https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-info
      revision: the sha of the buildbot change revision to use. Defaults to the
        value of change['current_revision']

    Returns the new buildbot change as Deferred.
    """
        revision = revision or change['current_revision']
        revision_details = change['revisions'][revision]
        commit = revision_details['commit']

        properties = {
            'event.change.number': change['_number'],
            'event.change.id': change['id'],
            'event.change.url': self.getChangeUrl(change),
        }
        if change['status'] == 'NEW':
            ref = revision_details.get('fetch', {}).get('http', {}).get('ref')
            if ref:
                properties['event.patchSet.ref'] = ref
        elif change['status'] in ('SUBMITTED', 'MERGED'):
            properties['event.refUpdate.newRev'] = revision
        chdict = {
            'author':
            '%s <%s>' % (commit['author']['name'], commit['author']['email']),
            'project':
            change['project'],
            'branch':
            change['branch'],
            'revision':
            revision,
            'comments':
            commit['subject'],
            'files':
            revision_details.get('files', {
                'UNKNOWN': None
            }).keys(),
            'category':
            self.change_category,
            'when_timestamp':
            ParseGerritTime(commit['committer']['date']),
            'revlink':
            self.getChangeUrl(change),
            'repository':
            self.getRepositoryUrl(change),
            'properties':
            properties,
        }

        # Factor in external 'chdict' overrides.
        if additional_chdict is not None:
            properties.update(additional_chdict.pop('properties', {}))
            chdict.update(additional_chdict)
        chdict['properties'] = properties

        d = self.master.addChange(**chdict)
        d.addErrback(
            log.err, 'GerritPoller: Could not add buildbot change for '
            'gerrit change %s.' % revision_details['_number'])
        return d
Esempio n. 8
0
 def _get_timestamp(j):
     if len(j) == 0:
         self.last_timestamp = datetime.datetime.now()
     else:
         self.last_timestamp = ParseGerritTime(j[0]['updated'])