How to use the pydriller.repository_mining.RepositoryMining function in PyDriller

To help you get started, we’ve selected a few PyDriller examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ishepard / pydriller / tests / integration / test_commit_filters.py View on Github external
def test_single_commit():
    lc = list(RepositoryMining('test-repos/git-10/',
                               single="4e669cb4f69245dc669e116517d80d038d8e0434").traverse_commits())
    assert len(lc) == 1
    assert lc[0].hash == "4e669cb4f69245dc669e116517d80d038d8e0434"

    lc = list(RepositoryMining('test-repos/git-10/',
                               single="168b3aab057ed61a769acf336a4ef5e64f76c9fd").traverse_commits())
    assert len(lc) == 1
    assert lc[0].hash == "168b3aab057ed61a769acf336a4ef5e64f76c9fd"
github ishepard / pydriller / tests / integration / test_commit_filters.py View on Github external
def test_mod_with_file_types():
    lc = list(RepositoryMining('test-repos/git-4/',
                               only_modifications_with_file_types=['.java'])
              .traverse_commits())

    assert len(lc) == 2
    assert lc[0].hash == 'a1b6136f978644ff1d89816bc0f2bd86f6d9d7f5'
    assert lc[1].hash == 'b8c2be250786975f1c6f47e96922096f1bb25e39'

    lc = list(RepositoryMining('test-repos/git-7/',
                               only_modifications_with_file_types=['.java'])
              .traverse_commits())

    assert len(lc) == 2
    assert lc[0].hash == '5adbb71167e79ab6b974827e74c9da4d81977655'
    assert lc[1].hash == '0577bec2387ee131e1ccf336adcc172224d3f6f9'
github ishepard / pydriller / tests / test_ranges.py View on Github external
def test_multiple_filters_exceptions():
    from_commit = '6411e3096dd2070438a17b225f44475136e54e3a'
    from_tag = 'v1.4'

    with pytest.raises(Exception):
        for commit in RepositoryMining('test-repos/test1/',
                                       since=dt2,
                                       from_commit=from_commit
                                       ).traverse_commits():
            print(commit.hash)

    with pytest.raises(Exception):
        for commit in RepositoryMining('test-repos/test1/',
                                       since=dt2,
                                       from_tag=from_tag).traverse_commits():
            print(commit.hash)

    with pytest.raises(Exception):
        for commit in RepositoryMining('test-repos/test1/',
                                       from_commit=from_commit,
                                       from_tag=from_tag).traverse_commits():
            print(commit.hash)
github ishepard / pydriller / tests / integration / test_commit_filters.py View on Github external
def test_mod_with_file_types():
    lc = list(RepositoryMining('test-repos/git-4/',
                               only_modifications_with_file_types=['.java'])
              .traverse_commits())

    assert len(lc) == 2
    assert lc[0].hash == 'a1b6136f978644ff1d89816bc0f2bd86f6d9d7f5'
    assert lc[1].hash == 'b8c2be250786975f1c6f47e96922096f1bb25e39'

    lc = list(RepositoryMining('test-repos/git-7/',
                               only_modifications_with_file_types=['.java'])
              .traverse_commits())

    assert len(lc) == 2
    assert lc[0].hash == '5adbb71167e79ab6b974827e74c9da4d81977655'
    assert lc[1].hash == '0577bec2387ee131e1ccf336adcc172224d3f6f9'
github ishepard / pydriller / tests / integration / test_commit_filters.py View on Github external
def test_only_releases_wo_releases():
    lc = list(RepositoryMining('test-repos/git-1/',
                               only_releases=True).traverse_commits())

    assert len(lc) == 0
github ishepard / pydriller / tests / integration / test_commit_filters.py View on Github external
def test_only_in_branches():
    # by default, only analyze master
    assert len(list(RepositoryMining('test-repos/test8/')
                    .traverse_commits())) == 3
    # only analyze b2
    assert len(list(RepositoryMining('test-repos/test8/', only_in_branch='b2')
                    .traverse_commits())) == 4
    # only analyze b1
    assert len(list(RepositoryMining('test-repos/test8/', only_in_branch='b1')
                    .traverse_commits())) == 5
github ishepard / pydriller / tests / test_ranges.py View on Github external
print(commit.hash)

    with pytest.raises(Exception):
        for commit in RepositoryMining('test-repos/test1/',
                                       since=dt2,
                                       from_tag=from_tag).traverse_commits():
            print(commit.hash)

    with pytest.raises(Exception):
        for commit in RepositoryMining('test-repos/test1/',
                                       from_commit=from_commit,
                                       from_tag=from_tag).traverse_commits():
            print(commit.hash)

    with pytest.raises(Exception):
        for commit in RepositoryMining('test-repos/test1/',
                                       to=dt2,
                                       to_commit=from_commit
                                       ).traverse_commits():
            print(commit.hash)

    with pytest.raises(Exception):
        for commit in RepositoryMining('test-repos/test1/',
                                       to=dt2,
                                       to_tag=from_tag).traverse_commits():
            print(commit.hash)

    with pytest.raises(Exception):
        for commit in RepositoryMining('test-repos/test1/',
                                       single=from_commit,
                                       to=dt2,
                                       to_tag=from_tag).traverse_commits():
github ishepard / pydriller / tests / integration / test_commit_filters.py View on Github external
def test_only_in_branch_not_exist():
    with pytest.raises(Exception):
        list(RepositoryMining('test-repos/git-5/', only_in_branch='branch7')
             .traverse_commits())
github ishepard / pydriller / tests / integration / test_commit_filters.py View on Github external
def test_only_authors_not_existing():
    lc = list(RepositoryMining('test-repos/git-10/',
                               only_authors=["Uncle Bob"])
              .traverse_commits())
    assert len(lc) == 0
github ishepard / pydriller / pydriller / metrics / process / process_metrics.py View on Github external
"""
        Return the number of commits made to a file from the first commit to
        the one identified by commit_hash.

        :path_to_repo: path to a single repo
        :commit_hash: the SHA of the commit to stop counting. If None, the
            analysis starts from the latest commit
        :filepath: the path to the file to count for. E.g. 'doc/README.md'

        :return: int number of commits made to the file
        """

        filepath = str(Path(filepath))
        count = 0

        for commit in RepositoryMining(path_to_repo, from_commit=from_commit,
                                       to_commit=to_commit,
                                       reversed_order=True).traverse_commits():
            for modified_file in commit.modifications:
                if filepath in (modified_file.new_path,
                                modified_file.old_path):
                    count += 1

                    if modified_file.change_type == ModificationType.RENAME:
                        filepath = str(Path(modified_file.old_path))

                    break
        return count