<commit_before>import os
from glob import glob

from toolbox.utils import abort_inactive_branch, run_cmd, update_hook, upload_files

from .config import CONTROLLER_FUNCTIONS_REGION, GOOGLE_PROJECT_ID


# TODO: Allow JavaScript and Go.
def deploy_controller(repo_path: str, image: str) -> list:
    controller_path = os.path.join(repo_path, 'controller')
    if glob(os.path.join(controller_path, '*.py')):
        run_cmd(
            [
                'gcloud', 'functions', 'deploy', image,
                f'--project={GOOGLE_PROJECT_ID}',
                f'--region={CONTROLLER_FUNCTIONS_REGION}',
                '--entry-point=main',
                '--runtime=python37',
                '--trigger-http'
            ],
            cwd=controller_path,
        )


def run(repo_path: str, repo_name: str, repo_branch: str, config: dict):
    abort_inactive_branch(repo_branch, allow_local=False)

    config['image'] = '-'.join((repo_name, repo_branch))
    deploy_controller(repo_path, config['image'])

    upload_files(repo_path, repo_name, repo_branch)
    update_hook(repo_name, repo_branch, config)
<commit_msg>Fix gce deploy script<commit_after>import os
from glob import glob

from toolbox.utils import abort_inactive_branch, run_cmd, update_hook, upload_files

from .config import CONTROLLER_FUNCTIONS_REGION, GOOGLE_PROJECT_ID


# TODO: Allow JavaScript and Go.
def deploy_controller(repo_path: str, image: str) -> list:
    controller_path = os.path.join(repo_path, 'controller')
    if glob(os.path.join(controller_path, '*.py')):
        run_cmd(
            [
                'gcloud', 'functions', 'deploy', image,
                f'--project={GOOGLE_PROJECT_ID}',
                f'--region={CONTROLLER_FUNCTIONS_REGION}',
                '--entry-point=main',
                '--runtime=python37',
                '--trigger-http'
            ],
            cwd=controller_path,
        )


def run(repo_path: str, repo_name: str, repo_branch: str, config: dict):
    abort_inactive_branch(repo_branch, allow_local=False)

    config['crp_config']['image'] = '-'.join((repo_name, repo_branch))
    deploy_controller(repo_path, config['crp_config']['image'])

    upload_files(repo_path, repo_name, repo_branch)
    update_hook(repo_name, repo_branch, config)

{'fraction_non_alphanumeric': 0.12094653812445223, 'fraction_numerical': 0.0017528483786152498, 'mean_word_length': 3.0193661971830985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2092852', 'n_tokens_mistral': 731, 'n_tokens_neox': 708, 'n_words': 139}