diff --git a/api/gitlab_classes.py b/api/gitlab_classes.py index efdc493dd3f0d09facfda28fd8f8766f5ecd71d3..418c0a9ad5a3ea42b8e9acac058b9a43d0a4bc08 100644 --- a/api/gitlab_classes.py +++ b/api/gitlab_classes.py @@ -250,6 +250,9 @@ class GitlabCommit: def is_merge(self) -> bool: return len(self.git_commit.parent_ids) > 1 + def is_revert(self) -> bool: + return self.get_message().startswith('Revert') + def get_id(self) -> str: return self.git_commit.id @@ -659,6 +662,12 @@ class GitlabProject: commits.append(GitlabCommit(commit)) return commits + def get_branch_names(self) -> List[str]: + branches = self.git_project.branches.list() + branch_names: List[str] = list(map(lambda b: b.name, branches)) + return branch_names + + def get_labels(self) -> Set[str]: """ :return: set of label names diff --git a/commit_format_info.py b/commit_format_info.py index 9f8761c1e3b8b08d3561d1ee436efaa2d9e684f0..4a5f38fb189b069ab9fe72f30a70f9bfb271a045 100644 --- a/commit_format_info.py +++ b/commit_format_info.py @@ -1,29 +1,44 @@ from api.gitlab_classes import * from course import Course + +# noinspection PyShadowingNames +def judge_commits(commits: List[GitlabCommit]): + merges = 0 + reverts = 0 + well_formatted_commits = 0 + malformatted_commits = [] + for commit in commits: + if commit.is_merge(): + merges += 1 + elif commit.is_revert(): + reverts += 1 + elif commit.is_well_formatted(): + well_formatted_commits += 1 + else: + malformatted_commits.append(commit) + print( + f'\t\t{merges} merges, {reverts} reverts, {well_formatted_commits} well-formatted commits, ' + f'and {len(malformatted_commits)} malformatted commits') + for commit in malformatted_commits: + print(f'\t\t{commit.get_timestamp()} {commit.detail_formatting_problems()} ({commit.get_author()["name"]})') + + if __name__ == '__main__': projects = GitlabProject.get_projects_by_group(Course.gitlab_namespace) - projects = list(filter(lambda p: p.get_name().startswith('30pair'), projects)) + # projects = list(filter(lambda p: p.get_name().startswith('30pair'), projects)) + projects = list(filter(lambda p: p.get_name().startswith('36team'), projects)) # TODO: soft-code prefix projects.sort(key=lambda p: p.get_name()) for project in projects: - commits = project.get_commits() - print(f'\n\n. >>>> {project} <<<<') - print(f'{len(commits)} commits on the master branch') - merges = 0 - reverts = 0 - well_formatted_commits = 0 - malformatted_commits = [] - for commit in commits: - if commit.is_merge(): - merges += 1 - elif commit.get_message().startswith('Revert'): - reverts += 1 - elif commit.is_well_formatted(): - well_formatted_commits += 1 - else: - malformatted_commits.append(commit) - print( - f'{merges} merges, {reverts} reverts, {well_formatted_commits} well-formatted commits, ' - f'and {len(malformatted_commits)} malformatted commits') - for commit in malformatted_commits: - print(f'{commit.detail_formatting_problems()} ({commit.get_author()})') + print(f'\n\n\t>>>> {project} <<<<') + master_branch_commits = project.get_commits() + print(f'{len(master_branch_commits)} commits on the master branch') + all_branches_commits: Set[GitlabCommit] = set() + for branch in project.get_branch_names(): + for commit in project.get_commits(branch): + all_branches_commits.add(commit) + print(f'{len(all_branches_commits)} commits among all branches') + print('\tOn the master branch:') + judge_commits(master_branch_commits) + print('\tOn all other branches:') + judge_commits(list(sorted(all_branches_commits - set(master_branch_commits), key=lambda c: c.get_timestamp())))