<commit_before>import os
import sys
import subprocess
import hashlib
import argparse


def merge(source, merge_to):
    current = subprocess.check_output(
        ['git', 'rev-parse', "HEAD"]).decode('utf-8').strip()
    subprocess.check_output(
        ['git', 'config', "--replace-all", "remote.origin.fetch",
         '+refs/heads/*:refs/remotes/origin/*'])
    subprocess.check_output(['git', 'fetch'])
    subprocess.check_output(
        ['git', 'checkout', merge_to]).decode('utf-8').strip()
    subprocess.check_output(
        ['git', 'merge', current, '-m', 'merged']).decode('utf-8').strip()
    subprocess.check_output(
        ['git', 'push', 'origin', merge_to]).decode('utf-8').strip()


def get_git_version():
    if (os.environ.get("TRAVIS_BRANCH") == "production"):
        version = "1.0.0"  # Change this with new version
    else:
        version = os.environ.get("TRAVIS_COMMIT")
    if not version:
        version = subprocess.check_output(
            ['git', '-C', os.path.dirname(__file__), 'describe']).decode('utf-8').strip()
        diff = subprocess.check_output(
            ['git', '-C', os.path.dirname(__file__), 'diff', '--no-ext-diff'])
        if diff:
            version += '-patch' + hashlib.sha1(diff).hexdigest()[:7]
    return version


def update_version(version):
    filename = 'buildout.cfg'
    regex = 's/encoded_version.*/encoded_version = %s/' % (version)

    print("updated buildout.cfg with version", version)
    subprocess.check_output(
        ['sed', '-i', regex, filename])
    commit_with_previous_msg(filename)


def commit_with_previous_msg(filename):
    print("adding file to git")
    subprocess.check_output(
        ['git', 'add', filename])

    msg = parse(previous_git_commit())

    print("git commit -m " + msg)
    subprocess.check_output(
        ['git', 'commit', '-m', 'version bump + ' + msg])

def previous_git_commit():
    return subprocess.check_output(
        ['git', 'log', '-1']
    ).decode('utf-8').strip()

def parse(commit):
    author , msg = "", ""
    # parse up some commit lines
    commit_lines = commit.split('\n')
    author = commit_lines[1].split(":")[1].strip()
    msg = " ".join(l.strip() for l in commit_lines[3:] if l)

    return  "%s - %s" % (author, msg)


def deploy():
    '''
    run eb deploy and show the output
    '''
    print("start deployment to elastic beanstalk")

    p = subprocess.Popen(['eb', 'deploy'], stderr=subprocess.PIPE)
    while True:
        out = p.stderr.read(1)
        out = out.decode('utf-8')
        if out == '' and p.poll() != None:
            break
        if out != '':
            sys.stdout.write(out)
            sys.stdout.flush()


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="update version if relevant and deploy"
    )
    parser.add_argument('--prod', action="store_true", help="deploy to prod")
    args = parser.parse_args()
    branch = os.environ.get("TRAVIS_BRANCH")
    merge_to = os.environ.get("tibanna_merge")

    if not args.prod:
        print("not production")
        ver = get_git_version()
        update_version(ver)
        if merge_to:
            merge(branch, merge_to)
        deploy()<commit_msg>working on deploy script still<commit_after>import os
import sys
import subprocess
import hashlib
import argparse


def tag(name):
    subprocess.check_output(['git', 'tag', name, '-m', 'version created for staging deploy'])


def merge(source, merge_to):
    current = subprocess.check_output(
        ['git', 'rev-parse', "HEAD"]).decode('utf-8').strip()
    subprocess.check_output(
        ['git', 'config', "--replace-all", "remote.origin.fetch",
         '+refs/heads/*:refs/remotes/origin/*'])
    subprocess.check_output(['git', 'fetch', '--no-tags', '--depth 200'])
    subprocess.check_output(
        ['git', 'checkout', merge_to]).decode('utf-8').strip()
    subprocess.check_output(
        ['git', 'merge', current, '-m', 'merged']).decode('utf-8').strip()
    subprocess.check_output(
        ['git', 'push', 'origin', merge_to]).decode('utf-8').strip()


def get_git_version():
    if (os.environ.get("TRAVIS_BRANCH") == "production"):
        version = "1.0.0"  # Change this with new version
    else:
        version = os.environ.get("TRAVIS_COMMIT")
    if not version:
        version = subprocess.check_output(
            ['git', '-C', os.path.dirname(__file__), 'describe']).decode('utf-8').strip()
        diff = subprocess.check_output(
            ['git', '-C', os.path.dirname(__file__), 'diff', '--no-ext-diff'])
        if diff:
            version += '-patch' + hashlib.sha1(diff).hexdigest()[:7]
    return version


def update_version(version):
    filename = 'buildout.cfg'
    regex = 's/encoded_version.*/encoded_version = %s/' % (version)

    print("updated buildout.cfg with version", version)
    subprocess.check_output(
        ['sed', '-i', regex, filename])
    commit_with_previous_msg(filename)


def commit_with_previous_msg(filename):
    print("adding file to git")
    subprocess.check_output(
        ['git', 'add', filename])

    msg = parse(previous_git_commit())

    print("git commit -m " + msg)
    subprocess.check_output(
        ['git', 'commit', '-m', 'version bump + ' + msg])

def previous_git_commit():
    return subprocess.check_output(
        ['git', 'log', '-1']
    ).decode('utf-8').strip()

def parse(commit):
    author , msg = "", ""
    # parse up some commit lines
    commit_lines = commit.split('\n')
    author = commit_lines[1].split(":")[1].strip()
    msg = " ".join(l.strip() for l in commit_lines[3:] if l)

    return  "%s - %s" % (author, msg)


def deploy():
    '''
    run eb deploy and show the output
    '''
    print("start deployment to elastic beanstalk")

    p = subprocess.Popen(['eb', 'deploy'], stderr=subprocess.PIPE)
    while True:
        out = p.stderr.read(1)
        out = out.decode('utf-8')
        if out == '' and p.poll() != None:
            break
        if out != '':
            sys.stdout.write(out)
            sys.stdout.flush()


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="update version if relevant and deploy"
    )
    parser.add_argument('--prod', action="store_true", help="deploy to prod")
    args = parser.parse_args()
    branch = os.environ.get("TRAVIS_BRANCH")
    merge_to = os.environ.get("tibanna_merge")

    if not args.prod:
        print("not production")
        ver = get_git_version()
        update_version(ver)
        if merge_to:
            merge(branch, merge_to)
            tag()
        deploy()
{'fraction_non_alphanumeric': 0.16868564506359782, 'fraction_numerical': 0.005602665051483949, 'mean_word_length': 2.8289855072463768, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '5143276', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2090, 'n_words': 466}