Esempio n. 1
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 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))

    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)

    # TODO: Look up Buildbucket bucket from builder_name.
    return buildbucket_service.Put(bucket, builder_tags, parameters)
Esempio n. 2
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)