def clone_git_repos(repo_url_list: list):
    for item in repo_url_list:
        clone_url = item + ".git"
        print(clone_url)
        app_name = item.split('/')[-1]
        local_repo_path = config.APM_REPO_PATH + app_name
        shell_util.run_command("git clone {} '{}'".format(
            clone_url, local_repo_path))
def get_methods_or_exprs_of_file(file_path: str, is_java_file):
    xml_name = file_util.generate_random_file_name_with_extension('xml')
    methods = []
    xml_p = None
    try:
        shell_util.run_command("srcml '{}' -o {}".format(file_path, xml_name))
        xml_p = Path(xml_name)
        xml_bytes = xml_p.read_bytes()
        methods = get_methods_exprs_of_xml_bytes(xml_bytes, is_java_file)
    finally:
        xml_p.unlink()
        return methods
Пример #3
0
def get_java_kotlin_loc(path: str, commit_id=None):
    if commit_id is None:
        output = shell_util.run_command(
            CLOC_COMMAND +
            " --include-lang=Java,Kotlin --not-match-f='^[Mm]ock|[Mm]ock$|.*[Tt]est.*' '{}'"
            .format(path))
    else:
        output = shell_util.run_command(
            CLOC_COMMAND +
            " --include-lang=Java,Kotlin --not-match-f='^[Mm]ock|[Mm]ock$|.*[Tt]est.*' '{}' {}"
            .format(path, commit_id),
            cwd=path)
    pattern = '.*SUM.*'
    m = re.search(pattern, output)
    result = LOC()
    if m is not None:
        line = m.group(0)
        result = _convert_cloc_line_to_object(line)

    return result
def get_code_churn_between_commits(path: str, old_commit, new_commit):
    output = shell_util.run_command(
        "git diff --shortstat {} {} -- '*.java' | head -n 1".format(
            old_commit, new_commit),
        cwd=path)
    added_count = 0
    deleted_count = 0
    added_match = insertion_pattern.search(output)
    if added_match:
        added_count = int(added_match.group(1))
    deleted_match = deletion_pattern.search(output)
    if deleted_match:
        deleted_count = int(deleted_match.group(1))

    return added_count + deleted_count
Пример #5
0
def get_file_loc_diff(old_path: str, new_path: str):
    output = shell_util.run_command(
        CLOC_COMMAND +
        " --diff --diff-timeout 1000 '{}' '{}'".format(old_path, new_path))

    if file_util.is_java_file(old_path):
        pattern = '.*Java(\s.*){4}'
    else:
        pattern = '.*Kotlin(\s.*){4}'
    m = re.search(pattern, output)
    same = LOC()
    modified = LOC()
    added = LOC()
    removed = LOC()

    if m is not None:
        lines = m.group(0).split('\n')
        lines.pop(0)
        for line in lines:
            line_type = line.split()[0]
            loc_detail = _convert_cloc_line_to_object(line)
            if line_type == 'same':
                same = loc_detail
            elif line_type == 'modified':
                modified = loc_detail
            elif line_type == 'added':
                added = loc_detail
            elif line_type == 'removed':
                removed = loc_detail

    return {
        'same': same,
        'modified': modified,
        'added': added,
        'removed': removed
    }
def get_repo_age_str(path: str):
    output = shell_util.run_command(
        "git log --reverse --pretty=oneline --format='%ar' | head -n 1 | LC_ALL=C sed 's/ago//' | tr -d ' '",
        cwd=path)
    return output
def get_commits_num(path: str):
    output = shell_util.run_command(
        "git log --oneline $commit | wc -l | tr -d ' '", cwd=path)
    return int(output)
def get_files_num(path: str):
    output = shell_util.run_command("git ls-files | wc -l | tr -d ' '",
                                    cwd=path)
    return int(output)
def get_default_branch(path: str):
    output = shell_util.run_command(
        "git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' | tr -d ' '",
        cwd=path)
    return output.strip()
def get_authors_num(path: str):
    output = shell_util.run_command(
        "git log --format='%aN' | sort -u | wc -l | tr -d ' '", cwd=path)
    return int(output)
def get_first_commit_date(path: str):
    output = shell_util.run_command(
        "git log --reverse --pretty='format: %ai' | head -n 1", cwd=path)
    datetime_str = output.strip()
    return datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S %z')