<commit_before>#!/usr/bin/env python
"""
Tag repos for an Open edX release. When run, this script will:

1. Make sure we have an OAuth token for the GitHub API, and help the user
   create one if we don't already have one
2. Fetch the repos.yaml file from the repo-tools-data repo
3. Identify the repos in that file that are tagged in the Open edX release
4. Identify the commit that needs to be tagged in each repo, tracing cross-repo
   dependencies as necessary
5. Show the identified repos and commits, and ask for confirmation from the user
6. Upon confirmation, create Git tags for the repos using the GitHub API
"""
from __future__ import unicode_literals, print_function
import sys
import re
import json
import getpass
import argparse
import logging
import copy
try:
    from path import Path as path
    from git import Repo, Commit
    from git.refs.symbolic import SymbolicReference
    from git.exc import GitCommandError
    import requests
    from requests.exceptions import RequestException
    import yaml
except ImportError:
    print("Error: missing dependencies! Please run this command to install them:")
    print("pip install path.py requests GitPython PyYAML")
    sys.exit(1)

log = logging.getLogger(__name__)


# Name used for fetching/storing GitHub OAuth tokens on disk
TOKEN_NAME = "<PASSWORD>"
# URL to the source of truth about our repositories
REPOS_YAML = "https://raw.githubusercontent.com/edx/repo-tools-data/master/repos.yaml"
# Regular expression for parsing out the parts of a pip requirement line
REQUIREMENT_RE = re.compile(r"""
    git\+https?://github\.com/          # prefix
    (?P<owner>[a-zA-Z0-9_.-]+)/         # repo owner
    (?P<repo>[a-zA-Z0-9_.-]+).git       # repo name
    (@(?P<ref>[a-zA-Z0-9_.-]+))?        # git ref (tag, branch, or commit hash) (optional)
    (\#egg=(?P<egg>[a-zA-Z0-9_.-]+))?   # egg name (optional)
    (==(?P<version>[a-zA-Z0-9_.-]+))?   # version (optional)
""", re.VERBOSE)


def make_parser():
    parser = argparse.ArgumentParser(
        description="Create/remove tags & branches on GitHub repos for Open edX releases",
    )
    parser.add_argument(
        'ref', metavar="REFNAME",
        help="The name of the ref to create in the repos",
    )

    refgroup = parser.add_argument_group(
        "arguments for git refs",
    )
    reftype = refgroup.add_mutually_exclusive_group()
    reftype.add_argument(
        '--tag', action="store_true", default=True, dest="use_tag",
        help="Create tags in repos [default]"
    )
    reftype.add_argument(
        '--branch', action="store_false", default=True, dest="use_tag",
        help="Create branches in repos"
    )
    refgroup.add_argument(
        '--override-ref', nargs=1, metavar="REF",
        help="A reference to use that overrides the references from the "
            "repos.yaml file in *ALL* repos. This might be a release candidate "
            "branch, for example."<commit_msg>Store one item (default) for override-ref, not a list of one item<commit_after>#!/usr/bin/env python
"""
Tag repos for an Open edX release. When run, this script will:

1. Make sure we have an OAuth token for the GitHub API, and help the user
   create one if we don't already have one
2. Fetch the repos.yaml file from the repo-tools-data repo
3. Identify the repos in that file that are tagged in the Open edX release
4. Identify the commit that needs to be tagged in each repo, tracing cross-repo
   dependencies as necessary
5. Show the identified repos and commits, and ask for confirmation from the user
6. Upon confirmation, create Git tags for the repos using the GitHub API
"""
from __future__ import unicode_literals, print_function
import sys
import re
import json
import getpass
import argparse
import logging
import copy
try:
    from path import Path as path
    from git import Repo, Commit
    from git.refs.symbolic import SymbolicReference
    from git.exc import GitCommandError
    import requests
    from requests.exceptions import RequestException
    import yaml
except ImportError:
    print("Error: missing dependencies! Please run this command to install them:")
    print("pip install path.py requests GitPython PyYAML")
    sys.exit(1)

log = logging.getLogger(__name__)


# Name used for fetching/storing GitHub OAuth tokens on disk
TOKEN_NAME = "<PASSWORD>"
# URL to the source of truth about our repositories
REPOS_YAML = "https://raw.githubusercontent.com/edx/repo-tools-data/master/repos.yaml"
# Regular expression for parsing out the parts of a pip requirement line
REQUIREMENT_RE = re.compile(r"""
    git\+https?://github\.com/          # prefix
    (?P<owner>[a-zA-Z0-9_.-]+)/         # repo owner
    (?P<repo>[a-zA-Z0-9_.-]+).git       # repo name
    (@(?P<ref>[a-zA-Z0-9_.-]+))?        # git ref (tag, branch, or commit hash) (optional)
    (\#egg=(?P<egg>[a-zA-Z0-9_.-]+))?   # egg name (optional)
    (==(?P<version>[a-zA-Z0-9_.-]+))?   # version (optional)
""", re.VERBOSE)


def make_parser():
    parser = argparse.ArgumentParser(
        description="Create/remove tags & branches on GitHub repos for Open edX releases",
    )
    parser.add_argument(
        'ref', metavar="REFNAME",
        help="The name of the ref to create in the repos",
    )

    refgroup = parser.add_argument_group(
        "arguments for git refs",
    )
    reftype = refgroup.add_mutually_exclusive_group()
    reftype.add_argument(
        '--tag', action="store_true", default=True, dest="use_tag",
        help="Create tags in repos [default]"
    )
    reftype.add_argument(
        '--branch', action="store_false", default=True, dest="use_tag",
        help="Create branches in repos"
    )
    refgroup.add_argument(
        '--override-ref', action="store", metavar="REF",
        help="A reference to use that overrides the references from the "
            "repos.yaml file in *ALL* repos. This might be a release candidate "
            "branch, for example."
{'fraction_non_alphanumeric': 0.1057417073581411, 'fraction_numerical': 0.00589324802155245, 'mean_word_length': 3.245889921372409, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '5850644', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1741, 'n_words': 644}