def test_with_dates(path_to_repo, filepath, since, to, expected_count):
    metric = LinesCount(path_to_repo=path_to_repo, since=since, to=to)

    actual_count = metric.count()
    filepath = str(Path(filepath))

    assert actual_count[filepath] == expected_count
Ejemplo n.º 2
0
def test(path_to_repo, filepath, from_commit, to_commit, expected):
    metric = LinesCount(path_to_repo=path_to_repo,
                        from_commit=from_commit,
                        to_commit=to_commit)

    count = metric.count()
    filepath = str(Path(filepath))
    assert count[filepath] == expected
def test_with_commits(path_to_repo, filepath, from_commit, to_commit,
                      expected_count):
    metric = LinesCount(path_to_repo=path_to_repo,
                        from_commit=from_commit,
                        to_commit=to_commit)

    actual_count = metric.count()
    filepath = str(Path(filepath))

    assert actual_count[filepath] == expected_count
def test_with_dates(path_to_repo, filepath, since, to, expected_count, expected_max, expected_avg):
    metric = LinesCount(path_to_repo=path_to_repo, since=since, to=to)

    actual_count = metric.count_removed()
    actual_max = metric.max_removed()
    actual_avg = metric.avg_removed()

    filepath = str(Path(filepath))

    assert actual_count[filepath] == expected_count
    assert actual_max[filepath] == expected_max
    assert actual_avg[filepath] == expected_avg
def test_with_commits(path_to_repo, filepath, from_commit, to_commit, expected_count, expected_max, expected_avg):
    metric = LinesCount(path_to_repo=path_to_repo,
                        from_commit=from_commit,
                        to_commit=to_commit)

    actual_count = metric.count_removed()
    actual_max = metric.max_removed()
    actual_avg = metric.avg_removed()

    filepath = str(Path(filepath))

    assert actual_count[filepath] == expected_count
    assert actual_max[filepath] == expected_max
    assert actual_avg[filepath] == expected_avg
Ejemplo n.º 6
0
 def fetch_metrics(self):
     change_set = ChangeSet(self.url,
                            since=datetime.datetime.fromtimestamp(0),
                            to=datetime.datetime.now())
     code_churn = CodeChurn(self.url,
                            since=datetime.datetime.fromtimestamp(0),
                            to=datetime.datetime.now())
     commits_count = CommitsCount(self.url,
                                  since=datetime.datetime.fromtimestamp(0),
                                  to=datetime.datetime.now())
     contributors_count = ContributorsCount(
         self.url,
         since=datetime.datetime.fromtimestamp(0),
         to=datetime.datetime.now())
     contributors_experience = ContributorsExperience(
         self.url,
         since=datetime.datetime.fromtimestamp(0),
         to=datetime.datetime.now())
     hunks_count = HunksCount(self.url,
                              since=datetime.datetime.fromtimestamp(0),
                              to=datetime.datetime.now())
     line_count = LinesCount(self.url,
                             since=datetime.datetime.fromtimestamp(0),
                             to=datetime.datetime.now())
     return {
         'changeSet': change_set,
         'codeChurn': code_churn,
         'commitsCount': commits_count,
         'contributorsCount': contributors_count,
         'contributorsExperience': contributors_experience,
         'hunksCount': hunks_count,
         'lineCount': line_count,
     }
Ejemplo n.º 7
0
    def find_bic(self, fix_commit_hash: str,
                 impacted_files: List['ImpactedFile'],
                 **kwargs) -> Set[Commit]:
        """
        Find bug introducing commits candidates.

        :param str fix_commit_hash: hash of fix commit to scan for buggy commits
        :param List[ImpactedFile] impacted_files: list of impacted files in fix commit
        :key ignore_revs_file_path (str): specify ignore revs file for git blame to ignore specific commits.
        :key mod_files_treshold (int): if the number of modified files exceeds the threshold, the commit will be
            excluded (default 20)
        :key detect_move_from_other_files (DetectLineMoved): detect lines moved or copied from other files that were
            modified in the same commit, from parent commits or from any commit (default DetectLineMoved.SAME_COMMIT)
        :key metric (MetricType): define which metric to use for commit selection (default MetricType.LINES_COUNT)
        :returns Set[Commit] a set of bug introducing commits candidates, represented by Commit object
        """

        bic_candidates = super().find_bic(fix_commit_hash=fix_commit_hash,
                                          impacted_files=impacted_files,
                                          **kwargs)

        bic_candidate = None
        max_mod_lines = 0
        for commit in bic_candidates:
            lc = LinesCount(path_to_repo=self.repository_path,
                            from_commit=commit.hexsha,
                            to_commit=commit.hexsha).count()
            mod_lines_count = 0
            for k in lc.keys():
                mod_lines_count += lc.get(k)

            if mod_lines_count > max_mod_lines:
                max_mod_lines = mod_lines_count
                bic_candidate = commit

        log.info(f"Selected bug introducing commit: {bic_candidate}")

        return {bic_candidate}
