<commit_before>import git
import github
import os
from .utils import tmp_directory


def update_feedstock(org_name, repo_name):
    if not repo_name.endswith("-feedstock"):
        return

    gh = github.Github(os.environ['FEEDSTOCKS_GH_TOKEN'])

    repo_gh = gh.get_repo("{}/{}".format(org_name, repo_name))
    name = repo_name[:-len("-feedstock")]

    with tmp_directory() as tmp_dir:
        feedstocks_url = (
            "https://{}@github.com/conda-forge/feedstocks.git"
            "".format(os.environ["FEEDSTOCKS_GH_TOKEN"])
        )
        feedstocks_repo = git.Repo.clone_from(
            feedstocks_url,
            tmp_dir
        )

        # Get the submodule
        feedstock_submodule = feedstocks_repo.create_submodule(
            name=name,
            path=os.path.join("feedstocks", name),
            url=repo_gh.clone_url,
            branch="master"
        )
        # Hack needed if the submodule already exists.
        # Borrows the fix accepted upstream.
        # PR: https://github.com/gitpython-developers/GitPython/pull/679
        feedstock_submodule._name = name

        # Update the feedstocks submodule
        feedstock_submodule.update(init=True, recursive=False, force=True)
        feedstock_submodule.branch.checkout(force=True)
        feedstock_submodule.update(
            init=True,
            recursive=False,
            force=True,
            to_latest_revision=True
        )

        # Submit changes
        if feedstocks_repo.is_dirty():
            author = git.Actor(
                "conda-forge-coordinator", "<EMAIL>"
            )
            feedstocks_repo.git.add(update=True)
            feedstocks_repo.index.commit(
                "Updated feedstocks submodules. [ci skip]",
                author=author,
                committer=author
            )
            feedstocks_repo.remote().pull(rebase=True)
            feedstocks_repo.remote().push()


if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('org')
    parser.add_argument('repo')
    args = parser.parse_args()
    update_feedstock(args.org, args.repo)
<commit_msg>Avoid calling GitHub API when updating feedstocks<commit_after>import git
import os
from .utils import tmp_directory


def update_feedstock(org_name, repo_name):
    if not repo_name.endswith("-feedstock"):
        return

    name = repo_name[:-len("-feedstock")]

    with tmp_directory() as tmp_dir:
        feedstocks_url = (
            "https://{}@github.com/conda-forge/feedstocks.git"
            "".format(os.environ["FEEDSTOCKS_GH_TOKEN"])
        )
        feedstocks_repo = git.Repo.clone_from(
            feedstocks_url,
            tmp_dir
        )

        # Get the submodule
        feedstock_submodule = feedstocks_repo.create_submodule(
            name=name,
            path=os.path.join("feedstocks", name),
            url="https://github.com/{0}/{1}.git".format(org_name, repo_name),
            branch="master"
        )
        # Hack needed if the submodule already exists.
        # Borrows the fix accepted upstream.
        # PR: https://github.com/gitpython-developers/GitPython/pull/679
        feedstock_submodule._name = name

        # Update the feedstocks submodule
        feedstock_submodule.update(init=True, recursive=False, force=True)
        feedstock_submodule.branch.checkout(force=True)
        feedstock_submodule.update(
            init=True,
            recursive=False,
            force=True,
            to_latest_revision=True
        )

        # Submit changes
        if feedstocks_repo.is_dirty():
            author = git.Actor(
                "conda-forge-coordinator", "<EMAIL>"
            )
            feedstocks_repo.git.add(update=True)
            feedstocks_repo.index.commit(
                "Updated feedstocks submodules. [ci skip]",
                author=author,
                committer=author
            )
            feedstocks_repo.remote().pull(rebase=True)
            feedstocks_repo.remote().push()


if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('org')
    parser.add_argument('repo')
    args = parser.parse_args()
    update_feedstock(args.org, args.repo)

{'fraction_non_alphanumeric': 0.10287584755669862, 'fraction_numerical': 0.0018704699555763386, 'mean_word_length': 2.134065934065934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 5, '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': '2130129', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1264, 'n_words': 212}