Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.0 kB
2
Indexable
Never
 def generate_report_for_repositories(self, folder_path, languages="Java"):
        folder_absolute_path = pathlib.Path(__file__).parent / folder_path
        project_folders = [join(folder_absolute_path, f) for f in os.listdir(folder_absolute_path) if
                           os.path.isdir(join(folder_absolute_path, f))]
        for project_folder in project_folders:
            metrics_list = defaultdict(list)
            print(project_folder)
            # if project_folder.split('/')[-1] in ['ActionBarSherlock', 'Bukkit', 'clojure', 'commons-lang',
            #                                      'elasticsearch', 'hadoop']:
            #     continue

            repo = git.Repo(project_folder)

            if 'master' in str(repo.branches):
                repo.git.checkout('master')
            elif 'trunk' in str(repo.branches):
                repo.git.checkout('trunk')
            elif 'main' in str(repo.branches):
                repo.git.checkout('main')

            tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime)

            for i in range(len(tags)):

                # print(repo.head.object.hexsha)
                repo.git.checkout(tags[i].path)
                # print(repo.head.object.hexsha)
                print(f"{i + 1}/{len(tags)}: {repo.head.object.hexsha}")
                data = self.generate_metrics(folder_path=project_folder, languages=languages)
                data["version"] = tags[i].path
                data["commit_time"] = tags[i].commit.committed_datetime
                for k, v in data.items():
                    metrics_list[k].append(v)

            # print(metrics_list)

            df = pd.DataFrame.from_dict(metrics_list)
            res_absolute_path = pathlib.Path(__file__).parent / 'res' / f"{project_folder.split('/')[-1]}.csv"
            df.to_csv(res_absolute_path, index=False)
            print('\n\n')
        # data_df = pd.DataFrame.from_dict(metrics_list)