Beispiel #1
0
 def BuildsetTags(self):
     patch_info = gerrit_service.GetChange(self.server,
                                           self.change,
                                           fields=('ALL_REVISIONS', ))
     revision_info = patch_info['revisions'][self.revision]
     return 'buildset:patch/gerrit/%s/%s/%s' % (
         self.hostname, patch_info['_number'], revision_info['_number'])
Beispiel #2
0
 def AsDict(self):
     patch_info = gerrit_service.GetChange(self.server,
                                           self.change,
                                           fields=('ALL_REVISIONS',
                                                   'DETAILED_ACCOUNTS'))
     # TODO: Cache this stuff in memcache.
     revision_info = patch_info['revisions'][self.revision]
     return {
         'server':
         self.server,
         'change':
         self.change,
         'revision':
         self.revision,
         'url':
         '%s/c/%s/+/%d/%d' %
         (self.server, patch_info['project'], patch_info['_number'],
          revision_info['_number']),
         'subject':
         patch_info['subject'],
         'time':
         revision_info['created'],
         'author':
         revision_info['uploader']['email'],
     }
Beispiel #3
0
  def AsDict(self):
    d = {
        'server': self.server,
        'change': self.change,
        'revision': self.revision,
    }

    try:
      d.update(commit_cache.Get(self.id_string))
      d['created'] = d['created'].isoformat()
    except KeyError:
      patch_info = gerrit_service.GetChange(
          self.server, self.change,
          fields=('ALL_REVISIONS', 'DETAILED_ACCOUNTS', 'COMMIT_FOOTERS'))
      revision_info = patch_info['revisions'][self.revision]
      url = '%s/c/%s/+/%d/%d' % (
          self.server, patch_info['project'],
          patch_info['_number'], revision_info['_number'])
      author = revision_info['uploader']['email']
      created = datetime.datetime.strptime(
          revision_info['created'], '%Y-%m-%d %H:%M:%S.%f000')
      subject = patch_info['subject']
      current_revision = patch_info['current_revision']
      message = patch_info['revisions'][current_revision]['commit_with_footers']

      d.update({
          'url': url,
          'author': author,
          'created': created.isoformat(),
          'subject': subject,
          'message': message,
      })
      commit_cache.Put(self.id_string, url, author, created, subject, message)

    return d
 def testGetChange(self):
     server = 'https://chromium-review.googlesource.com'
     response = gerrit_service.GetChange(server, 672011)
     self._AssertCorrectResponse(response)
     self._AssertRequestMadeOnce(server + '/changes/672011',
                                 use_auth=True,
                                 scope=gerrit_service.GERRIT_SCOPE,
                                 o=None)
 def testGetChangeWithFields(self):
     server = 'https://chromium-review.googlesource.com'
     response = gerrit_service.GetChange(server,
                                         672011,
                                         fields=('FIELD_NAME', ))
     self._AssertCorrectResponse(response)
     self._AssertRequestMadeOnce(server + '/changes/672011',
                                 o=('FIELD_NAME', ))
Beispiel #6
0
    def FromDict(cls, data):
        """Creates a new GerritPatch from the given data.

    Args:
      data: A patch URL string, for example:
        https://chromium-review.googlesource.com/c/chromium/tools/build/+/679595
        Or a dict containing {server, change, revision [optional]}.
        change is a {change-id} as described in the Gerrit API documentation.
        revision is a commit ID hash or numeric patch number.
        If revision is omitted, it is the change's current revision.

    Returns:
      A GerritPatch.

    Raises:
      KeyError: The patch doesn't have the given revision.
      ValueError: The URL has an unrecognized format.
    """
        if isinstance(data, basestring):
            url_parts = urlparse.urlparse(data)
            server = urlparse.urlunsplit(
                (url_parts.scheme, url_parts.netloc, '', '', ''))

            path_parts = iter(url_parts.path.split('/'))
            for path_part in path_parts:
                if path_part == '+':
                    break
            else:
                raise ValueError('Unknown URL format.')

            change = path_parts.next()
            try:
                revision = int(path_parts.next())
            except StopIteration:
                revision = None
        else:
            server = data['server']
            change = data['change']
            revision = data.get('revision')

        # Look up the patch and convert everything to a canonical format.
        patch_info = gerrit_service.GetChange(server,
                                              change,
                                              fields=('ALL_REVISIONS', ))
        change = patch_info['id']

        # Revision can be a revision ID or numeric patch number.
        if not revision:
            revision = patch_info['current_revision']
        for revision_id, revision_info in patch_info['revisions'].iteritems():
            if revision == revision_id or revision == revision_info['_number']:
                revision = revision_id
                break
        else:
            raise KeyError('Patch revision not found: %s/%s revision %s' %
                           (server, change, revision))

        return cls(server, change, revision)
Beispiel #7
0
 def BuildParameters(self):
   patch_info = gerrit_service.GetChange(
       self.server, self.change, fields=('ALL_REVISIONS',))
   revision_info = patch_info['revisions'][self.revision]
   return {
       'patch_gerrit_url': self.server,
       'patch_issue': patch_info['_number'],
       'patch_project': patch_info['project'],
       'patch_ref': revision_info['fetch']['http']['ref'],
       'patch_repository_url': revision_info['fetch']['http']['url'],
       'patch_set': revision_info['_number'],
       'patch_storage': 'gerrit',
   }
