<commit_before>from __future__ import absolute_import
from __future__ import unicode_literals

import os

from git import GitCommandError
from git import Repo
from github import Github

from .const import NAME
from .const import REPO_ROOT
from .utils import branch_name
from .utils import read_release_notes_from_changelog
from .utils import ScriptError


class Repository(object):
    def __init__(self, root=None, gh_name=None):
        if root is None:
            root = REPO_ROOT
        if gh_name is None:
            gh_name = NAME
        self.git_repo = Repo(root)
        self.gh_client = Github(os.environ['GITHUB_TOKEN'])
        self.gh_repo = self.gh_client.get_repo(gh_name)

    def create_release_branch(self, version, base=None):
        print('Creating release branch {} based on {}...'.format(version, base or 'master'))
        remote = self.find_remote(self.gh_repo.full_name)
        remote.fetch()
        if self.branch_exists(branch_name(version)):
            raise ScriptError(
                "Branch {} already exists locally. "
                "Please remove it before running the release script.".format(branch_name(version))
            )
        if base is not None:
            base = self.git_repo.tag('refs/tags/{}'.format(base))
        else:
            base = 'refs/remotes/{}/master'.format(remote.name)
        release_branch = self.git_repo.create_head(branch_name(version), commit=base)
        release_branch.checkout()
        self.git_repo.git.merge('--strategy=ours', '--no-edit', '{}/release'.format(remote.name))
        with release_branch.config_writer() as cfg:
            cfg.set_value('release', version)
        return release_branch

    def find_remote(self, remote_name=None):
        if not remote_name:
            remote_name = self.gh_repo.full_name
        for remote in self.git_repo.remotes:
            for url in remote.urls:
                if remote_name in url:
                    return remote
        return None

    def create_bump_commit(self, bump_branch, version):
        print('Creating bump commit...')
        bump_branch.checkout()<commit_msg>Temp test<commit_after>from __future__ import absolute_import
from __future__ import unicode_literals

import os

from git import GitCommandError
from git import Repo
from github import Github

from .const import NAME
from .const import REPO_ROOT
from .utils import branch_name
from .utils import read_release_notes_from_changelog
from .utils import ScriptError


class Repository(object):
    def __init__(self, root=None, gh_name=None):
        if root is None:
            root = REPO_ROOT
        if gh_name is None:
            gh_name = NAME
        self.git_repo = Repo(root)
        self.gh_client = Github(os.environ['GITHUB_TOKEN'])
        self.gh_repo = self.gh_client.get_repo(gh_name)

    def create_release_branch(self, version, base=None):
        print('Creating release branch {} based on {}...'.format(version, base or 'master'))
        remote = self.find_remote(self.gh_repo.full_name)
        remote.fetch()
        if self.branch_exists(branch_name(version)):
            raise ScriptError(
                "Branch {} already exists locally. "
                "Please remove it before running the release script.".format(branch_name(version))
            )
        if base is not None:
            base = self.git_repo.tag('refs/tags/{}'.format(base))
        else:
            base = 'refs/remotes/{}/automated-releases'.format(remote.name)
        release_branch = self.git_repo.create_head(branch_name(version), commit=base)
        release_branch.checkout()
        self.git_repo.git.merge('--strategy=ours', '--no-edit', '{}/release'.format(remote.name))
        with release_branch.config_writer() as cfg:
            cfg.set_value('release', version)
        return release_branch

    def find_remote(self, remote_name=None):
        if not remote_name:
            remote_name = self.gh_repo.full_name
        for remote in self.git_repo.remotes:
            for url in remote.urls:
                if remote_name in url:
                    return remote
        return None

    def create_bump_commit(self, bump_branch, version):
        print('Creating bump commit...')
        bump_branch.checkout()
{'fraction_non_alphanumeric': 0.09399906235349273, 'fraction_numerical': 0.0, 'mean_word_length': 2.582703610411419, 'pattern_counts': {'":': 0, '<': 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': '5814455', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1210, 'n_words': 310}