@require_POST
def import_build(request):
    """
    example POST params:
    source: 'http://build.dimagi.com:250/repository/downloadAll/bt97/14163:id/artifacts.zip'
    version: '2.13.0'
    build_number: 32703

    """
    source = request.POST.get('source')
    version = request.POST.get('version')
    build_number = request.POST.get('build_number')

    try:
        SemanticVersionProperty().validate(version)
    except BadValueError as e:
        return json_response({
            'reason': 'Badly formatted version',
            'info': {
                'error_message': unicode(e),
                'error_type': unicode(type(e))
            }
        }, status_code=400)

    if build_number:
        try:
            build_number = int(build_number)
        except __HOLE__:
            return json_response({
                'reason': 'build_number must be an int'
            }, status_code=400)

    session = requests.session()

    # log in to the build server if we know how
    for key in KNOWN_BUILD_SERVER_LOGINS:
        if source.startswith(key):
            KNOWN_BUILD_SERVER_LOGINS[key](session)

    r = session.get(source)

    try:
        r.raise_for_status()
    except requests.exceptions.HTTPError:
        return json_response({
            'reason': 'Fetching artifacts.zip failed',
            'response': {
                'status_code': r.status_code,
                'content': r.content,
                'headers': r.headers,
            }
        }, status_code=400)
    try:
        _, inferred_build_number = (
            extract_build_info_from_filename(r.headers['content-disposition'])
        )
    except (KeyError, ValueError):  # no header or header doesn't match
        inferred_build_number = None

    if inferred_build_number:
        build_number = inferred_build_number

    if not build_number:
        return json_response({
            'reason': "You didn't give us a build number "
                      "and we couldn't infer it"
        }, status_code=400)

    build = CommCareBuild.create_from_zip(
        StringIO(r.content), version, build_number)

    return json_response({
        'message': 'New CommCare build added',
        'info': {
            'version': version,
            'build_number': build_number,
            '_id': build.get_id,
        }
    })
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/builds/views.py/import_build