How to use the pydriller.domain.commit.ModificationType.RENAME 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 / pydriller / git_repository.py View on Github external
def _calculate_last_commits(self, commit: Commit,
                                modifications: List[Modification],
                                hashes_to_ignore_path: str = None) \
            -> Dict[str, Set[str]]:

        commits = {}

        for mod in modifications:
            path = mod.new_path
            if mod.change_type == ModificationType.RENAME or \
                    mod.change_type == ModificationType.DELETE:
                path = mod.old_path
            deleted_lines = self.parse_diff(mod.diff)['deleted']
            try:
                blame = self._get_blame(commit.hash, path,
                                        hashes_to_ignore_path)
                for num_line, line in deleted_lines:
                    if not self._useless_line(line.strip()):
                        buggy_commit = blame[num_line - 1].split(' ')[
                            0].replace('^', '')

                        # Skip unblamable lines.
                        if buggy_commit.startswith("*"):
                            continue

                        if mod.change_type == ModificationType.RENAME:
github ishepard / pydriller / pydriller / metrics / process / process_metrics.py View on Github external
:return: int number of distinct developers contributing to the file
        """
        filepath = str(Path(filepath))
        developers = set()

        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):
                    developers.add(commit.author.email.strip())

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

                    break

        return len(developers)
github ishepard / pydriller / pydriller / domain / commit.py View on Github external
def _from_change_to_modification_type(diff: Diff):
        if diff.new_file:
            return ModificationType.ADD
        if diff.deleted_file:
            return ModificationType.DELETE
        if diff.renamed_file:
            return ModificationType.RENAME
        if diff.a_blob and diff.b_blob and diff.a_blob != diff.b_blob:
            return ModificationType.MODIFY

        return ModificationType.UNKNOWN