Ejemplo n.º 8
0
    def get_process_metrics(self, from_commit: str, to_commit: str) -> dict:
        """ Extract process metrics for an evolution period.

        Parameters
        ----------
        from_commit : str
            Hash of release start
        to_commit : str
            Hash of release end

        """
        change_set = ChangeSet(self.path_to_repo, from_commit=from_commit, to_commit=to_commit)
        code_churn = CodeChurn(self.path_to_repo, from_commit=from_commit, to_commit=to_commit, ignore_added_files=True)
        commits_count = CommitsCount(self.path_to_repo, from_commit=from_commit, to_commit=to_commit)
        contributors_count = ContributorsCount(self.path_to_repo, from_commit=from_commit, to_commit=to_commit)
        highest_contributors_experience = ContributorsExperience(self.path_to_repo, from_commit=from_commit,
                                                                 to_commit=to_commit)
        median_hunks_count = HunksCount(self.path_to_repo, from_commit=from_commit, to_commit=to_commit)
        lines_count = LinesCount(self.path_to_repo, from_commit=from_commit, to_commit=to_commit)

        return {
            'dict_change_set_max': change_set.max(),
            'dict_change_set_avg': change_set.avg(),
            'dict_code_churn_count': code_churn.count(),
            'dict_code_churn_max': code_churn.max(),
            'dict_code_churn_avg': code_churn.avg(),
            'dict_commits_count': commits_count.count(),
            'dict_contributors_count': contributors_count.count(),
            'dict_minor_contributors_count': contributors_count.count_minor(),
            'dict_highest_contributor_experience': highest_contributors_experience.count(),
            'dict_hunks_median': median_hunks_count.count(),
            'dict_additions': lines_count.count_added(),
            'dict_additions_max': lines_count.max_added(),
            'dict_additions_avg': lines_count.avg_added(),
            'dict_deletions': lines_count.count_removed(),
            'dict_deletions_max': lines_count.max_removed(),
            'dict_deletions_avg': lines_count.avg_removed()}
Ejemplo n.º 9
0
 project = argv[2].split("/")[1]
 for commit in RepositoryMining(urls,
                                clone_repo_to="./repo").traverse_commits():
     try:
         c = Repo("./repo/" + commit.project_name).commit(commit.hash)
         previousCommit = getCommit(c, 1)
         thirdCommit = getCommit(c, 3)
         fifthCommit = getCommit(c, 5)
         print(commit.hash)
         print(previousCommit)
         print(thirdCommit)
         print(fifthCommit)
         g = Git("./repo/" + commit.project_name)
         g.checkout(commit.hash)
         churn = LinesCount(
             path_to_repo=commit.project_path,
             from_commit=previousCommit,
             to_commit=commit.hash).count() if previousCommit else None
         churn3 = LinesCount(
             path_to_repo=commit.project_path,
             from_commit=thirdCommit,
             to_commit=commit.hash).count() if thirdCommit else None
         churn5 = LinesCount(
             path_to_repo=commit.project_path,
             from_commit=fifthCommit,
             to_commit=commit.hash).count() if fifthCommit else None
         added = LinesCount(path_to_repo=commit.project_path,
                            from_commit=previousCommit,
                            to_commit=commit.hash).count_added(
                            ) if previousCommit else None
         added3 = LinesCount(
             path_to_repo=commit.project_path,
Ejemplo n.º 10
0
# Aceste valori reprezinta formatul hash generat de github al commiturilor
# Codul a fost documentat de la adresa: https://readthedocs.org/projects/pydriller/downloads/pdf/latest/

from_commit1 = "8119659fb1e4ae6fabe8897c42ba7629fda07b21"
to_commit1 = "c2f7b6575156a7c3e049e17248acb6b580ba899f"

metric = ContributorsCount(
    path_to_repo='G:\\GIT_Repos\\spring-framework',
    from_commit='8119659fb1e4ae6fabe8897c42ba7629fda07b21',
    to_commit='c2f7b6575156a7c3e049e17248acb6b580ba899f')
count = metric.count()
print('Number of contributors per file: {}'.format(count))

# Get Number of lines / each file in the repo directory
metric = LinesCount(path_to_repo="G:\\GIT_Repos\\spring-framework",
                    from_commit='8119659fb1e4ae6fabe8897c42ba7629fda07b21',
                    to_commit='c2f7b6575156a7c3e049e17248acb6b580ba899f')
added_count = metric.count_added()
print(type(added_count))

# Get number of commits / each file in the repo directory
metric = CommitsCount(path_to_repo='G:\\GIT_Repos\\spring-framework',
                      from_commit='8119659fb1e4ae6fabe8897c42ba7629fda07b21',
                      to_commit='c2f7b6575156a7c3e049e17248acb6b580ba899f')
files = metric.count()

f = open("output.txt", "w")
# searching by key and value in dictionary, key means file name, value means actual commits number, etc, value retrieved by build in pydriller functions
for (key, value), (key2, value2), (key3,
                                   value3) in zip(files.items(),
                                                  added_count.items(),