Beispiel #8
0
def _RequestBuild(builder_name, change, bucket):
    base_as_dict = change.base_commit.AsDict()
    review_url = base_as_dict.get('review_url')
    if not review_url:
        raise BuildError('Could not find gerrit review url for commit: ' +
                         str(base_as_dict))

    change_id = base_as_dict.get('change_id')
    if not change_id:
        raise BuildError('Could not find gerrit change id for commit: ' +
                         str(base_as_dict))

    url_parts = urlparse.urlparse(review_url)
    base_review_url = urlparse.urlunsplit(
        (url_parts.scheme, url_parts.netloc, '', '', ''))

    patch = change_module.GerritPatch.FromUrl(review_url)

    change_info = gerrit_service.GetChange(base_review_url, patch.change)

    commit_url_parts = urlparse.urlparse(base_as_dict['url'])

    # Note: The ordering here for buildbucket v1 api is important.
    # crbug.com/937392
    builder_tags = []
    if change.patch:
        builder_tags.append(change.patch.BuildsetTags())
    builder_tags.append('buildset:commit/gitiles/%s/%s/+/%s' %
                        (commit_url_parts.netloc, change_info['project'],
                         change.base_commit.git_hash))

    deps_overrides = {dep.repository_url: dep.git_hash for dep in change.deps}
    parameters = {
        'builder_name': builder_name,
        'properties': {
            'clobber': True,
            'revision': change.base_commit.git_hash,
            'deps_revision_overrides': deps_overrides,
        },
    }

    if change.patch:
        parameters['properties'].update(change.patch.BuildParameters())

    # TODO: Look up Buildbucket bucket from builder_name.
    return buildbucket_service.Put(bucket, builder_tags, parameters)
Beispiel #9
0
    def FromDict(cls, data):
        """Creates a new GerritPatch from the given dict.

    Args:
      data: A dict containing {server, change, revision [optional]}.
        change is a {change-id} as described in the Gerrit API documentation.
        revision is a commit ID hash or numeric patch number.
        If revision is omitted, it is the change's current revision.

    Returns:
      A GerritPatch.

    Raises:
      KeyError: The patch doesn't have the given revision.
    """
        server = data['server']
        change = data['change']
        revision = data.get('revision')

        # Look up the patch and convert everything to a canonical format.
        try:
            patch_info = gerrit_service.GetChange(server,
                                                  change,
                                                  fields=('ALL_REVISIONS', ))
        except gerrit_service.NotFoundError as e:
            raise KeyError(str(e))
        change = patch_info['id']

        # Revision can be a revision ID or numeric patch number.
        if not revision:
            revision = patch_info['current_revision']
        for revision_id, revision_info in patch_info['revisions'].items():
            if revision == revision_id or revision == revision_info['_number']:
                revision = revision_id
                break
        else:
            raise KeyError('Patch revision not found: %s/%s revision %s' %
                           (server, change, revision))

        return cls(server, change, revision)
Beispiel #10
0
def _RequestBuild(builder_name, change, bucket, build_tags, task=None):
    base_as_dict = change.base_commit.AsDict()
    review_url = base_as_dict.get('review_url')
    if not review_url:
        raise errors.BuildGerritUrlNotFound(str(change.base_commit))

    url_parts = urlparse.urlparse(review_url)
    base_review_url = urlparse.urlunsplit(
        (url_parts.scheme, url_parts.netloc, '', '', ''))

    patch = change_module.GerritPatch.FromUrl(review_url)

    change_info = gerrit_service.GetChange(base_review_url, patch.change)

    commit_url_parts = urlparse.urlparse(base_as_dict['url'])

    # Note: The ordering here for buildbucket v1 api is important.
    # crbug.com/937392
    builder_tags = []
    if change.patch:
        builder_tags.append(change.patch.BuildsetTags())
    builder_tags.append('buildset:commit/gitiles/%s/%s/+/%s' %
                        (commit_url_parts.netloc, change_info['project'],
                         change.base_commit.git_hash))
    builder_tags.extend(['%s:%s' % (k, v) for k, v in build_tags.items()])

    deps_overrides = {dep.repository_url: dep.git_hash for dep in change.deps}
    parameters = {
        'builder_name': builder_name,
        'properties': {
            'clobber': True,
            'revision': change.base_commit.git_hash,
            'deps_revision_overrides': deps_overrides,
        },
    }

    if change.patch:
        parameters['properties'].update(change.patch.BuildParameters())

    logging.debug('bucket: %s', bucket)
    logging.debug('builder_tags: %s', builder_tags)
    logging.debug('parameters: %s', parameters)

    pubsub_callback = None
    if build_tags:
        # This means we have access to Pinpoint job details, we should provide this
        # information to the attempts to build.
        pubsub_callback = {
            # TODO(dberris): Consolidate constants in environment vars?
            'topic':
            'projects/chromeperf/topics/pinpoint-swarming-updates',
            'auth_token':
            'UNUSED',
            'user_data':
            json.dumps({
                'job_id': build_tags.get('pinpoint_job_id'),
                'task': {
                    'type':
                    'build',
                    'id':
                    build_tags.get('pinpoint_task_id')
                    if not task else task.id,
                }
            })
        }
        logging.debug('pubsub_callback: %s', pubsub_callback)

    # TODO: Look up Buildbucket bucket from builder_name.
    return buildbucket_service.Put(bucket, builder_tags, parameters,
                                   pubsub_callback)